Skip to content

Commit

Permalink
feat: paramountplus support
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenYCL committed Mar 21, 2021
1 parent 075e441 commit 83cb43c
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 88 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
.env.development.local
.env.test.local
.env.production.local

.history
# secrets
secrets.*.js
v2.0.0
.idea
.vscode
./history
./.history

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ v2.1.0

- [x] Amazon 视频支持

- [x] paramountplus 视频支持

- [x] Disneyplus 视频支持

- [x] Yandex 翻译接口接入
Expand All @@ -89,7 +91,7 @@ v2.1.0

- [x] 百度翻译接口接入

- [x] deepl接口接入
- [x] deepl 接口接入

- [x] 控制面板

Expand Down Expand Up @@ -119,7 +121,7 @@ v2.1.0

### 交流

[tg交流](https://t.me/joinchat/Gs1RFzD5MpIwJ7S-)
[tg 交流](https://t.me/joinchat/Gs1RFzD5MpIwJ7S-)

<img src="https://i.loli.net/2021/01/12/Vti5GPdqxjN3ETL.jpg" alt="" height="148" width="148" />

Expand Down
2 changes: 2 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ v2.1.0

- [x] Amazon video support

- [x] paramountplus video support

- [x] Disneyplus video support

- [x] Yandex translate Api support
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chrome-extension-udemy-translate",
"version": "2.1.1",
"version": "2.1.2",
"description": "Translate Udemy's subtitles into Chinese/English(netflix+udemy+lynda+hulu+hbo now字幕翻译)",
"license": "MIT",
"repository": {
Expand Down
111 changes: 57 additions & 54 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
{
"name": "Udemy Translate",
"options_page": "options.html",
"background": {
"page": "background.html",
"persistent": false
},
"browser_action": {
"default_popup": "popup.html",
"default_icon": "icon-48.png"
},
"devtools_page": "devtools.html",
"permissions": [
"http://*/*",
"https://*/*",
"tabs",
"contextMenus",
"notifications",
"webRequestBlocking",
"storage",
"activeTab",
"declarativeContent"
],
"icons": {
"128": "icon-128.png"
},
"content_scripts": [{
"matches": [
"https://*.udemy.com/*",
"https://*.youtube.com/*",
"https://*.netflix.com/*",
"https://*.lynda.com/*",
"https://*.hbonow.com/*",
"https://*.hbomax.com/*",
"https://*.hulu.com/*",
"https://*.primevideo.com/*",
"https://*.amazon.com/*",
"https://*.amazon.com/gp/*",
"https://*.amazon.co.uk/*",
"https://*.amazon.de/*",
"https://*.amazon.co.jp/*",
"https://*.disneyplus.com/*"
],
"js": ["contentScript.bundle.js"],
"css": ["content.styles.scss"],
"run_at": "document_start"
}],
"web_accessible_resources": [
"content.styles.scss",
"icon-128.png",
"icon-48.png"
],
"manifest_version": 2,
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
"name": "Udemy Translate",
"options_page": "options.html",
"background": {
"page": "background.html",
"persistent": false
},
"browser_action": {
"default_popup": "popup.html",
"default_icon": "icon-48.png"
},
"devtools_page": "devtools.html",
"permissions": [
"http://*/*",
"https://*/*",
"tabs",
"contextMenus",
"notifications",
"webRequestBlocking",
"storage",
"activeTab",
"declarativeContent"
],
"icons": {
"128": "icon-128.png"
},
"content_scripts": [
{
"matches": [
"https://*.udemy.com/*",
"https://*.youtube.com/*",
"https://*.netflix.com/*",
"https://*.lynda.com/*",
"https://*.hbonow.com/*",
"https://*.hbomax.com/*",
"https://*.hulu.com/*",
"https://*.primevideo.com/*",
"https://*.amazon.com/*",
"https://*.amazon.com/gp/*",
"https://*.amazon.co.uk/*",
"https://*.amazon.de/*",
"https://*.amazon.co.jp/*",
"https://*.disneyplus.com/*",
"https://www.paramountplus.com/*"
],
"js": ["contentScript.bundle.js"],
"css": ["content.styles.scss"],
"run_at": "document_start"
}
],
"web_accessible_resources": [
"content.styles.scss",
"icon-128.png",
"icon-48.png"
],
"manifest_version": 2,
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
59 changes: 59 additions & 0 deletions src/pages/Content/VideoType/paramountplus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* www.paramountplus.com
*/

import { getItem } from '../modules/localStorage';
import { dealSubtitle } from '../modules/utils.ts';

const sub = {
pre: '',
current: '',
};

let time = null;
const run = async () => {
try {
console.log('-----------seraching...-------------');
if ($('video') !== null) {
let plugin_status = await getItem('status');
if (plugin_status) {
let current = $('video')[0].textTracks[0].activeCues[0].text;
current = current
.replace('<br>', ' ')
.replace(/\[(.+)\]/, '')
.replace(/<i>/g, '')
.replace(/<\/i>/g, ' ')
.replace(/\n/g, ' ');

// when change send request ,then make same
if (sub.pre !== current && current !== '') {
sub.pre = current;
console.log(sub);
// send message to background
if (typeof chrome.app.isInstalled !== 'undefined') {
chrome.runtime.sendMessage({ text: current });
}
}
} else {
// close plugin
// clearInterval(time);
await $('style[id=chrome-extension-plugin-css]').remove();
await $('.SUBTILTE').remove();
}
}
} catch (e) {
console.log(`can't find subtitle`);
}
};
time = setInterval(run, 100);

chrome.runtime.onMessage.addListener(async function(
request,
sender,
sendResponse
) {
console.log(JSON.stringify(request));
if (sub.current !== sub.pre) {
dealSubtitle('video', request);
}
});
64 changes: 34 additions & 30 deletions src/pages/Content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const hrefMap = {
hulu: 'hulu',
amazon: 'amazon',
hbo: 'hbo',
hbomax:'hbomax',
hbomax: 'hbomax',
primevideo: 'primevideo',
disneyplus: 'disneyplus',
paramountplus: 'paramountplus',
};

const whatsPage = (href) => {
Expand All @@ -26,35 +27,38 @@ console.log(
whatsPage(window.location.href)
);

switch (whatsPage(window.location.href)) {
case 'udemy':
require('./VideoType/udemy.ts');
break;
case 'netflix':
require('./VideoType/netflix.ts');
break;
case 'lynda':
require('./VideoType/lynda.ts');
break;
case 'hulu':
require('./VideoType/hulu.ts');
break;
case 'amazon':
require('./VideoType/amazon.ts');
break;
case 'hbo':
require('./VideoType/hbo.ts');
break;
case 'hbomax':
require('./VideoType/hbomax.ts');
break;
case 'primevideo':
require('./VideoType/primevideo.ts');
break;
case 'disneyplus':
require('./VideoType/disneyplus.ts');
break;
}
require(`./VideoType/${hrefMap[whatsPage(window.location.href)]}.ts`);
// switch (whatsPage(window.location.href)) {
// case 'udemy':
// require('./VideoType/udemy.ts');
// break;
// case 'netflix':
// require('./VideoType/netflix.ts');
// break;
// case 'lynda':
// require('./VideoType/lynda.ts');
// break;
// case 'hulu':
// require('./VideoType/hulu.ts');
// break;
// case 'amazon':
// require('./VideoType/amazon.ts');
// break;
// case 'hbo':
// require('./VideoType/hbo.ts');
// break;
// case 'hbomax':
// require('./VideoType/hbomax.ts');
// break;
// case 'primevideo':
// require('./VideoType/primevideo.ts');
// break;
// case 'disneyplus':
// require('./VideoType/disneyplus.ts');
// case 'paramountplus':
// require('./VideoType/paramountplus.ts');
// break;
// }

console.log('Content script works!');
console.log('Must reload extension for modifications to take effect.');
Expand Down

0 comments on commit 83cb43c

Please sign in to comment.