-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
87 changed files
with
437 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { type UdemyConfig } from "../../content_scripts/webApps/udemy/webApp.config"; | ||
import getWebAppConfig from "../../lib/getWebAppConfig"; | ||
import { type SupportedWebAppContext } from "../webAppContext"; | ||
|
||
export interface UdemyLearnContext extends SupportedWebAppContext { | ||
contextData: { | ||
webAppURL: URL; | ||
activeRoute: "learn"; | ||
payload: UdemyLecture; | ||
}; | ||
} | ||
|
||
export interface UdemyLecture { | ||
lectureID: string; | ||
courseName: string; | ||
} | ||
|
||
export type UdemyContext = UdemyLearnContext | SupportedWebAppContext; | ||
|
||
export default async function parseUdemyContext( | ||
webAppURL: URL, | ||
): Promise<UdemyContext> { | ||
const udemyConfig = (await getWebAppConfig("udemy")) as UdemyConfig; | ||
|
||
if (!udemyConfig) { | ||
throw new Error("Udemy configuration not found."); | ||
} | ||
|
||
const lectureRouteRegex = | ||
/https:\/\/www\.udemy\.com\/course\/([a-zA-Z0-9-]+)\/learn\/lecture\/(\d+)/; | ||
const match = lectureRouteRegex.exec(webAppURL.href); | ||
|
||
if (match !== null) { | ||
const lectureID = match[2]; | ||
const courseName = match[1]; | ||
const context: UdemyContext = { | ||
isSupported: true, | ||
appName: "udemy", | ||
webAppConfig: udemyConfig, | ||
contextData: { | ||
webAppURL, | ||
activeRoute: "learn", | ||
payload: { | ||
lectureID, | ||
courseName, | ||
}, | ||
}, | ||
}; | ||
return context; | ||
} | ||
|
||
return { | ||
isSupported: true, | ||
appName: "udemy", | ||
webAppConfig: udemyConfig, | ||
contextData: { | ||
webAppURL, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { WebAppConfig } from "../lib/getWebAppConfig"; | ||
import webAppContextParser from "./parsers"; | ||
|
||
export interface UnSupportedWebAppContext { | ||
isSupported: false; | ||
appName: null; | ||
} | ||
|
||
export interface SupportedWebAppContext { | ||
isSupported: true; | ||
appName: string; | ||
webAppConfig: WebAppConfig; | ||
contextData: { | ||
webAppURL: URL; | ||
activeRoute?: string; | ||
payload?: ContextPayload | ContextPayload[]; | ||
[key: string]: any; | ||
}; | ||
} | ||
|
||
export interface ContextPayload { | ||
[key: string]: any; | ||
} | ||
|
||
export type WebAppContext = UnSupportedWebAppContext | SupportedWebAppContext; | ||
|
||
export const getWebAppContext = async ( | ||
href: string, | ||
): Promise<WebAppContext> => { | ||
const webAppURL = new URL(href); | ||
const origin = webAppURL.origin; | ||
|
||
switch (origin) { | ||
case "https://www.youtube.com": { | ||
return await webAppContextParser.YouTube(webAppURL); | ||
} | ||
case "https://www.udemy.com": { | ||
return await webAppContextParser.Udemy(webAppURL); | ||
} | ||
default: { | ||
const webAppContext: WebAppContext = { | ||
appName: null, | ||
isSupported: false, | ||
}; | ||
return webAppContext; | ||
} | ||
} | ||
}; | ||
|
||
export const dispatchWebAppContext = async ( | ||
tabId: number, | ||
webAppContext: SupportedWebAppContext, | ||
): Promise<void> => { | ||
return await chrome.tabs.sendMessage(tabId, webAppContext); | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 10 additions & 13 deletions
23
app/src/modules/content_scripts/index.ts β app/src/content_scripts/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { type UdemyContext } from "../../../background/parsers"; | ||
import { type UdemyLearnContext } from "../../../background/parsers/parseUdemyContext"; | ||
import runLearn from "./routes/learn"; | ||
import { UdemyConfig } from "./webApp.config"; | ||
|
||
const runUdemy = async (context: UdemyContext): Promise<void> => { | ||
const { activeRoute } = context.contextData; | ||
const webAppConfig = context.webAppConfig as UdemyConfig; | ||
|
||
switch (activeRoute) { | ||
case "learn": { | ||
const isLearnEnabled = webAppConfig.routes.learn.isEnabled; | ||
isLearnEnabled && (await runLearn(context as UdemyLearnContext)); | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
export default runUdemy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../workers/udemy/routes/learn/interfaces.ts β .../webApps/udemy/routes/learn/interfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { | ||
YouTubeContext, | ||
YouTubePlaylistContext, | ||
YouTubeWatchContext, | ||
YouTubeShortsContext, | ||
} from "../../../background/parsers//parseYouTubeContext"; | ||
import runWatch from "./routes/watch"; | ||
import runPlaylist from "./routes/playlist"; | ||
import runShorts from "./routes/shorts"; | ||
import { YouTubeConfig } from "./webApp.config"; | ||
import "./global.css"; | ||
|
||
const runYouTube = async (context: YouTubeContext): Promise<void> => { | ||
const { activeRoute } = context.contextData; | ||
const webAppConfig = context.webAppConfig as YouTubeConfig; | ||
|
||
switch (activeRoute) { | ||
case "watch": { | ||
const isWatchEnabled = webAppConfig.routes.watch.isEnabled; | ||
isWatchEnabled && (await runWatch(context as YouTubeWatchContext)); | ||
break; | ||
} | ||
case "playlist": { | ||
const isPlaylistEnabled = webAppConfig.routes.playlist.isEnabled; | ||
isPlaylistEnabled && | ||
(await runPlaylist(context as YouTubePlaylistContext)); | ||
break; | ||
} | ||
case "shorts": { | ||
const isShortsEnabled = webAppConfig.routes.shorts.isEnabled; | ||
isShortsEnabled && (await runShorts(context as YouTubeShortsContext)); | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
export default runYouTube; |
2 changes: 1 addition & 1 deletion
2
...be/routes/playlist/addMetadataToppings.ts β ...be/routes/playlist/addMetadataToppings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.