fix: try fix subtitle in userscript
This commit is contained in:
@@ -91,6 +91,7 @@ const userscriptWebpack = (config, env) => {
|
||||
// @grant GM.getValue
|
||||
// @grant GM.deleteValue
|
||||
// @grant GM.info
|
||||
// @grant GM.addElement
|
||||
// @grant unsafeWindow
|
||||
// @connect translate.googleapis.com
|
||||
// @connect translate-pa.googleapis.com
|
||||
@@ -106,6 +107,7 @@ const userscriptWebpack = (config, env) => {
|
||||
// @connect openai.azure.com
|
||||
// @connect workers.dev
|
||||
// @connect github.io
|
||||
// @connect github.com
|
||||
// @connect githubusercontent.com
|
||||
// @connect kiss-translator.rayjar.com
|
||||
// @connect ghproxy.com
|
||||
|
||||
@@ -216,7 +216,7 @@ export async function run(isUserscript = false) {
|
||||
}
|
||||
|
||||
// 字幕翻译
|
||||
runSubtitle({ href, setting, rule });
|
||||
runSubtitle({ href, setting, rule, isUserscript });
|
||||
|
||||
// 监听消息
|
||||
// !isUserscript && runtimeListener(translator);
|
||||
|
||||
@@ -17,6 +17,7 @@ import { debounceSyncMeta } from "../libs/storage";
|
||||
import Loading from "./Loading";
|
||||
import { logger } from "../libs/log";
|
||||
import { sendBgMsg } from "../libs/msg";
|
||||
import { isExt } from "../libs/client";
|
||||
|
||||
const SettingContext = createContext({
|
||||
setting: DEFAULT_SETTING,
|
||||
@@ -36,7 +37,9 @@ export function SettingProvider({ children }) {
|
||||
(async () => {
|
||||
try {
|
||||
logger.setLevel(setting?.logLevel);
|
||||
if (isExt) {
|
||||
await sendBgMsg(MSG_SET_LOGLEVEL, setting?.logLevel);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Failed to fetch log level, using default.", error);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { MSG_XHR_DATA_YOUTUBE } from "./config";
|
||||
|
||||
(function () {
|
||||
const originalOpen = XMLHttpRequest.prototype.open;
|
||||
XMLHttpRequest.prototype.open = function (...args) {
|
||||
@@ -8,7 +6,7 @@ import { MSG_XHR_DATA_YOUTUBE } from "./config";
|
||||
this.addEventListener("load", function () {
|
||||
window.postMessage(
|
||||
{
|
||||
type: MSG_XHR_DATA_YOUTUBE,
|
||||
type: "KISS_XHR_DATA_YOUTUBE",
|
||||
url: this.responseURL,
|
||||
response: this.responseText,
|
||||
},
|
||||
|
||||
@@ -10,7 +10,7 @@ const providers = [
|
||||
{ pattern: "https://www.youtube.com", start: YouTubeInitializer },
|
||||
];
|
||||
|
||||
export function runSubtitle({ href, setting }) {
|
||||
export function runSubtitle({ href, setting, isUserscript }) {
|
||||
try {
|
||||
const subtitleSetting = setting.subtitleSetting || DEFAULT_SUBTITLE_SETTING;
|
||||
if (!subtitleSetting.enabled) {
|
||||
@@ -19,9 +19,21 @@ export function runSubtitle({ href, setting }) {
|
||||
|
||||
const provider = providers.find((item) => isMatch(href, item.pattern));
|
||||
if (provider) {
|
||||
if (isUserscript) {
|
||||
GM.addElement("script", {
|
||||
src: "https://github.com/fishjar/kiss-translator/blob/gh-pages/injector.js",
|
||||
// src: "http://127.0.0.1:8000/injector.js",
|
||||
type: "text/javascript",
|
||||
}).onload = function () {
|
||||
console.log(
|
||||
"Script successfully injected and loaded via GM_addElement."
|
||||
);
|
||||
};
|
||||
} else {
|
||||
const id = "kiss-translator-injector";
|
||||
const src = browser.runtime.getURL("injector.js");
|
||||
injectExternalJs(src, id);
|
||||
}
|
||||
|
||||
const apiSetting =
|
||||
setting.transApis.find(
|
||||
|
||||
Reference in New Issue
Block a user