From 4313fe71506dc7f132916613c0c43e205be4fce2 Mon Sep 17 00:00:00 2001 From: daniel k Date: Mon, 4 Dec 2023 13:57:13 +0900 Subject: [PATCH] fix highlight pos --- config/webpack.config.js | 2 +- doc/description.md | 3 + doc/intro.md | 5 +- package-lock.json | 436 +++++++++++++--------------------- package.json | 8 +- src/contentScript.js | 110 +++------ src/ebook/ebookEventInject.js | 10 +- src/pdf/pdfInject.js | 28 +-- src/util/index.js | 63 +++++ 9 files changed, 296 insertions(+), 369 deletions(-) diff --git a/config/webpack.config.js b/config/webpack.config.js index de56a34d..517f1189 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -6,7 +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"); +const ExtReloader = require("webpack-ext-reloader"); // Merge webpack configuration files module.exports = (env, argv) => { diff --git a/doc/description.md b/doc/description.md index c8583224..d50de18c 100644 --- a/doc/description.md +++ b/doc/description.md @@ -19,6 +19,9 @@ When mouse hover on text, it shows translated tooltip in any language. English, Russian, Japanese, Chinese and so on # Change Log +- 0.1.94 + - hide pdf viewer url + - add highlight (request by imymexxx) - 0.1.93 - fix pdf url - 0.1.92 diff --git a/doc/intro.md b/doc/intro.md index 8c4b2db9..b1d369c2 100644 --- a/doc/intro.md +++ b/doc/intro.md @@ -8,14 +8,15 @@ - Use left ctrl to listen tts pronunciation when tooltip is shown(Press esc to stop voice) - Use right alt to translate writing text (or highlighted text) in input box. (Do undo, press ctrl +z) ![result](/doc/11.gif) +- Setting page is given for customizing to taste +![result](/doc/14.gif) - Support online pdf to display translated tooltip using PDF.js (local computer pdf file need additional permission, see [exception](https://github.com/ttop32/MouseTooltipTranslator/blob/main/doc/intro.md#exception)) ![result](/doc/12.gif) - Support dual subtitles for youtube video ![result](/doc/16.gif) - Process OCR when hold left shift + mouse over on image (ex manga) ![result](/doc/15.gif) -- Setting page is given for customizing to taste -![result](/doc/14.gif) + # Exception - If source text language and translate language are same, it will skip diff --git a/package-lock.json b/package-lock.json index bcc82f96..7aa0a269 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "mouse_tooltip_translator", "version": "0.1.89", "dependencies": { - "@mswjs/interceptors": "^0.25.12", + "@mswjs/interceptors": "^0.25.13", "async-wait-until": "^2.0.12", "bcp-47": "^2.0.0", "bootstrap": "^4.5.3", @@ -36,7 +36,6 @@ "devDependencies": { "@mdi/font": "^5.9.55", "@mdi/js": "^5.9.55", - "@reorx/webpack-ext-reloader": "github:ttop32/webpack-ext-reloader", "copy-webpack-plugin": "^6.4.1", "cross-env": "^7.0.3", "css-loader": "^4.3.0", @@ -54,6 +53,7 @@ "vue-template-compiler": "^2.7.14", "webpack": "^5.74.0", "webpack-cli": "^5.0.1", + "webpack-ext-reloader": "^1.1.12", "webpack-merge": "^5.7.3" } }, @@ -169,54 +169,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@kingyue/useragent": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@kingyue/useragent/-/useragent-2.4.0.tgz", - "integrity": "sha512-ZjnkxQ+cmlLzDQIJp3MO9tT1700A56tJ902ucsvzxya9Yuf919YAtS1TaztKzC8JaEDY8ARyB7UuDwSNp4vSbA==", - "dev": true, - "dependencies": { - "axios": "^0.27.2", - "lru-cache": "4.1.x", - "semver": "5.5.x", - "tmp": "0.0.x", - "yamlparser": "0.0.x" - } - }, - "node_modules/@kingyue/useragent/node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "dev": true, - "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" - } - }, - "node_modules/@kingyue/useragent/node_modules/lru-cache": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", - "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", - "dev": true, - "dependencies": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, - "node_modules/@kingyue/useragent/node_modules/semver": { - "version": "5.5.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz", - "integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==", - "dev": true, - "bin": { - "semver": "bin/semver" - } - }, - "node_modules/@kingyue/useragent/node_modules/yallist": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", - "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", - "dev": true - }, "node_modules/@mdi/font": { "version": "5.9.55", "resolved": "https://registry.npmjs.org/@mdi/font/-/font-5.9.55.tgz", @@ -230,9 +182,9 @@ "dev": true }, "node_modules/@mswjs/interceptors": { - "version": "0.25.12", - "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.25.12.tgz", - "integrity": "sha512-a+zyoR01cPQeukSmaDEkE6aMwSjjfcT5ILzsyxmctEeCePnc2DMOd0X8Fn9bytq1IsAfMxJf/lu2aTfdivDbRg==", + "version": "0.25.13", + "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.25.13.tgz", + "integrity": "sha512-xfjR81WwXPHwhDbqJRHlxYmboJuiSaIKpP4I5TJVFl/EmByOU13jOBT9hmEnxcjR3jvFYoqoNKt7MM9uqerj9A==", "dependencies": { "@open-draft/deferred-promise": "^2.2.0", "@open-draft/logger": "^0.3.0", @@ -321,38 +273,6 @@ "url": "https://opencollective.com/popperjs" } }, - "node_modules/@reorx/webpack-ext-reloader": { - "version": "1.3.0", - "resolved": "git+ssh://git@github.com/ttop32/webpack-ext-reloader.git#6fe6db772efa02e202a97d1f49b7efad578b5fbf", - "dev": true, - "license": "MIT", - "dependencies": { - "@kingyue/useragent": "^2.4.0", - "@types/webpack": "^5.28.0", - "@types/webpack-sources": "^3.2.0", - "clean-webpack-plugin": "^4.0.0", - "colors": "^1.4.0", - "lodash": "^4.17.21", - "minimist": "^1.2.6", - "webpack-sources": "^3.2.3", - "ws": "^8.4.2" - }, - "bin": { - "webpack-ext-reloader": "dist/webpack-ext-reloader-cli.js" - }, - "peerDependencies": { - "webpack": "^5.61.0" - } - }, - "node_modules/@reorx/webpack-ext-reloader/node_modules/webpack-sources": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", - "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==", - "dev": true, - "engines": { - "node": ">=10.13.0" - } - }, "node_modules/@types/eslint": { "version": "8.4.5", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.5.tgz", @@ -425,10 +345,16 @@ "integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==", "dev": true }, + "node_modules/@types/webextension-polyfill": { + "version": "0.10.7", + "resolved": "https://registry.npmjs.org/@types/webextension-polyfill/-/webextension-polyfill-0.10.7.tgz", + "integrity": "sha512-10ql7A0qzBmFB+F+qAke/nP1PIonS0TXZAOMVOxEUsm+lGSW6uwVcISFNa0I4Oyj0884TZVWGGMIWeXOVSNFHw==", + "dev": true + }, "node_modules/@types/webpack": { - "version": "5.28.2", - "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-5.28.2.tgz", - "integrity": "sha512-7tcxyrIOd7WGimZIcWU6pDsNh2edGGnwYExOvd3l/nMvuxqwVPrFXnnTbYCnplqV9BJoU7Mo2mfFtiH8CNFvYw==", + "version": "5.28.5", + "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-5.28.5.tgz", + "integrity": "sha512-wR87cgvxj3p6D0Crt1r5avwqffqPXUkNlnQ1mjU93G7gCuFjufZR4I6j8cz5g1F1tTYpfOOFvly+cmIQwL9wvw==", "dev": true, "dependencies": { "@types/node": "*", @@ -437,9 +363,9 @@ } }, "node_modules/@types/webpack-sources": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-3.2.0.tgz", - "integrity": "sha512-Ft7YH3lEVRQ6ls8k4Ff1oB4jN6oy/XmU6tQISKdhfh+1mR+viZFphS6WL0IrtDOzvefmJg5a0s7ZQoRXwqTEFg==", + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-3.2.3.tgz", + "integrity": "sha512-4nZOdMwSPHZ4pTEZzSp0AsTM4K7Qmu40UKW4tJDiOVs20UzYF9l+qUe4s0ftfN0pin06n+5cWWDJXH+sbhAiDw==", "dev": true, "dependencies": { "@types/node": "*", @@ -1000,12 +926,6 @@ "npm": ">= 1.0.0" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true - }, "node_modules/axios": { "version": "0.21.4", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", @@ -1644,18 +1564,6 @@ "node": ">=0.1.90" } }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -2210,15 +2118,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/des.js": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz", @@ -2636,20 +2535,6 @@ "is-callable": "^1.1.3" } }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", @@ -3926,10 +3811,13 @@ } }, "node_modules/minimist": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", - "dev": true + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/minimist-options": { "version": "4.1.0", @@ -5943,6 +5831,32 @@ } } }, + "node_modules/useragent": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/useragent/-/useragent-2.3.0.tgz", + "integrity": "sha512-4AoH4pxuSvHCjqLO04sU6U/uE65BYza8l/KKBS0b0hnUPWi+cQ2BpeTEwejCSx9SPV5/U03nniDTrWx5NrmKdw==", + "dev": true, + "dependencies": { + "lru-cache": "4.1.x", + "tmp": "0.0.x" + } + }, + "node_modules/useragent/node_modules/lru-cache": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", + "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", + "dev": true, + "dependencies": { + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" + } + }, + "node_modules/useragent/node_modules/yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", + "dev": true + }, "node_modules/utf8-byte-length": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", @@ -6315,6 +6229,42 @@ "node": "^12.20.0 || >=14" } }, + "node_modules/webpack-ext-reloader": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/webpack-ext-reloader/-/webpack-ext-reloader-1.1.12.tgz", + "integrity": "sha512-UHjwiX8Qx4aAV8XkQQeHVDP6+7NY0wT/C+t8TNlEClcv/+mkKiRRlEi3Yq5yeaViM7DCFS1x8OBp5DyELB/JWg==", + "dev": true, + "dependencies": { + "@types/webextension-polyfill": "^0.10.6", + "@types/webpack": "^5.28.5", + "@types/webpack-sources": "^3.2.3", + "clean-webpack-plugin": "^4.0.0", + "colors": "^1.4.0", + "cross-env": "^7.0.3", + "json5": "^2.2.3", + "lodash": "^4.17.21", + "minimist": "^1.2.8", + "useragent": "^2.3.0", + "webextension-polyfill": "^0.10.0", + "webpack-sources": "^3.2.3", + "ws": "^8.14.2" + }, + "bin": { + "webpack-ext-reloader": "dist/webpack-ext-reloader-cli.js" + }, + "peerDependencies": { + "webpack": "^5.61.0" + } + }, + "node_modules/webpack-ext-reloader/node_modules/webpack-sources": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", + "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==", + "dev": true, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/webpack-merge": { "version": "5.7.3", "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.7.3.tgz", @@ -6433,9 +6383,9 @@ "dev": true }, "node_modules/ws": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", - "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", + "version": "8.14.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz", + "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==", "dev": true, "engines": { "node": ">=10.0.0" @@ -6474,12 +6424,6 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, - "node_modules/yamlparser": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/yamlparser/-/yamlparser-0.0.2.tgz", - "integrity": "sha512-Cou9FCGblEENtn1/8La5wkDM/ISMh2bzu5Wh7dYzCzA0o9jD4YGyLkUJxe84oPBGoB92f+Oy4ZjVhA8S0C2wlQ==", - "dev": true - }, "node_modules/yargs-parser": { "version": "13.1.2", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.2.tgz", @@ -6621,53 +6565,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "@kingyue/useragent": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@kingyue/useragent/-/useragent-2.4.0.tgz", - "integrity": "sha512-ZjnkxQ+cmlLzDQIJp3MO9tT1700A56tJ902ucsvzxya9Yuf919YAtS1TaztKzC8JaEDY8ARyB7UuDwSNp4vSbA==", - "dev": true, - "requires": { - "axios": "^0.27.2", - "lru-cache": "4.1.x", - "semver": "5.5.x", - "tmp": "0.0.x", - "yamlparser": "0.0.x" - }, - "dependencies": { - "axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "dev": true, - "requires": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" - } - }, - "lru-cache": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", - "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", - "dev": true, - "requires": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, - "semver": { - "version": "5.5.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz", - "integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==", - "dev": true - }, - "yallist": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", - "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", - "dev": true - } - } - }, "@mdi/font": { "version": "5.9.55", "resolved": "https://registry.npmjs.org/@mdi/font/-/font-5.9.55.tgz", @@ -6681,9 +6578,9 @@ "dev": true }, "@mswjs/interceptors": { - "version": "0.25.12", - "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.25.12.tgz", - "integrity": "sha512-a+zyoR01cPQeukSmaDEkE6aMwSjjfcT5ILzsyxmctEeCePnc2DMOd0X8Fn9bytq1IsAfMxJf/lu2aTfdivDbRg==", + "version": "0.25.13", + "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.25.13.tgz", + "integrity": "sha512-xfjR81WwXPHwhDbqJRHlxYmboJuiSaIKpP4I5TJVFl/EmByOU13jOBT9hmEnxcjR3jvFYoqoNKt7MM9uqerj9A==", "requires": { "@open-draft/deferred-promise": "^2.2.0", "@open-draft/logger": "^0.3.0", @@ -6752,30 +6649,6 @@ "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==" }, - "@reorx/webpack-ext-reloader": { - "version": "git+ssh://git@github.com/ttop32/webpack-ext-reloader.git#6fe6db772efa02e202a97d1f49b7efad578b5fbf", - "dev": true, - "from": "@reorx/webpack-ext-reloader@github:ttop32/webpack-ext-reloader", - "requires": { - "@kingyue/useragent": "^2.4.0", - "@types/webpack": "^5.28.0", - "@types/webpack-sources": "^3.2.0", - "clean-webpack-plugin": "^4.0.0", - "colors": "^1.4.0", - "lodash": "^4.17.21", - "minimist": "^1.2.6", - "webpack-sources": "^3.2.3", - "ws": "^8.4.2" - }, - "dependencies": { - "webpack-sources": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", - "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==", - "dev": true - } - } - }, "@types/eslint": { "version": "8.4.5", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.5.tgz", @@ -6848,10 +6721,16 @@ "integrity": "sha512-K5K+yml8LTo9bWJI/rECfIPrGgxdpeNbj+d53lwN4QjW1MCwlkhUms+gtdzigTeUyBr09+u8BwOIY3MXvHdcsA==", "dev": true }, + "@types/webextension-polyfill": { + "version": "0.10.7", + "resolved": "https://registry.npmjs.org/@types/webextension-polyfill/-/webextension-polyfill-0.10.7.tgz", + "integrity": "sha512-10ql7A0qzBmFB+F+qAke/nP1PIonS0TXZAOMVOxEUsm+lGSW6uwVcISFNa0I4Oyj0884TZVWGGMIWeXOVSNFHw==", + "dev": true + }, "@types/webpack": { - "version": "5.28.2", - "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-5.28.2.tgz", - "integrity": "sha512-7tcxyrIOd7WGimZIcWU6pDsNh2edGGnwYExOvd3l/nMvuxqwVPrFXnnTbYCnplqV9BJoU7Mo2mfFtiH8CNFvYw==", + "version": "5.28.5", + "resolved": "https://registry.npmjs.org/@types/webpack/-/webpack-5.28.5.tgz", + "integrity": "sha512-wR87cgvxj3p6D0Crt1r5avwqffqPXUkNlnQ1mjU93G7gCuFjufZR4I6j8cz5g1F1tTYpfOOFvly+cmIQwL9wvw==", "dev": true, "requires": { "@types/node": "*", @@ -6860,9 +6739,9 @@ } }, "@types/webpack-sources": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-3.2.0.tgz", - "integrity": "sha512-Ft7YH3lEVRQ6ls8k4Ff1oB4jN6oy/XmU6tQISKdhfh+1mR+viZFphS6WL0IrtDOzvefmJg5a0s7ZQoRXwqTEFg==", + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/@types/webpack-sources/-/webpack-sources-3.2.3.tgz", + "integrity": "sha512-4nZOdMwSPHZ4pTEZzSp0AsTM4K7Qmu40UKW4tJDiOVs20UzYF9l+qUe4s0ftfN0pin06n+5cWWDJXH+sbhAiDw==", "dev": true, "requires": { "@types/node": "*", @@ -7344,12 +7223,6 @@ "resolved": "https://registry.npmjs.org/async-wait-until/-/async-wait-until-2.0.12.tgz", "integrity": "sha512-SXy/vDs6UPJMG6YeEYOQ4ilA/JnGxk187KPGqFx9O+qVxsjkSl+jH+3P50qSNyMpEmDgr8qOFGOKCJckWb1i7A==" }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true - }, "axios": { "version": "0.21.4", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", @@ -7838,15 +7711,6 @@ "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", "dev": true }, - "combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, - "requires": { - "delayed-stream": "~1.0.0" - } - }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -8247,12 +8111,6 @@ "resolved": "https://registry.npmjs.org/delay/-/delay-6.0.0.tgz", "integrity": "sha512-2NJozoOHQ4NuZuVIr5CWd0iiLVIRSDepakaovIN+9eIDHEhdCAEvSy2cuf1DCrPPQLvHmbqTHODlhHg8UCy4zw==" }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true - }, "des.js": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz", @@ -8586,17 +8444,6 @@ "is-callable": "^1.1.3" } }, - "form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - }, "fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", @@ -9528,9 +9375,9 @@ } }, "minimist": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", "dev": true }, "minimist-options": { @@ -10993,6 +10840,34 @@ "schema-utils": "^3.0.0" } }, + "useragent": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/useragent/-/useragent-2.3.0.tgz", + "integrity": "sha512-4AoH4pxuSvHCjqLO04sU6U/uE65BYza8l/KKBS0b0hnUPWi+cQ2BpeTEwejCSx9SPV5/U03nniDTrWx5NrmKdw==", + "dev": true, + "requires": { + "lru-cache": "4.1.x", + "tmp": "0.0.x" + }, + "dependencies": { + "lru-cache": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", + "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", + "dev": true, + "requires": { + "pseudomap": "^1.0.2", + "yallist": "^2.1.2" + } + }, + "yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", + "dev": true + } + } + }, "utf8-byte-length": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", @@ -11260,6 +11135,35 @@ } } }, + "webpack-ext-reloader": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/webpack-ext-reloader/-/webpack-ext-reloader-1.1.12.tgz", + "integrity": "sha512-UHjwiX8Qx4aAV8XkQQeHVDP6+7NY0wT/C+t8TNlEClcv/+mkKiRRlEi3Yq5yeaViM7DCFS1x8OBp5DyELB/JWg==", + "dev": true, + "requires": { + "@types/webextension-polyfill": "^0.10.6", + "@types/webpack": "^5.28.5", + "@types/webpack-sources": "^3.2.3", + "clean-webpack-plugin": "^4.0.0", + "colors": "^1.4.0", + "cross-env": "^7.0.3", + "json5": "^2.2.3", + "lodash": "^4.17.21", + "minimist": "^1.2.8", + "useragent": "^2.3.0", + "webextension-polyfill": "^0.10.0", + "webpack-sources": "^3.2.3", + "ws": "^8.14.2" + }, + "dependencies": { + "webpack-sources": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", + "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==", + "dev": true + } + } + }, "webpack-merge": { "version": "5.7.3", "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.7.3.tgz", @@ -11354,9 +11258,9 @@ "dev": true }, "ws": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", - "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", + "version": "8.14.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz", + "integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==", "dev": true, "requires": {} }, @@ -11378,12 +11282,6 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, - "yamlparser": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/yamlparser/-/yamlparser-0.0.2.tgz", - "integrity": "sha512-Cou9FCGblEENtn1/8La5wkDM/ISMh2bzu5Wh7dYzCzA0o9jD4YGyLkUJxe84oPBGoB92f+Oy4ZjVhA8S0C2wlQ==", - "dev": true - }, "yargs-parser": { "version": "13.1.2", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.2.tgz", diff --git a/package.json b/package.json index 6fb43554..6470e069 100644 --- a/package.json +++ b/package.json @@ -6,17 +6,16 @@ "scripts": { "watch": "webpack --mode=development --watch --config config/webpack.config.js", "build": "webpack --mode=production --config config/webpack.config.js", - "zip": "npm-build-zip", "delete": "del-cli --force ./build", - "build-zip": "npm run delete && npm run build && npm run zip", "delete-en": "del-cli --force ./build/_locales/* !./build/_locales/en", + "zip": "npm-build-zip", "zip-en": "npm-build-zip --name _en", + "build-zip": "npm run delete && npm run build && npm run zip", "build-zip-en": "npm run build-zip && npm run delete-en && npm run zip-en" }, "devDependencies": { "@mdi/font": "^5.9.55", "@mdi/js": "^5.9.55", - "@reorx/webpack-ext-reloader": "github:ttop32/webpack-ext-reloader", "copy-webpack-plugin": "^6.4.1", "cross-env": "^7.0.3", "css-loader": "^4.3.0", @@ -34,10 +33,11 @@ "vue-template-compiler": "^2.7.14", "webpack": "^5.74.0", "webpack-cli": "^5.0.1", + "webpack-ext-reloader": "^1.1.12", "webpack-merge": "^5.7.3" }, "dependencies": { - "@mswjs/interceptors": "^0.25.12", + "@mswjs/interceptors": "^0.25.13", "async-wait-until": "^2.0.12", "bcp-47": "^2.0.0", "bootstrap": "^4.5.3", diff --git a/src/contentScript.js b/src/contentScript.js index 01c48949..3090011b 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -39,19 +39,24 @@ var highlightNode; //tooltip core====================================================================== $(async function initMouseTooltipTranslator() { - loadDestructor(); //remove previous tooltip script - await getSetting(); //load setting - if (checkExcludeUrl()) { - return; + try { + loadDestructor(); //remove previous tooltip script + stopPrevBackgroundAction(); //stop prev tts and clear context menu + await getSetting(); //load setting + if (checkExcludeUrl()) { + return; + } + detectPDF(); //check current page is pdf + checkYoutube(); + addElementEnv(); //add tooltip container + applyStyleSetting(); //add tooltip style + addBackgroundListener(); + loadEventListener(); //load event listener to detect mouse move + startMouseoverDetector(); // start current mouseover text detector + startTextSelectDetector(); // start current text select detector + } catch (error) { + console.log(error); } - detectPDF(); //check current page is pdf - checkYoutube(); - addElementEnv(); //add tooltip container - applyStyleSetting(); //add tooltip style - addBackgroundListener(); - loadEventListener(); //load event listener to detect mouse move - startMouseoverDetector(); // start current mouseover text detector - startTextSelectDetector(); // start current text select detector }); //determineTooltipShowHide based on hover, check mouse over word on every 700ms @@ -160,14 +165,22 @@ function highlightText(range) { } hideHighlight(); var rects = range.getClientRects(); - rects = filterOverlappedRect(rects); + rects = util.filterOverlappedRect(rects); + var adjustX = window.scrollX; + var adjustY = window.scrollY; + if (util.isEbookReader()) { + var ebookViewerRect = util.getEbookIframe()?.getBoundingClientRect(); + adjustX += ebookViewerRect?.left; + adjustY += ebookViewerRect?.top; + } + for (var rect of rects) { highlightNode = $("
", { class: "mtt-highlight", }) .css({ - left: rect.left + window.scrollX, - top: rect.top + window.scrollY, + left: rect.left + adjustX, + top: rect.top + adjustY, width: rect.width, height: rect.height, }) @@ -176,55 +189,12 @@ function highlightText(range) { } } -function filterOverlappedRect(rects) { - //filter duplicate rect - var rectSet = new Set(); - rects = Array.from(rects).filter((rect) => { - var key = getRectKey(rect); - if (!rectSet.has(key)) { - rectSet.add(key); - return true; - } - return false; - }); - - //filter covered rect by other rect - rects = rects.filter((rect1) => { - for (const rect2 of rects) { - if (getRectKey(rect1) != getRectKey(rect2) && rectCovered(rect1, rect2)) { - return false; - } - } - return true; - }); - - return rects; -} - -function getRectKey(rect) { - return `${rect.left}${rect.top}${rect.width}${rect.height}`; -} - -function rectCovered(rect1, rect2) { - return ( - rect2.top <= rect1.top && - rect1.top <= rect2.bottom && - rect2.top <= rect1.bottom && - rect1.bottom <= rect2.bottom && - rect2.left <= rect1.left && - rect1.left <= rect2.right && - rect2.left <= rect1.right && - rect1.right <= rect2.right - ); -} - function restartWordProcess() { - var word = activatedWord; + // mouseover text will be trigger when no activate word + //restart selected text activatedWord = null; if (selectedText) { processWord(selectedText, "select"); - } else { - processWord(word, "mouseover"); } } @@ -277,10 +247,7 @@ function hideTooltip() { } function hideHighlight() { - if (highlightNode) { - highlightNode = null; - $(".mtt-highlight").remove(); - } + $(".mtt-highlight")?.remove(); } async function translateWithReverse(word) { @@ -393,8 +360,6 @@ function loadEventListener() { addEventHandler("keyup", handleKeyup); //detect tab switching to reset env addEventHandler("blur", handleBlur); - // when refresh web site, stop tts - addEventHandler("beforeunload", handleBeforeunload); } function handleMousemove(e) { @@ -460,10 +425,6 @@ function handleBlur(e) { requestRemoveAllContext(); ocrView.removeAllOcrEnv(); } -function handleBeforeunload() { - requestStopTTS(); - requestRemoveAllContext(); -} function setMouseStatus(e) { clientX = e.clientX; @@ -603,7 +564,7 @@ function applyStyleSetting() { z-index: 100000100 !important; pointer-events: none !important; display: inline !important; - border-radius: 2px !important; + border-radius: 3px !important; } .ocr_text_div{ position: absolute; @@ -796,3 +757,10 @@ function removePrevElement() { $("#mttstyle").remove(); ocrView.removeAllOcrEnv(); } + +function stopPrevBackgroundAction() { + if (!util.isIframe()) { + requestStopTTS(); + requestRemoveAllContext(); + } +} diff --git a/src/ebook/ebookEventInject.js b/src/ebook/ebookEventInject.js index de2b2f78..316a62f5 100644 --- a/src/ebook/ebookEventInject.js +++ b/src/ebook/ebookEventInject.js @@ -4,7 +4,7 @@ import { enableSelectionEndEvent } from "/src/event/selection"; var iframeSrc = ""; setInterval(function () { - var iframe = getIframe(); + var iframe = util.getEbookIframe(); if (iframe && iframeSrc != iframe.src) { iframeSrc = iframe.src; bindIFrameEvent(iframe); @@ -12,18 +12,12 @@ setInterval(function () { } }, 1000); -function getIframe() { - var shadows = util.getAllShadows(); - var iframe = shadows?.[1]?.querySelectorAll("iframe")[0]; - return iframe; -} - function bindIFrameEvent(iframe) { //bind text selection enableSelectionEndEvent(iframe.contentWindow); // bind mouse for mouse over event - ["mousemove"].forEach((eventName) => { + ["mousemove", "keydown", "keyup"].forEach((eventName) => { iframe.contentWindow.addEventListener(eventName, (e) => { var evt = new CustomEvent(eventName, { bubbles: true, diff --git a/src/pdf/pdfInject.js b/src/pdf/pdfInject.js index 1b284150..7e498543 100644 --- a/src/pdf/pdfInject.js +++ b/src/pdf/pdfInject.js @@ -66,36 +66,36 @@ function waitUntilPdfLoad() { // change space system for tooltip async function addSpaceBetweenPdfText() { - var lastY; - var lastItem; + var prevY; + var prevLine; // remove all br $("br").remove(); // add new line for split text - $(".page span").each(function (index, item) { + $(".page span").each(function (index, line) { try { - var currentY = parseFloat(item.getBoundingClientRect().top); - var currentFontSize = parseFloat(window.getComputedStyle(item).fontSize); + var lineY = parseFloat(line.getBoundingClientRect().top); + var lineFontSize = parseFloat(window.getComputedStyle(line).fontSize); //if prev item is too far pos, add new line to prev item //if not too far add space //skip if already has space - if (index != 0 && !/ $/.test(lastItem.textContent)) { + if (prevLine && !/[\n ]$/.test(prevLine.textContent)) { if ( - lastY < currentY - currentFontSize * 2 || - currentY + currentFontSize * 2 < lastY + prevY < lineY - lineFontSize * 2 || + lineY + lineFontSize * 2 < prevY ) { - lastItem.textContent = lastItem.textContent + "\n "; + prevLine.textContent += "\n"; } else if ( - lastY < currentY - currentFontSize || - currentY + currentFontSize < lastY + prevY < lineY - lineFontSize || + lineY + lineFontSize < prevY ) { - lastItem.textContent = lastItem.textContent + " "; + prevLine.textContent += " "; } } - lastY = currentY; - lastItem = item; + prevY = lineY; + prevLine = line; } catch (error) { console.log(error); } diff --git a/src/util/index.js b/src/util/index.js index 1c44c787..ac853022 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -774,6 +774,26 @@ export function getReviewUrl() { return reviewUrlJson[extId]; } +export function isIframe() { + try { + return window.self !== window.top; + } catch (e) { + return true; + } +} + +export function isEbookReader() { + return ( + window.location.href == chrome.runtime.getURL("/foliate-js/reader.html") + ); +} + +export function getEbookIframe() { + var shadows = getAllShadows(); + var iframe = shadows?.[1]?.querySelectorAll("iframe")[0]; + return iframe; +} + // browser Listener handler======================== export function postMessage(data) { @@ -825,3 +845,46 @@ export function addCommandListener(type, handler) { } }); } + +//rect ======================================= +export function filterOverlappedRect(rects) { + //filter duplicate rect + var rectSet = new Set(); + rects = Array.from(rects).filter((rect) => { + var key = getRectKey(rect); + if (!rectSet.has(key)) { + rectSet.add(key); + return true; + } + return false; + }); + + //filter covered rect by other rect + rects = rects.filter((rect1) => { + for (const rect2 of rects) { + if (getRectKey(rect1) != getRectKey(rect2) && rectCovered(rect1, rect2)) { + return false; + } + } + return true; + }); + + return rects; +} + +function getRectKey(rect) { + return `${rect.left}${rect.top}${rect.width}${rect.height}`; +} + +function rectCovered(rect1, rect2) { + return ( + rect2.top <= rect1.top && + rect1.top <= rect2.bottom && + rect2.top <= rect1.bottom && + rect1.bottom <= rect2.bottom && + rect2.left <= rect1.left && + rect1.left <= rect2.right && + rect2.left <= rect1.right && + rect1.right <= rect2.right + ); +}