diff --git a/config/webpack.common.js b/config/webpack.common.js index 7969164b..ad753e5b 100644 --- a/config/webpack.common.js +++ b/config/webpack.common.js @@ -114,12 +114,7 @@ const common = { /\.vue$/, /\.vue\?vue/, // .vue ], - // global imports to register - imports: [ - // presets - "vue", - "vue-router", - ], + imports: ["vue", "vue-router"], }), require("unplugin-vue-router/webpack")({}), ], diff --git a/config/webpack.config.js b/config/webpack.config.js index 517f1189..19f98fa6 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -21,10 +21,6 @@ module.exports = (env, argv) => { alias: { vue$: "vue/dist/vue.esm-bundler.js", }, - fallback: { - crypto: require.resolve("crypto-browserify"), - stream: require.resolve("stream-browserify"), - }, }, plugins: [ argv.mode == "development" diff --git a/doc/description.md b/doc/description.md index 564b01ed..f011f8a1 100644 --- a/doc/description.md +++ b/doc/description.md @@ -19,6 +19,8 @@ Mouseover Translate Any Language At Once English, Russian, Japanese, Chinese and so on # Change Log +- 0.1.132 + - fix copy key conflict with tts voice(request by ldrahnik) - 0.1.131 - fix tts voice overlap(request by Nebras) - 0.1.130 diff --git a/package-lock.json b/package-lock.json index e131ca79..549d4227 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "bootstrap": "^4.5.3", "cheerio": "^1.0.0-rc.12", "crypto-browserify": "^3.12.0", + "crypto-js": "^4.2.0", "delay": "^6.0.0", "franc": "^6.2.0", "he": "^1.2.0", @@ -2005,6 +2006,11 @@ "node": "*" } }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "node_modules/css-loader": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/css-loader/-/css-loader-4.3.0.tgz", @@ -2135,12 +2141,15 @@ "integrity": "sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==" }, "node_modules/d": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", - "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", + "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", "dependencies": { - "es5-ext": "^0.10.50", - "type": "^1.0.1" + "es5-ext": "^0.10.64", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.12" } }, "node_modules/de-indent": { @@ -2630,13 +2639,14 @@ } }, "node_modules/es5-ext": { - "version": "0.10.62", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.62.tgz", - "integrity": "sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==", + "version": "0.10.64", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", + "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", "hasInstallScript": true, "dependencies": { "es6-iterator": "^2.0.3", "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", "next-tick": "^1.1.0" }, "engines": { @@ -2659,12 +2669,15 @@ "integrity": "sha512-SOp9Phqvqn7jtEUxPWdWfWoLmyt2VaJ6MpvP9Comy1MceMXqE6bxvaTu4iaxpYYPzhny28Lc+M87/c2cPK6lDg==" }, "node_modules/es6-symbol": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", - "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", + "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", "dependencies": { - "d": "^1.0.1", - "ext": "^1.1.2" + "d": "^1.0.2", + "ext": "^1.7.0" + }, + "engines": { + "node": ">=0.12" } }, "node_modules/es6-weak-map": { @@ -2708,6 +2721,20 @@ "node": ">=8.0.0" } }, + "node_modules/esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", + "dependencies": { + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.10" + } + }, "node_modules/esrecurse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", @@ -2778,11 +2805,6 @@ "type": "^2.7.2" } }, - "node_modules/ext/node_modules/type": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", - "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -6317,9 +6339,9 @@ } }, "node_modules/type": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", - "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", + "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" }, "node_modules/type-fest": { "version": "1.4.0", @@ -9035,6 +9057,11 @@ "randomfill": "^1.0.3" } }, + "crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "css-loader": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/css-loader/-/css-loader-4.3.0.tgz", @@ -9122,12 +9149,12 @@ "integrity": "sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==" }, "d": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", - "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", + "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", "requires": { - "es5-ext": "^0.10.50", - "type": "^1.0.1" + "es5-ext": "^0.10.64", + "type": "^2.7.2" } }, "de-indent": { @@ -9484,12 +9511,13 @@ } }, "es5-ext": { - "version": "0.10.62", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.62.tgz", - "integrity": "sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==", + "version": "0.10.64", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", + "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", "requires": { "es6-iterator": "^2.0.3", "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", "next-tick": "^1.1.0" } }, @@ -9509,12 +9537,12 @@ "integrity": "sha512-SOp9Phqvqn7jtEUxPWdWfWoLmyt2VaJ6MpvP9Comy1MceMXqE6bxvaTu4iaxpYYPzhny28Lc+M87/c2cPK6lDg==" }, "es6-symbol": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", - "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", + "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", "requires": { - "d": "^1.0.1", - "ext": "^1.1.2" + "d": "^1.0.2", + "ext": "^1.7.0" } }, "es6-weak-map": { @@ -9549,6 +9577,17 @@ "estraverse": "^4.1.1" } }, + "esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", + "requires": { + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + } + }, "esrecurse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", @@ -9607,13 +9646,6 @@ "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", "requires": { "type": "^2.7.2" - }, - "dependencies": { - "type": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", - "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" - } } }, "fast-deep-equal": { @@ -12180,9 +12212,9 @@ } }, "type": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", - "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", + "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" }, "type-fest": { "version": "1.4.0", diff --git a/package.json b/package.json index 9259d164..fe46a4b2 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "bootstrap": "^4.5.3", "cheerio": "^1.0.0-rc.12", "crypto-browserify": "^3.12.0", + "crypto-js": "^4.2.0", "delay": "^6.0.0", "franc": "^6.2.0", "he": "^1.2.0", diff --git a/public/manifest.json b/public/manifest.json index 4136d0df..1c7e1a9b 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -21,7 +21,7 @@ "web_accessible_resources": [{ - "resources": ["pdfjs/web/viewer.html", "ocr.html", "opencvHandler.html", "videoHandler.js","googleDocInject.js","subtitle.js"], + "resources": ["pdfjs/web/viewer.html", "ocr.html", "opencvHandler.html", "googleDocInject.js","subtitle.js"], "matches": [""], "use_dynamic_url": true }], diff --git a/public/ocr.html b/public/ocr.html index e23c5cd0..39600b32 100644 --- a/public/ocr.html +++ b/public/ocr.html @@ -1,7 +1,9 @@ - - - - - + + + + Mouse Tooltip Translator + + + diff --git a/public/offscreen.html b/public/offscreen.html index e86703db..1e383d64 100644 --- a/public/offscreen.html +++ b/public/offscreen.html @@ -1,7 +1,9 @@ - - - - - + + + + Mouse Tooltip Translator + + + diff --git a/public/opencvHandler.html b/public/opencvHandler.html index 56787df8..048c2974 100644 --- a/public/opencvHandler.html +++ b/public/opencvHandler.html @@ -1,6 +1,9 @@ - - + + + + Mouse Tooltip Translator OpenCV + - - + diff --git a/public/popup.html b/public/popup.html index d8c219d9..e1c5f9f4 100644 --- a/public/popup.html +++ b/public/popup.html @@ -5,10 +5,9 @@ Mouse Tooltip Translator - +
- diff --git a/src/contentScript.js b/src/contentScript.js index 73b0d1e5..7a7849a3 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -15,7 +15,7 @@ import { import { enableMouseoverTextEvent } from "/src/event/mouseover"; import * as util from "/src/util"; import * as ocrView from "/src/ocr/ocrView.js"; -import video from "./subtitle/subtitle.js"; +import subtitle from "/src/subtitle"; import { langListOpposite } from "/src/util/lang.js"; //init environment var======================================================================\ @@ -500,11 +500,26 @@ function handleMouseKeyUp(e) { function holdKeydownList(key) { // skip text key - if (key && !keyDownList[key] && !/Key|Digit|Numpad/.test(key)) { + if (key && !keyDownList[key] && !isCharKey(key)) { keyDownList[key] = true; restartWordProcess(); translateWriting(); } + stopTTSbyCombKey(key); +} + +async function stopTTSbyCombKey(key) { + if (!isCharKey(key) || !keyDownList[setting["TTSWhen"]]) { + return; + } + // stop tts if combination key ex crtl+c + for (var i in [1, 2, 3]) { + await delay(250); + util.requestStopTTS(); + } +} +function isCharKey(key) { + return /Key|Digit|Numpad/.test(key); } function releaseKeydownList(key) { @@ -823,8 +838,8 @@ function injectGoogleDocAnnotation() { // youtube================================ async function checkVideo() { - video["Youtube"].handleVideo(setting); - video["YoutubeNoCookie"].handleVideo(setting); + subtitle["Youtube"].handleVideo(setting); + subtitle["YoutubeNoCookie"].handleVideo(setting); } //destruction =================================== diff --git a/src/ocr/opencvHandler.js b/src/ocr/opencvHandler.js index d0e7ba95..798f4382 100644 --- a/src/ocr/opencvHandler.js +++ b/src/ocr/opencvHandler.js @@ -108,7 +108,7 @@ function detectText(canvasIn, mode) { var ksize = new cv.Size(50, 50); var element = cv.getStructuringElement(cv.MORPH_ELLIPSE, ksize); } else { - var ksize = new cv.Size(13, 13); + var ksize = new cv.Size(12, 12); var element = cv.getStructuringElement(cv.MORPH_RECT, ksize); } // var ksize = new cv.Size(20, 20); diff --git a/src/subtitle/baseVideo.js b/src/subtitle/baseVideo.js index 4ab5577c..6c287882 100644 --- a/src/subtitle/baseVideo.js +++ b/src/subtitle/baseVideo.js @@ -1,13 +1,9 @@ import { XMLHttpRequestInterceptor } from "@mswjs/interceptors/XMLHttpRequest"; import { debounce } from "throttle-debounce"; import $ from "jquery"; +import memoize from "memoizee"; +import browser from "webextension-polyfill"; import { waitUntil, WAIT_FOREVER } from "async-wait-until"; -import * as memoizee from "memoizee"; - -var browser; -try { - browser = require("webextension-polyfill"); -} catch (error) {} export default class BaseVideo { static sitePattern = /^(https:\/\/)(example\.com)/; @@ -229,7 +225,7 @@ export default class BaseVideo { this.killIntercept ); - static requestSubtitleCached = memoizee(async function ( + static requestSubtitleCached = memoize(async function ( subUrl, lang, tlang, @@ -273,6 +269,9 @@ export default class BaseVideo { //inject script for handle local function=============================== static async initInjectScript(setting) { + if (this.checkIsInjectedScript()) { + return; + } await this.injectScript(); this.resetInjectScript(setting); } diff --git a/src/subtitle/subtitle.js b/src/subtitle/index.js similarity index 100% rename from src/subtitle/subtitle.js rename to src/subtitle/index.js diff --git a/src/subtitle/youtube.js b/src/subtitle/youtube.js index db4e947b..91fd342c 100644 --- a/src/subtitle/youtube.js +++ b/src/subtitle/youtube.js @@ -1,5 +1,5 @@ import $ from "jquery"; -import * as memoizee from "memoizee"; +import memoize from "memoizee"; import BaseVideo from "./baseVideo"; import * as util from "/src/util"; @@ -291,7 +291,7 @@ export default class Youtube extends BaseVideo { }; } - static getYoutubeMetaDataCached = memoizee(this.getYoutubeMetaData); + static getYoutubeMetaDataCached = memoize(this.getYoutubeMetaData); static async getYoutubeMetaData(videoId) { // use global variable diff --git a/src/translator/papago.js b/src/translator/papago.js index 2f2678ba..2da033f1 100644 --- a/src/translator/papago.js +++ b/src/translator/papago.js @@ -2,7 +2,7 @@ import BaseTranslator from "./baseTranslator"; import ky from "ky"; import { v4 as uuidv4 } from "uuid"; -import Crypto from "crypto"; +import CryptoJS from "crypto-js"; var papagoLangCode = { ar: "ar", @@ -84,9 +84,10 @@ export default class papago extends BaseTranslator { var uuid = uuidv4(); var time = Date.now(); this.version = this.version ? this.version : await this.getVersion(); - var hash = Crypto.createHmac("md5", this.version) - .update(`${uuid}\n${url}\n${time}`) - .digest("base64"); + const key = CryptoJS.enc.Utf8.parse(this.version); + const plain = CryptoJS.enc.Utf8.parse(`${uuid}\n${url}\n${time}`); + var hash = CryptoJS.enc.Base64.stringify(CryptoJS.HmacMD5(plain, key)); + return { uuid, time, diff --git a/src/util/index.js b/src/util/index.js index 91b81592..401a280e 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -1,6 +1,7 @@ import $ from "jquery"; import isUrl from "is-url"; import _ from "lodash"; +import browser from "webextension-polyfill"; import { iso6393To1 } from "iso-639-3"; import { francAll } from "franc"; import { parse } from "bcp-47"; @@ -13,13 +14,6 @@ import { googleTranslateTtsLangList, } from "/src/util/lang.js"; -var browser; -try { - browser = require("webextension-polyfill"); -} catch (error) { - console.log(error); -} - export var defaultData = { showTooltipWhen: "always", TTSWhen: "ControlLeft", @@ -768,5 +762,3 @@ export async function requestBase64(url) { url, }); } - -// diff --git a/src/util/setting.js b/src/util/setting.js index 56be0b73..a24784ae 100644 --- a/src/util/setting.js +++ b/src/util/setting.js @@ -1,7 +1,4 @@ -var browser; -try { - browser = require("webextension-polyfill"); -} catch (error) {} +import browser from "webextension-polyfill"; // load setting from chrome storage // automatic setting update class===============================