Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
ttop32 committed Sep 5, 2023
1 parent c469d3e commit 71701a2
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 75 deletions.
13 changes: 0 additions & 13 deletions config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { VueLoaderPlugin } = require("vue-loader");
const PATHS = require("./paths");
// var path = require("path");
const ExtReloader = require("@reorx/webpack-ext-reloader");

// To re-use webpack configuration across templates,
// CLI maintains a common webpack configuration file - `webpack.common.js`.
Expand Down Expand Up @@ -91,18 +90,6 @@ const common = {
],
},
plugins: [
// extension auto reload
new ExtReloader({
port: 9090, // Which port use to create the server
reloadPage: true, // Force the reload of the page also
entries: {
// The entries used for the content/background scripts or extension pages
contentScript: "contentScript",
background: "background",
extensionPage: "popup",
},
}),

new VueLoaderPlugin(),
// Print file sizes
new SizePlugin(),
Expand Down
12 changes: 12 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const common = require("./webpack.common.js");
const PATHS = require("./paths");
var glob = require("glob");
var path = require("path");
const ExtReloader = require("@reorx/webpack-ext-reloader");

// Merge webpack configuration files
module.exports = (env, argv) => {
Expand All @@ -25,5 +26,16 @@ module.exports = (env, argv) => {
stream: require.resolve("stream-browserify"),
},
},
plugins: [
argv.mode == "development"
? new ExtReloader({
port: 9090, // Which port use to create the server
reloadPage: true, // Force the reload of the page also
entries: {
background: "background",
},
})
: false,
],
});
};
6 changes: 6 additions & 0 deletions doc/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ English, Russian, Japanese, Chinese and so on

# Change Log

- 0.1.78
- google reject by "Blue Argon"
- make ExtReloader works only on development
- remove any unused package
- refactor code
- double check any existence of eval()
- 0.1.77
- fix youtube dual subtitles time mismatch
- 0.1.76
Expand Down
31 changes: 2 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mouse_tooltip_translator",
"version": "0.1.77",
"version": "0.1.78",
"description": "Mouse over to translate",
"private": true,
"scripts": {
Expand Down Expand Up @@ -43,7 +43,6 @@
"he": "^1.2.0",
"is-url": "^1.2.4",
"jquery": "^3.5.1",
"load-script-once": "^2.0.1",
"match-url-wildcard": "^0.0.5",
"popper.js": "^1.16.1",
"source-map-support": "^0.5.21",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 3,
"version": "0.1.77",
"version": "0.1.78",
"name": "__MSG_appName__",
"description": "__MSG_appDesc__",
"default_locale": "en",
Expand Down
2 changes: 1 addition & 1 deletion size-plugin.json

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ function openIntroSite(reason) {
}

function addUninstallUrl() {
if (util.checkInDevMode()) {
return;
}

var reviewPage =
browser.name == "edge-chromium" ? edgeReviewPage : chromeReviewPage;
chrome.runtime.setUninstallURL(reviewPage);
Expand Down
1 change: 0 additions & 1 deletion src/popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ var translatorList = {
google: "google",
bing: "bing",
"papago (Experimental)": "papago",
"deepl (Experimental)": "deepl"
};
var translateActionList = {
Expand Down
27 changes: 3 additions & 24 deletions src/subtitle/youtube.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// https://terrillthompson.com/648
// intercept youtube subtitle and concat it
// intercept youtube subtitle and concat dual sub
// restart playersubtitle for apply

import $ from "jquery";
Expand Down Expand Up @@ -29,7 +28,7 @@ window.addEventListener(
false
);

// check any subtitle request
// check any subtitle request and concat dual sub
interceptor.on("request", async ({ request, requestId }) => {
try {
if (request.url.includes("www.youtube.com/api/timedtext")) {
Expand All @@ -52,7 +51,7 @@ interceptor.on("request", async ({ request, requestId }) => {
}
});

// check url change
// check url change and turn on sub
navigation.addEventListener("navigate", (e) => {
var url = e.destination.url;
activateCaption(url);
Expand Down Expand Up @@ -149,12 +148,6 @@ function concatWordSub(subtitle) {
newEvents[newEvents.length - 1].segs[0].utf8 += oneLineSub
? ` ${oneLineSub}`
: "";

// newEvents[newEvents.length - 1].dDurationMs =
// event.tStartMs +
// event.dDurationMs -
// newEvents[newEvents.length - 1].tStartMs -
// 100;
}
}

Expand Down Expand Up @@ -205,21 +198,7 @@ async function getYoutubeMetaData(vParam) {
return json;
}

async function getSubUrl(v, lang) {
var metaData = await getYoutubeMetaData(v);
var captionList =
metaData?.captions?.playerCaptionsTracklistRenderer?.captionTracks;
var langUrl = captionList.filter(
(caption) => !caption?.kind && caption.languageCode == lang
)?.[0]?.baseUrl;
return langUrl;
}

async function getTranslatedSubtitle(baseUrl, lang) {
// use user generated sub if exist
// var v = getVideoIdParam(baseUrl);
// var url = await getSubUrl(v, lang) + "&fmt=json3";

var url = new URL(baseUrl);
url.searchParams.set("tlang", lang);
return await (await fetch(url.toString())).json();
Expand Down

0 comments on commit 71701a2

Please sign in to comment.