├── README.md ├── background.js ├── manifest.json └── pen.svg /README.md: -------------------------------------------------------------------------------- 1 | # 编程随想博客评论区修复工具 2 | 这是一个浏览器扩展,只能在 FireFox 浏览器中使用,用于修复编程随想博客评论区提示 “初始化评论界面出错” 问题。 3 | 4 | ## 克隆这个仓库 5 | ``` 6 | git clone https://github.com/learnthink/blog_repair.git 7 | ``` 8 | 9 | ## 打开下面网址,根据 "Installing an example" 安装 10 | https://github.com/mdn/webextensions-examples#installing-an-example 11 | -------------------------------------------------------------------------------- /background.js: -------------------------------------------------------------------------------- 1 | function listener(details) { 2 | let filter = browser.webRequest.filterResponseData(details.requestId); 3 | let decoder = new TextDecoder("utf-8"); 4 | let encoder = new TextEncoder(); 5 | 6 | let data = []; 7 | filter.ondata = event => { 8 | data.push(event.data); 9 | }; 10 | 11 | filter.onstop = event => { 12 | let str = ""; 13 | for (let buffer of data) { 14 | str += decoder.decode(buffer, {stream: true}); 15 | } 16 | str += decoder.decode(); // end-of-stream 17 | 18 | // Just change any instance of WebExtension Example in the HTTP response 19 | // to WebExtension WebExtension Example. 20 | console.log("find and replace postID"); 21 | str = str.replace(/getParam\(\"postID\"\)/g, 'getParam("po")'); 22 | filter.write(encoder.encode(str)); 23 | filter.close(); 24 | }; 25 | } 26 | 27 | browser.webRequest.onBeforeRequest.addListener( 28 | listener, 29 | {urls: ["https://program-think.blogspot.com/*"], types: ["main_frame"]}, 30 | ["blocking"] 31 | ); 32 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "description": "Altering HTTP responses", 4 | "manifest_version": 2, 5 | "name": "blog-repair", 6 | "version": "1.0", 7 | "homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/http-response", 8 | "icons": { 9 | "48": "pen.svg" 10 | }, 11 | 12 | "permissions": [ 13 | "webRequest", "webRequestBlocking", "https://program-think.blogspot.com/*" 14 | ], 15 | 16 | "background": { 17 | "scripts": ["background.js"] 18 | }, 19 | 20 | "browser_specific_settings": { 21 | "gecko": { 22 | "strict_min_version": "57.0a1" 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /pen.svg: -------------------------------------------------------------------------------- 1 | 2 | --------------------------------------------------------------------------------