Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
yarn.lock

node_modules/
dist/
*.plugin
39 changes: 39 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -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', 'preview.png'].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}`);
})();
43 changes: 29 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
@@ -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);
};
});
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down