diff --git a/extension/_locales/en/messages.json b/extension/_locales/en/messages.json new file mode 100644 index 000000000..68fb3b3b1 --- /dev/null +++ b/extension/_locales/en/messages.json @@ -0,0 +1,10 @@ +{ + "extName": { + "message": "ShinyColors async app script", + "description": "Extension name" + }, + "desc": { + "message": "Make third-party userscripts load more stable by setting the async attribute on the game's app script", + "description": "Extension description" + } +} \ No newline at end of file diff --git a/extension/_locales/zh_CN/messages.json b/extension/_locales/zh_CN/messages.json new file mode 100644 index 000000000..9896d5060 --- /dev/null +++ b/extension/_locales/zh_CN/messages.json @@ -0,0 +1,10 @@ +{ + "extName": { + "message": "闪耀色彩异步脚本", + "description": "扩展名" + }, + "desc": { + "message": "通过给游戏的app脚本设置async属性使第三方用户脚本更稳定的加载", + "description": "Extension description" + } +} \ No newline at end of file diff --git a/extension/content-script.js b/extension/content-script.js new file mode 100644 index 000000000..44d45ca4c --- /dev/null +++ b/extension/content-script.js @@ -0,0 +1,22 @@ +const mutationCallback = (mutationsList) => { + for (let mutation of mutationsList) { + const addedNodes = mutation.addedNodes + addedNodes.forEach(node => { + if ('SCRIPT' === node.tagName) { + if (node.src.includes('shinycolors.enza.fun/app')) { + node.async = true + observer.disconnect() + } + } + }) + } +} + +const obConfig = { + subtree: true, + childList: true +} + +const targetNode = document +const observer = new MutationObserver(mutationCallback) +observer.observe(targetNode, obConfig) \ No newline at end of file diff --git a/extension/icon.png b/extension/icon.png new file mode 100644 index 000000000..0f9838654 Binary files /dev/null and b/extension/icon.png differ diff --git a/extension/manifest.json b/extension/manifest.json new file mode 100644 index 000000000..c5fd2e2f0 --- /dev/null +++ b/extension/manifest.json @@ -0,0 +1,17 @@ +{ + "name": "__MSG_extName__", + "description": "__MSG_desc__", + "version": "1.0", + "manifest_version": 3, + "default_locale": "zh_CN", + "content_scripts": [ + { + "matches": ["*://shinycolors.enza.fun/*"], + "run_at": "document_start", + "js": ["content-script.js"] + } + ], + "icons": { + "128": "/icon.png" + } +} \ No newline at end of file