Jelajahi Sumber

插件配置页面增加热更新功能

zxlie 3 bulan lalu
induk
melakukan
45dff0df22

+ 35 - 2
apps/background/background.js

@@ -586,6 +586,26 @@ let BgPageInstance = (function () {
                                 callback && callback({ success: false, error: error.message });
                             });
                         return true; // 异步响应必须返回true
+                    case 'fetch-fehelper-patchs':
+                        fetch('https://www.baidufe.com/fehelper-old/fh-patchs/fehelper-crx.json?t=' + Date.now())
+                            .then(resp => resp.json())
+                            .then(data => {
+                                const patchs = data.patchs || data;
+                                chrome.storage.local.set({ FH_PATCH_HOTFIX: patchs }, () => {
+                                    callback && callback({ success: true });
+                                });
+                            })
+                            .catch(e => {
+                                callback && callback({ success: false, error: e.message });
+                            });
+                        return true;
+                    case 'fh-get-tool-patch':
+                        if (request.toolName) {
+                            getToolPatch(request.toolName).then(patch => {
+                                callback && callback(patch);
+                            });
+                        }
+                        return true;
                 }
                 callback && callback(request.params);
             } else {
@@ -598,9 +618,7 @@ let BgPageInstance = (function () {
 
         // 每开一个窗口,都向内容脚本注入一个js,绑定tabId
         chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
-
             if (String(changeInfo.status).toLowerCase() === "complete") {
-
                 if(/^(http(s)?|file):\/\//.test(tab.url) && blacklist.every(reg => !reg.test(tab.url))){
                     InjectTools.inject(tabId, { js: `window.__FH_TAB_ID__=${tabId};` });
                     _injectContentScripts(tabId);
@@ -720,6 +738,21 @@ let BgPageInstance = (function () {
         }
     });
 
+    // 获取指定工具的补丁(css/js),返回Promise
+    function getToolPatch(toolName) {
+        return new Promise(resolve => {
+            chrome.storage.local.get('FH_PATCH_HOTFIX', result => {
+                const patchs = result.FH_PATCH_HOTFIX;
+                if (patchs && patchs[toolName]) {
+                    const { css, js } = patchs[toolName];
+                    resolve({ css, js });
+                } else {
+                    resolve({ css: '', js: '' });
+                }
+            });
+        });
+    }
+
     return {
         pageCapture: _captureVisibleTab,
         init: _init

+ 24 - 0
apps/json-format/index.js

@@ -98,6 +98,30 @@ new Vue({
                 });
             });
         }
+
+        // 页面加载时自动获取并注入json-format页面的补丁
+        chrome.runtime.sendMessage({
+            type: 'fh-dynamic-any-thing',
+            thing: 'fh-get-tool-patch',
+            toolName: 'json-format'
+        }, patch => {
+            if (patch) {
+                if (patch.css) {
+                    const style = document.createElement('style');
+                    style.textContent = patch.css;
+                    document.head.appendChild(style);
+                }
+                if (patch.js) {
+                    try {
+                        if (window.evalCore && window.evalCore.getEvalInstance) {
+                            window.evalCore.getEvalInstance(window)(patch.js);
+                        }
+                    } catch (e) {
+                        console.error('json-format补丁JS执行失败', e);
+                    }
+                }
+            }
+        });
     },
     methods: {
         isInUSA: function () {

+ 34 - 0
apps/options/index.css

@@ -1930,4 +1930,38 @@ body{
     color: #888;
 }
 
+/* 突出显示修复按钮 */
+.highlight-bugfix {
+    background: linear-gradient(90deg, #ff9800 0%, #ffc107 100%);
+    color: #fff !important;
+    border-radius: 6px;
+    font-weight: bold;
+    margin-left: 10px;
+    padding: 0 16px;
+    box-shadow: 0 2px 8px rgba(255,152,0,0.10);
+    display: flex;
+    align-items: center;
+    transition: transform 0.15s, box-shadow 0.15s;
+    border: 1px solid #ff9800;
+    height: 32px;
+}
+
+.highlight-bugfix:hover {
+    background: linear-gradient(90deg, #ffc107 0%, #ff9800 100%);
+    color: #fff;
+    transform: scale(1.06);
+    box-shadow: 0 4px 16px rgba(255,152,0,0.18);
+    text-decoration: none;
+}
+
+.bugfix-emoji {
+    font-size: 20px;
+    margin-right: 6px;
+}
+
+.bugfix-text {
+    font-size: 15px;
+    letter-spacing: 1px;
+}
+
 

+ 4 - 0
apps/options/index.html

@@ -27,6 +27,10 @@
                 <i class="nav-icon">⚙</i>
                 <span>插件设置</span>
             </a>
+            <a href="#" @click="autoFixBugs" class="nav-item bugfix-link highlight-bugfix" title="一键修复插件Bug,应用官方补丁">
+                <span class="bugfix-emoji">🛠️</span>
+                <span class="bugfix-text">一键修复Bug</span>
+            </a>
             <div class="version-info" v-if="versionChecked">
                 <!-- 当版本相同时显示简化信息 -->
                 <div v-if="latestVersion && !needUpdate" class="version-latest">

+ 49 - 0
apps/options/index.js

@@ -140,6 +140,9 @@ new Vue({
         // 检查URL中是否有donate_from参数
         this.checkDonateParam();
 
+        // 页面加载时自动获取并注入options页面的补丁
+        this.loadPatchHotfix();
+
         // 埋点:自动触发options
         chrome.runtime.sendMessage({
             type: 'fh-dynamic-any-thing',
@@ -1423,6 +1426,52 @@ new Vue({
                     type: 'error'
                 });
             }
+        },
+
+        async autoFixBugs() {
+            this.showNotification({ message: '正在拉取修复补丁,请稍候...' });
+            chrome.runtime.sendMessage({
+                type: 'fh-dynamic-any-thing',
+                thing: 'fetch-fehelper-patchs'
+            }, (resp) => {
+                if (!resp || !resp.success) {
+                    this.showNotification({ message: '补丁拉取失败,请稍后重试!', type: 'error' });
+                    return;
+                }
+                this.showNotification({
+                    message: '当前FeHelper插件中的已知Bug都已修复,你可以去验证了。',
+                    type: 'success',
+                    duration: 5000
+                });
+                // 当前页面的bug立即更新
+                this.loadPatchHotfix();
+            });
+        },
+
+        loadPatchHotfix() {
+            // 页面加载时自动获取并注入options页面的补丁
+            chrome.runtime.sendMessage({
+                type: 'fh-dynamic-any-thing',
+                thing: 'fh-get-tool-patch',
+                toolName: 'options'
+            }, patch => {
+                if (patch) {
+                    if (patch.css) {
+                        const style = document.createElement('style');
+                        style.textContent = patch.css;
+                        document.head.appendChild(style);
+                    }
+                    if (patch.js) {
+                        try {
+                            if (window.evalCore && window.evalCore.getEvalInstance) {
+                                window.evalCore.getEvalInstance(window)(patch.js);
+                            }
+                        } catch (e) {
+                            console.error('options补丁JS执行失败', e);
+                        }
+                    }
+                }
+            });
         }
     },
 

+ 24 - 0
apps/popup/index.js

@@ -51,6 +51,30 @@ new Vue({
         
         // 立即开始加载工具列表,不阻塞页面渲染
         this.loadTools();
+
+        // 页面加载时自动获取并注入popup页面的补丁
+        chrome.runtime.sendMessage({
+            type: 'fh-dynamic-any-thing',
+            thing: 'fh-get-tool-patch',
+            toolName: 'popup'
+        }, patch => {
+            if (patch) {
+                if (patch.css) {
+                    const style = document.createElement('style');
+                    style.textContent = patch.css;
+                    document.head.appendChild(style);
+                }
+                if (patch.js) {
+                    try {
+                        if (window.evalCore && window.evalCore.getEvalInstance) {
+                            window.evalCore.getEvalInstance(window)(patch.js);
+                        }
+                    } catch (e) {
+                        console.error('popup补丁JS执行失败', e);
+                    }
+                }
+            }
+        });
     },
 
     mounted: function () {