From 9fbf4e200db0ea1007ea11dffebbf1a832eba844 Mon Sep 17 00:00:00 2001 From: PRTS <873265236@qq.com> Date: Thu, 18 Sep 2025 16:54:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=82=E9=85=8D=20ncm3=20=E7=9A=84=20uct?= =?UTF-8?q?2=20=E8=BF=BD=E8=B8=AA=EF=BC=9B=E6=94=AF=E6=8C=81=E9=BB=91?= =?UTF-8?q?=E5=90=8D=E5=8D=95=E5=8F=82=E6=95=B0=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +++++ build.js | 39 +++++++++++++++++++++++++++++++++++++++ main.js | 43 +++++++++++++++++++++++++++++-------------- manifest.json | 2 +- 4 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 .gitignore create mode 100644 build.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c187b36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +yarn.lock + +node_modules/ +dist/ +*.plugin \ No newline at end of file diff --git a/build.js b/build.js new file mode 100644 index 0000000..88c43d6 --- /dev/null +++ b/build.js @@ -0,0 +1,39 @@ +const esbuild = require('esbuild'); +const fs = require('fs'); +const path = require('path'); +const compress = require('compressing'); + +// 从 manifest.json 读取版本号 +const manifest = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'manifest.json'), 'utf-8')); +const version = manifest.version || '0.0.0'; + +// 输出文件名 +const pluginName = `remove-tracking-attribute-${version}.plugin`; + +(async () => { + const distDir = path.resolve(__dirname, 'dist'); + if (!fs.existsSync(distDir)) { + fs.mkdirSync(distDir); + } + + ['manifest.json', 'build.js'].forEach(file => { + fs.copyFileSync( + path.resolve(__dirname, file), + path.resolve(distDir, file) + ); + }); + + await esbuild.build({ + entryPoints: ['./main.js'], + bundle: true, + minify: true, + target: 'chrome91', + outfile: './dist/main.js', + }); + + await compress.zip.compressDir(distDir, path.resolve(__dirname, pluginName), { + ignoreBase: true + }); + + console.log(`打包完成: ${pluginName}`); +})(); diff --git a/main.js b/main.js index 8b26eeb..0a758de 100644 --- a/main.js +++ b/main.js @@ -1,14 +1,29 @@ -plugin.onLoad(() => { - const _channalCall = channel.call; - channel.call = (name, ...args) => { - if (name === 'winhelper.setClipBoardData') { - const replacedString = args[1][0]; - if (replacedString.includes('&')) { - args[1][0] = replacedString.replace(/&userid=\d+/, ''); - } else { - args[1][0] = replacedString.replace(/userid=\d+/, ''); - } - } - _channalCall(name, ...args); - }; -}); +plugin.onLoad(() => { + const blacklist = ["userid", "uct2"]; + + const _channelCall = channel.call; + channel.call = (name, ...args) => { + if (name === "winhelper.setClipBoardData") { + let url = args[1][0]; + if (typeof url === "string") { + try { + const u = new URL(url); + const params = u.searchParams; + + blacklist.forEach(key => params.delete(key)); + + u.search = params.toString(); + args[1][0] = u.toString(); + } catch (e) { + blacklist.forEach(key => { + const regex = new RegExp(`([?&])${key}=[^&]+(&|$)`, "g"); + url = url.replace(regex, "$1"); + }); + url = url.replace(/[?&]$/, ""); + args[1][0] = url; + } + } + } + _channelCall(name, ...args); + }; +}); diff --git a/manifest.json b/manifest.json index bcbcc25..28ab5c5 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "author_links": ["https://github.com/solstice23"], "description": "移除分享链接中的追踪参数", "preview": "preview.png", - "version": "1.0.2", + "version": "1.0.3", "ncm3-compatible": true, "requirements": [], "betterncm_version": ">=1.0.0", From e310d8f0400ab07004badee491acd728e8221b54 Mon Sep 17 00:00:00 2001 From: PRTS <873265236@qq.com> Date: Thu, 18 Sep 2025 17:05:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?build=20=E9=87=8C=E6=94=BE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=94=BE=E9=94=99=E4=BA=86=EF=BC=8C=E7=8E=B0=E5=9C=A8?= =?UTF-8?q?=E4=BF=AE=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.js b/build.js index 88c43d6..38ad4e5 100644 --- a/build.js +++ b/build.js @@ -16,7 +16,7 @@ const pluginName = `remove-tracking-attribute-${version}.plugin`; fs.mkdirSync(distDir); } - ['manifest.json', 'build.js'].forEach(file => { + ['manifest.json', 'preview.png'].forEach(file => { fs.copyFileSync( path.resolve(__dirname, file), path.resolve(distDir, file)