🏠 Home 

跟踪链接净化

净化所有网站上的跟踪链接和事件

  1. // ==UserScript==
  2. // @name 跟踪链接净化
  3. // @name:zh-CN 跟踪链接净化
  4. // @name:zh-TW 跟蹤鏈接凈化
  5. // @name:en Clean Tracking URLs
  6. // @name:ja トラッカーの浄化
  7. // @name:ko 추적 URL 정리
  8. // @name:ru Очистить ссылки отслеживания
  9. // @name:de Tracking-URLs bereinigen
  10. // @name:fr Nettoyer les URLs de suivi
  11. // @name:es Limpiar URLs de seguimiento
  12. // @namespace https://github.com/cilxe/JavaScriptProjects
  13. // @author cilxe
  14. // @version 0.7.8
  15. // @description 净化所有网站上的跟踪链接和事件
  16. // @description:zh-CN 净化所有网站上的跟踪链接和事件
  17. // @description:zh-TW 凈化網際網路上的所有網站鏈接和事件
  18. // @description:en Clean all tracking URLs, block tracking events on all websites
  19. // @description:ja すべてのサイトの追跡リンクとイベントをサニタイズする
  20. // @description:ko 모든 추적 URL 정리, 모든 웹사이트에서 추적 이벤트 차단
  21. // @description:ru Очистить все ссылки отслеживания, заблокировать события отслеживания на всех веб-сайтах
  22. // @description:de Alle Tracking-URLs bereinigen, Tracking-Ereignisse auf allen Websites blockieren
  23. // @description:fr Nettoyer toutes les URLs de suivi, bloquer les événements de suivi sur tous les sites
  24. // @description:es Limpiar todas las URLs de seguimiento, bloquear eventos de seguimiento en todos los sitios web
  25. // @match *://*/*
  26. // @exclude /^https?:\/\/([a-z0-9-.]{0,52})(hdslb.com|csdnimg.cn)\/.*$/
  27. // @run-at document-start
  28. // @grant GM_registerMenuCommand
  29. // @grant GM_getValue
  30. // @grant GM_setValue
  31. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAOoklEQVR4nO2be1RTd7bHU3XddhRISAAJhJAA7ap6p9apbdE6fY2dejsz7R29VssrCILSChba22LnVsb6Lj54JpAEedVOZdqOEEQtdbAFReujPiu67Lr3CuGRnHNyfodH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yKr+tY444WarbDH5AysSLCGbRtwqW2tqZsUBXxOX7lyjCiYLtxvSfbMN/S40wdPj3irLnAmhCQNHXImiktXmM8Gre29mgeFq6jUXgdAGTwHE6EybnAKhfxJ/oP/nuw2fL9xuPOu6WbqjXrR9nH95V2tCaIKlwK0qnGI+EJTaN/8RNVnLbZd/ovyuvOYOwLJqU7xTu3w9Xu27kVgg2mo86E4V5u/uzONljdM774lJEy1LQ1ZaSLey+Jq+y/LN3dSMIop1YCKyAqW7OzCx+EtTBvfAxPM3D0zgP7iVxXd0mfi7u4bUBifMpMkgDknu3+vRkZmN3TCDPjKjpOAprekkF8CLFei739FHZjQkzCkgQTbckZnthkHfbEPlT+I0Wegq8/OSVf3f3sPCyDeCbMPIYvt7YZI3+56VpJh1krf6rOMPALMKt2A1ftsNnqW099Omr+4OCH6rf21QqvmboLW9/aMF4LcB7xdtxI/6bcLSpmdN0NY20UaHzOI080vit3syxRm9e8TvUedvHp3NvHt0Vuw4OruePB/wIbnHP4vMDNhAviTOcqPe/mK/GG+87P8A5YmAIqn+ohcAAAAASUVORK5CYII=
  32. // @license MIT
  33. // ==/UserScript==
  34. /*
  35. ## Main features
  36. - Auto clean up all URLs and block tracking events by default.
  37. - Manually clean all links with keyboard shortcuts (Shift + Alt + X). `(v0.6.3~)`
  38. ## Additional features (via the script menu)
  39. - Manually clean up the links again. `(v0.5.2~)`
  40. - Add specific tracking params for the current site (match by domain). `(v0.6.1~)`
  41. - Remove custom added params for the current site (match by domain). `(v0.6.2~)`
  42. ## Websites that support common cleaning
  43. - All websites on the internet.
  44. ## Websites that support additional cleaning
  45. - Bilibili
  46. - Baidu (Unencrypted) URLs
  47. - CSDN
  48. - Alibaba sites
  49. - alibaba.com/aliyun.com/alibabagroup.com/alimama.com
  50. - taobao.com/tmall.com/tmall.hk/1688.com/aliexpress.com/trendyol/lazada
  51. - youku.com
  52. - Douyin/Tiktok.com
  53. - Amazon
  54. - Youtube
  55. */
  56. (() => {
  57. const DELAY_TIME = { fast: 600, normal: 1000, slow: 3000 };
  58. const doc = document;
  59. const pageHost = window.location.hostname;
  60. const pageURL = window.location.href;
  61. const pagePath = window.location.pathname;
  62. let topScroll = 0;
  63. let isLogin = false;
  64. const hostRegex = /[a-z0-9-]{1,128}\.[a-z]{2,15}$/;
  65. // Matches all tracking parameters *contains/starts/ends* with the name
  66. const paramsRegStr = '^(spm|from_|ref_|track|trk|share_|embeds_|refer_)|'
  67. + '_from$|scm|referrer';
  68. let paramsReg = new RegExp(paramsRegStr);
  69. const commonParams = ['spm', 'mkt', 'src', 'from', 'source', 'alias',
  70. 'vd_source', 'brand', 'curator_clanid', 'snr', 'redir', 'sprefix',
  71. 'utm_id', 'utm_content', 'utm_source', 'utm_medium', 'utm_sources',
  72. 'utm_term', 'utm_campaign', 'utm_referrer', 'utm_keyword', 'ref',
  73. 'feature'];
  74. // Tracking or other params for certain sites
  75. const bilibiliParams = ['vd_source', 'hotRank', 'launch_id', 'popular_rank',
  76. 'session_id', 'business', 'sort_field', 'is_room_feed', 'visit_id',
  77. 'is_live_full_webview', 'is_live_webview', 'vt', 'theme', 'noReffer',
  78. 'timestamp', 'unique_k', 'hasBack', 'noTitleBar', 'plat_id', 'is_preview',
  79. 'buvid', 'up_id', 'is_story_h5', 'hybrid_set_header', 'lottery_id', 'seid',
  80. '-Abrowser', 'from', 'pagefrom', 'schema', 'preUrl', 'jumpLinkType',
  81. 'referfrom', 'spm_id', 'plat_id', 'p2p_type', 'broadcast_type',
  82. 'event_source_type'];
  83. // 'share_medium', 'share_plat', 'share_source', 'share_tag'
  84. // 'from_source', 'from_spmid', 'goFrom', 'sourceFrom', 'share_session_id'
  85. // 'refer_from', 'spm_id_from', 'dynamicspm_id_from', 'extra_jump_from'
  86. // 'search_source', 'bsource', 'msource', 'csource'
  87. // 'p2p_type', 'broadcast_type', 'event_source_type'
  88. const biliParamsReg = /^(utm_|share_|spm|from_)|(From|_from|source)$/;
  89. const baiduParams = ['rsv_idx', 'hisfilter', 'rsf', 'rsv_pq', 'rsv_t', 'qid', // baidu
  90. 'rsv_dl', 'oq', 'gpc', 'usm', 'tfflag', 'bs', 'rqlang', 'tn',
  91. 'sc_us', 'wfr', 'fenlei', 'platform', 'rqid', 'base_query', 'entry', 'qbl',
  92. 'for', 'from', 'topic_pn', 'rsp', 'rs_src', 'f', 'rsv_page', 'dyTabStr',
  93. 'ct', 'lm', 'site', 'sites', 'fr', 'cl', 'bsst', 'lid', 'rsv_spt',
  94. 'rsv_bp', 'src', 'sfrom', 'refer', 'zp_fr', 'channel', 'p_from', 'n_type',
  95. 'eqid', '_at_', 'sa', 'pd', 'source', 'tag_key', 'uname', 'uid',
  96. 'fromModule', 'lemmaFrom', 'structureId', 'structureClickId', 'ie',
  97. 'structureItemId', 'xzhid', 'rsv_enter', 'rsv_btype', 'prefixsug',
  98. 'client_type', 'task', 'locate', 'page', 'type', 'is_new_user', 'frwh', // tieba
  99. 'obj_id', 'fid', 'fname', '_t', 'topic_name', 'frs', 'share_from', 'tpl',
  100. 'u', 'tb_mod', 'tb_fr', 'share', 'sfc', 'idfrom', 'client_version', 'st',
  101. 'qq-pf-to',
  102. 'unique', 'is_video', '_wkts_', 'ai', 'ck', 'shh', // wenku
  103. 'utm_source', 'utm_medium', 'utm_term', 'utm_campaign', 'utm_content',
  104. 'utm_id',
  105. ];
  106. const douyinParams = ['rsv_idx', 'hisfilter', 'source', 'aid', 'enter_from',
  107. 'focus_method', 'previous_page', 'extra_params', 'gid', 'enter_method', // douyin
  108. 'is_from_webapp', 'sender_device', 'web_id']; // tiktok
  109. // 'from_wecom', 'source',
  110. const csdnParams = commonParams.concat(['ops_request_misc', 'request_id',
  111. 'biz_id', 'ydreferer', 'usp']);
  112. const youkuTudouParams = ['spm', 'scm', 'from', 's', 'playMode', 'client_id'];
  113. const aliSitesStr = '(alibaba|alibabagroup|aliyun|alimama|aliexpress'
  114. + '|taobao|tmall|1688|jiyoujia|fliggy)'
  115. + '.(com|hk|cn)$|(lazada|trendyol).[a-z.]{2,15}$';
  116. const aliSitesReg = new RegExp(aliSitesStr);
  117. const aliParams = [
  118. 'spm', 'acm', 'scm', 'scene', 'from', 'pvid', 'pvid2',
  119. ]; // 'wh_pid', 'wh_random_str', 'wx_navbar_transparent', 'wh_weex'
  120. const aliParamsRegStr = '^(utm_|spm_|from_|ref|track|wh_|wx_)';
  121. const aliParamsReg = new RegExp(aliParamsRegStr);
  122. const amaznParams = ['content-id', 'qid', 'crid', 'isAmazonFulfilled',
  123. 'sbo', 'plattr', 'sprefix', 'ld', '_encoding', 'ie', 'ds',
  124. ];
  125. const amznParamsRegStr = '_ref|^(utm_|ref|pd_rd_|pf_rd_|track|sc_)';
  126. const amznParamsReg = new RegExp(amznParamsRegStr, 'i');
  127. const ytParams = commonParams.concat(['embeds_referring_euri', 'embeds_euri',
  128. 'source_ve_path', 'feature', 'embeds_referring_origin', 'redir_token',
  129. 'pp', 'origin', 'ab_channel', 'enablejsapi', 'widgetid']);
  130. // If <true> block [Lucky Draw (The Selection)] popups on live.bilibili.com.
  131. const BlockLivePopups = true;
  132. // Add a custom 'urlchange' event to pushState and replaceState
  133. (() => { // [https://stackoverflow.com/a/52809105]
  134. const originalPushState = window.history.pushState;
  135. const originalReplaceState = window.history.replaceState;
  136. window.history.pushState = function pushState(...args) {
  137. const newPushState = originalPushState.apply(this, args);
  138. window.dispatchEvent(new Event('pushstate'));
  139. window.dispatchEvent(new Event('urlchange'));
  140. return newPushState;
  141. };
  142. window.history.replaceState = function replaceState(...args) {
  143. const newReplaceState = originalReplaceState.apply(this, args);
  144. window.dispatchEvent(new Event('replacestate'));
  145. window.dispatchEvent(new Event('urlchange'));
  146. return newReplaceState;
  147. };
  148. })();
  149. // Restore history state, remove redundant parameters
  150. function restoreState(siteParams) {
  151. const url = new URL(window.location.href);
  152. const params = url.searchParams;
  153. siteParams.forEach((k) => { if (params.has(k)) { params.delete(k); } });
  154. Array.from(params.keys()).forEach((k) => {
  155. if (paramsReg.test(k)) { params.delete(k); }
  156. });
  157. if (url.href !== window.location.href) {
  158. window.history.replaceState({}, 'Restore', url.href);
  159. }
  160. }
  161. let cleanLinks; // Clean most of <a> links
  162. switch (true) {
  163. case aliSitesReg.test(pageHost): // Alibaba sites
  164. cleanLinks = (siteParams) => {
  165. const links = doc.getElementsByTagName('a');
  166. for (let i = 0; i < links.length; i += 1) {
  167. if (hostRegex.test(links[i].hostname)) {
  168. const url = new URL(links[i].href);
  169. const params = url.searchParams;
  170. if (params.has('q')) { params.set('q', links[i].innerText); } // // 1. Ali sites (decoding error)
  171. siteParams.forEach((k) => { if (params.has(k)) { params.delete(k); } });
  172. Array.from(params.keys()).forEach((k) => { if (aliParamsReg.test(k)) { params.delete(k); } });
  173. if (links[i].href !== url.href) { links[i].href = url.href; }
  174. }
  175. }
  176. const areaLinks = doc.getElementsByTagName('area');
  177. for (let i = 0; i < areaLinks.length; i += 1) {
  178. if (hostRegex.test(areaLinks[i].hostname)) {
  179. const url = new URL(areaLinks[i].href);
  180. const params = url.searchParams;
  181. if (params.has('q')) { params.set('q', areaLinks[i].innerText); } // // 1. Ali sites (decoding error)
  182. siteParams.forEach((k) => { if (params.has(k)) { params.delete(k); } });
  183. Array.from(params.keys()).forEach((k) => { if (aliParamsReg.test(k)) { params.delete(k); } });
  184. if (areaLinks[i].href !== url.href) { areaLinks[i].href = url.href; }
  185. }
  186. }
  187. };
  188. break;
  189. case /baidu.com$/.test(pageHost): // Baidu sites
  190. cleanLinks = (siteParams) => {
  191. const links = doc.getElementsByTagName('a');
  192. for (let i = 0; i < links.length; i += 1) {
  193. if (hostRegex.test(links[i].hostname)) {
  194. const url = new URL(links[i].href);
  195. const params = url.searchParams;
  196. if (links[i].hostname === 'passport.baidu.com' && siteParams.includes('u')) {
  197. siteParams.splice(siteParams.indexOf('u'), 1);
  198. }
  199. if (links[i].innerText === '应用中心') { params.set('kw', links[i].innerText); } // 2. Tieba.baidu.com
  200. siteParams.forEach((k) => { if (params.has(k)) { params.delete(k); } });
  201. if (url.href !== links[i].href) { links[i].href = url.href; }
  202. }
  203. }
  204. };
  205. break;
  206. case /(bilibili|biligame)\.com$/.test(pageHost):
  207. cleanLinks = (siteParams) => {
  208. const links = doc.getElementsByTagName('a');
  209. for (let i = 0; i < links.length; i += 1) {
  210. if (hostRegex.test(links[i].hostname)) {
  211. links[i].removeAttribute('data-mod');
  212. links[i].removeAttribute('data-spmid');
  213. links[i].removeAttribute('data-idx');
  214. links[i].removeAttribute('data-target-url');
  215. const url = new URL(links[i].href);
  216. const params = url.searchParams;
  217. siteParams.forEach((k) => { if (params.has(k)) { params.delete(k); } });
  218. Array.from(params.keys()).forEach((k) => { if (biliParamsReg.test(k)) { params.delete(k); } });
  219. if (links[i].href !== url.href) { links[i].href = url.href; }
  220. }
  221. // 3. Bilibili
  222. // Clean <a> link data-url on video/bangumi of bilibili.com
  223. const dataLink = links[i].getAttribute('data-url');
  224. if (/^(https?:\/\/|\/\/)[a-zA-Z0-9-.]{1,128}\.[a-z]{2,15}/.test(dataLink)) {
  225. let dlURL;
  226. if (dataLink.startsWith('//')) {
  227. dlURL = new URL(`https:${dataLink}`);
  228. } else {
  229. dlURL = new URL(dataLink);
  230. }
  231. const dlParams = dlURL.searchParams;
  232. if (dlURL.hostname.endsWith('bilibili.com')) {
  233. Array.from(dlParams.keys()).forEach((k) => { if (biliParamsReg.test(k)) { dlParams.delete(k); } });
  234. siteParams.forEach((k) => { if (dlParams.has(k)) { dlParams.delete(k); } });
  235. } else {
  236. const dlParamsReg = paramsReg;
  237. Array.from(dlParams.keys()).forEach((k) => { if (dlParamsReg.test(k)) { dlParams.delete(k); } });
  238. commonParams.forEach((k) => { if (dlParams.has(k)) { dlParams.delete(k); } });
  239. }
  240. links[i].href = dlURL.href;
  241. links[i].classList.remove('jump-link');
  242. links[i].target = '_blank';
  243. if (links[i].innerText.startsWith(dlURL.href)) {
  244. links[i].innerText = dlURL.href;
  245. }
  246. }
  247. }
  248. };
  249. break;
  250. case /amazon\.[a-z.]{2,15}$/.test(pageHost):
  251. cleanLinks = (siteParams) => {
  252. const links = doc.getElementsByTagName('a');
  253. for (let i = 0; i < links.length; i += 1) {
  254. if (hostRegex.test(links[i].hostname)) {
  255. const url = new URL(links[i].href);
  256. const params = url.searchParams;
  257. siteParams.forEach((k) => { if (params.has(k)) { params.delete(k); } });
  258. Array.from(params.keys()).forEach((k) => { if (amznParamsReg.test(k)) { params.delete(k); } });
  259. if (links[i].href !== url.href) { links[i].href = url.href; }
  260. }
  261. if (/amazon\.[a-z.]{2,15}$/.test(links[i].hostname)) { // 4. Amazon
  262. if (links[i].pathname.includes('/ref')) {
  263. links[i].pathname = links[i].pathname.substring(links[i].pathname.indexOf('/ref'), 1);
  264. }
  265. }
  266. }
  267. };
  268. break;
  269. case /google\.[a-z.]{2,15}$|about.google$/.test(pageHost):
  270. cleanLinks = (siteParams) => {
  271. const links = doc.getElementsByTagName('a'); const iParamsReg = paramsReg;
  272. for (let i = 0; i < links.length; i += 1) {
  273. if (hostRegex.test(links[i].hostname)) {
  274. const url = new URL(links[i].href);
  275. const params = url.searchParams;
  276. siteParams.forEach((k) => { if (params.has(k)) { params.delete(k); } });
  277. Array.from(params.keys()).forEach((k) => { if (iParamsReg.test(k)) { params.delete(k); } });
  278. if (links[i].href !== url.href) { links[i].href = url.href; }
  279. // Clean params at the hash of urls // 5. Google
  280. if (/utm_/.test(url.hash)) {
  281. const ua = url.hash.substring(1).split('&');
  282. ua.forEach((key, index) => { if (/^utm_/.test(key)) ua.splice(index, 8); });
  283. links[i].hash = `#${ua.toString().replaceAll(',', '&')}`;
  284. }
  285. }
  286. }
  287. };
  288. break;
  289. default:
  290. cleanLinks = (siteParams) => {
  291. const links = doc.getElementsByTagName('a'); const iParamsReg = paramsReg;
  292. for (let i = 0; i < links.length; i += 1) {
  293. if (hostRegex.test(links[i].hostname)) {
  294. const url = new URL(links[i].href);
  295. const params = url.searchParams;
  296. siteParams.forEach((k) => { if (params.has(k)) { params.delete(k); } });
  297. Array.from(params.keys()).forEach((k) => { if (iParamsReg.test(k)) { params.delete(k); } });
  298. if (links[i].href !== url.href) { links[i].href = url.href; }
  299. }
  300. }
  301. };
  302. break;
  303. }
  304. function deferredCleanLinks(siteParams, delayTime) {
  305. const tid = setTimeout(() => {
  306. restoreState(siteParams); cleanLinks(siteParams); clearTimeout(tid);
  307. }, delayTime);
  308. }
  309. // Block link clicking events
  310. function blockClickEvents(siteParams, delayTime) {
  311. const tid = setTimeout(() => {
  312. const handleLinkClick = () => { cleanLinks(siteParams); };
  313. const handleLinkCM = (e) => { e.stopImmediatePropagation(); cleanLinks(siteParams); };
  314. const handleLinkClickN = () => { deferredCleanLinks(siteParams, 0); };
  315. const divs = doc.getElementsByTagName('div');
  316. for (let i = 0; i < divs.length; i += 1) {
  317. if (divs[i].className) {
  318. divs[i].removeEventListener('click', handleLinkClickN);
  319. divs[i].addEventListener('click', handleLinkClickN);
  320. divs[i].removeEventListener('auxclick', handleLinkCM);
  321. divs[i].addEventListener('auxclick', handleLinkCM);
  322. divs[i].removeEventListener('mousedown', handleLinkClick);
  323. divs[i].addEventListener('mousedown', handleLinkClick);
  324. divs[i].removeEventListener('keydown', handleLinkClick);
  325. divs[i].addEventListener('keydown', handleLinkClick);
  326. }
  327. }
  328. const btns = doc.getElementsByTagName('button');
  329. for (let i = 0; i < btns.length; i += 1) {
  330. if (btns[i].className) {
  331. btns[i].removeEventListener('click', handleLinkClickN);
  332. btns[i].addEventListener('click', handleLinkClickN);
  333. }
  334. }
  335. const links = doc.getElementsByTagName('a');
  336. for (let i = 0; i < links.length; i += 1) {
  337. if (hostRegex.test(links[i].hostname)) {
  338. // links[i].removeEventListener('mousedown', handleLinkCM); // mail.qq.com/web.telegram.org
  339. // links[i].addEventListener('mousedown', handleLinkCM);
  340. links[i].removeEventListener('keyup', handleLinkCM);
  341. links[i].addEventListener('keyup', handleLinkCM);
  342. links[i].removeEventListener('click', handleLinkClick);
  343. links[i].addEventListener('click', handleLinkClick);
  344. links[i].removeEventListener('auxclick', handleLinkClick);
  345. links[i].addEventListener('auxclick', handleLinkClick);
  346. links[i].removeEventListener('contextmenu', handleLinkCM);
  347. if (links[i].ontouchstart === undefined) {
  348. links[i].addEventListener('contextmenu', handleLinkCM);
  349. }
  350. }
  351. }
  352. clearTimeout(tid);
  353. }, delayTime);
  354. }
  355. // ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦ Custom clean ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
  356. // Youku, Tudou, Douyin, Amazon
  357. function customClean(siteParams) {
  358. restoreState(siteParams); cleanLinks(siteParams);
  359. let x = 0; let y = 0;
  360. doc.addEventListener('pointermove', (e) => {
  361. if (Math.abs(e.clientX - x) > 20 || Math.abs(e.clientY - y) > 20) {
  362. cleanLinks(siteParams); x = e.clientX; y = e.clientY;
  363. }
  364. });
  365. doc.addEventListener('DOMContentLoaded', () => {
  366. blockClickEvents(siteParams, 0);
  367. });
  368. }
  369. // Hide elements (common)
  370. function hideElement(attrs, intervals, duration, isRemove) {
  371. const intervalID = setInterval(() => {
  372. attrs.forEach((attr) => {
  373. if (document.querySelector(attr)) {
  374. if (!isRemove) {
  375. document.querySelector(attr).style.visibility = 'hidden';
  376. } else {
  377. document.querySelector(attr).remove();
  378. }
  379. }
  380. });
  381. }, intervals);
  382. document.addEventListener('DOMContentLoaded', () => {
  383. const timeoutId = setTimeout(() => {
  384. clearInterval(intervalID); clearTimeout(timeoutId);
  385. }, duration);
  386. });
  387. }
  388. // Auto close (common)
  389. function autoClick(attrs, attrIndex, intervals, duration) {
  390. const intervalID = setInterval(() => {
  391. attrs.forEach((attr) => {
  392. const closeBtn = document.querySelectorAll(attr)[attrIndex];
  393. if (closeBtn) { closeBtn.click(); }
  394. });
  395. }, intervals);
  396. document.addEventListener('DOMContentLoaded', () => {
  397. const timeoutId = setTimeout(() => {
  398. clearInterval(intervalID); clearTimeout(timeoutId);
  399. }, duration);
  400. });
  401. }
  402. // Auto close (mutation observer)
  403. function autoClose(loginWindow, closeButton, loginButton, timeout) {
  404. doc.addEventListener('DOMContentLoaded', () => {
  405. const observer = new MutationObserver((mutations) => {
  406. mutations.forEach((mutation) => {
  407. mutation.addedNodes.forEach((node) => {
  408. if (document.querySelector(loginWindow)) {
  409. if (node.querySelector(closeButton) && !isLogin) {
  410. console.info('Auto Cloesd!');
  411. node.querySelector(closeButton).click();
  412. }
  413. }
  414. });
  415. });
  416. });
  417. observer.observe(doc, { childList: true, subtree: true });
  418. if (isLogin) {
  419. const timeoutID = setTimeout(() => {
  420. loginButton.addEventListener('click', () => {
  421. isLogin = true;
  422. observer.disconnect();
  423. });
  424. clearTimeout(timeoutID);
  425. }, DELAY_TIME.normal * 2);
  426. } else { // Set timeout to disconnect observer whithout login button
  427. const timeoutID = setTimeout(() => {
  428. isLogin = true;
  429. observer.disconnect();
  430. clearTimeout(timeoutID);
  431. }, timeout);
  432. }
  433. });
  434. }
  435. // ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦ Common sites ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
  436. function commonClean() {
  437. switch (true) { // additional params for certain sites
  438. case /google\.[a-z.]{2,15}$|(about|wellbeing).google/.test(pageHost):
  439. commonParams.push(
  440. 'device',
  441. 'pcampaignid',
  442. 'subid',
  443. 'hl',
  444. 'fg',
  445. 'ved',
  446. 'ei',
  447. 'prev',
  448. 'sig',
  449. 'sca_esv',
  450. 'visit_id',
  451. 'dest_src',
  452. );
  453. break;
  454. case pageHost.endsWith('facebook.com'):
  455. commonParams.push(
  456. 'privacy_mutation_token',
  457. 'ars',
  458. 'helpref',
  459. 'search_session_id',
  460. 'entry_point',
  461. 'campaign_id',
  462. 'nav_source',
  463. 'placement',
  464. 'privacy_source',
  465. '__cft__[0]',
  466. '__tn__',
  467. );
  468. break;
  469. case /(twitter|x)\.com$/.test(pageHost):
  470. commonParams.push('screen_name');
  471. break;
  472. case pageHost.endsWith('reddit.com'):
  473. commonParams.push('embed_host_url', 'actionSource', 'shreddit');
  474. paramsReg = /^(utm_|spm_|from_|ref|track|trk|experiment_d2x_|experiment_mweb)/;
  475. break;
  476. case pageHost.endsWith('linkedin.com'):
  477. commonParams.push( // 'trk' , 'trkInfo'
  478. 'original_referer',
  479. 'origin',
  480. 'upsellOrderOrigin',
  481. 'lipi',
  482. 'desktopBackground',
  483. 'profileFormEntryPoint',
  484. 'entityUrn',
  485. 'veh',
  486. 'miniCompanyUrn',
  487. 'courseSlug',
  488. 'upsellTrk',
  489. 'upsellTrackingId',
  490. 'contextUrn',
  491. 'ct',
  492. 'pt',
  493. 'refId',
  494. 'position',
  495. );
  496. document.addEventListener('DOMContentLoaded', () => {
  497. blockClickEvents(commonParams, 8500);
  498. deferredCleanLinks(commonParams, DELAY_TIME.normal * 2);
  499. });
  500. break;
  501. case pageHost.endsWith('dzen.ru'):
  502. commonParams.push(
  503. 'lang',
  504. 'country_code',
  505. 'rid',
  506. 'clid',
  507. 'stid',
  508. 'issue_tld',
  509. 'parent_rid',
  510. 'persistent_id',
  511. 'story',
  512. 't',
  513. 'utr',
  514. 'place',
  515. 'secdata',
  516. 'integration',
  517. 'feed_exp',
  518. 'force_common_feed',
  519. 'feed_filter_type',
  520. 'feed_filter_source',
  521. );
  522. break;
  523. case pageHost.endsWith('vk.com'):
  524. commonParams.push('scheme', 'initial_stats_info');
  525. break;
  526. case /(microsoft|bing|xbox|skype|office|microsoft365)\.com$/.test(pageHost):
  527. commonParams.push(
  528. 'ocid',
  529. 'OCID',
  530. 'ICID',
  531. 'icid',
  532. 'CLCID',
  533. 'clcid',
  534. 'es',
  535. 'response_mode',
  536. 'exp',
  537. 'form',
  538. 'FORM',
  539. 'xr',
  540. 'cat0',
  541. 'culture',
  542. 'country',
  543. 'WT.mc_id',
  544. 'uiflavor', // office
  545. 'activetab',
  546. 'fl',
  547. 'client_id',
  548. 'wreply',
  549. 'cobrandid', // signin
  550. 'deeplink',
  551. 'referrer',
  552. 'mode',
  553. 'pos',
  554. );
  555. break;
  556. case /msn.(com|cn)$/.test(pageHost): // No effect on the [Shadow Root] elements.
  557. commonParams.push('ocid', 'cvid', 'ei', '.cn', 'fullscreen');
  558. break;
  559. case /bestbuy\.(com|ca)$/.test(pageHost):
  560. commonParams.push(
  561. 'id',
  562. 'ar',
  563. 'cmp',
  564. 'loc',
  565. 'irgwc',
  566. 'mpid',
  567. 'irclickid',
  568. 'intlreferer',
  569. 'intl',
  570. 'browsedCategory',
  571. 'qp',
  572. 'type',
  573. 'usc',
  574. 'iht',
  575. 'ks',
  576. 'sc',
  577. '_dyncharset',
  578. 'icmp',
  579. ); // 'subId1', 'subId2', 'subId3', 'nrtv_cid', 'nrtv_as_src',
  580. paramsReg = /^(utm_|nrtv_|subId)/;
  581. break;
  582. case pageHost.endsWith('github.com'):
  583. commonParams.push('ref_cta', 'ref_loc', 'ref_page');
  584. break;
  585. case pageHost.endsWith('stackoverflow.com'):
  586. paramsReg = /^(utm_|spm_|from_|ref|track|trk|so_)/;
  587. break;
  588. case pageHost.endsWith('pixiv.net'):
  589. commonParams.push('provider');
  590. break;
  591. case pageHost.endsWith('music.apple.com'):
  592. commonParams.push('at', 'ct', 'itscg', 'itsct');
  593. break;
  594. case pageHost.endsWith('zhihu.com'):
  595. commonParams.push(
  596. 'search_source',
  597. 'hybrid_search_source',
  598. 'hybrid_search_extra',
  599. 'utm_psn',
  600. );
  601. autoClose(
  602. '.Modal-content',
  603. '.Modal-closeButton',
  604. doc.querySelector('.AppHeader-profile button'),
  605. 2000,
  606. );
  607. break;
  608. case /(163|126|yeah)\.(com|net)$/.test(pageHost):
  609. commonParams.push('scene', 'session_id', 'fromDlpro', 'dltype');
  610. break;
  611. case pageHost.endsWith('weibo.com'):
  612. commonParams.push(
  613. 'mark_id',
  614. 'entry',
  615. '_rand',
  616. 'sudaref',
  617. 'refer',
  618. 'band_rank',
  619. 'gid',
  620. 'ua',
  621. );
  622. break;
  623. case pageHost.endsWith('qq.com'):
  624. commonParams.push('ADTAG', 'fromSource');
  625. break;
  626. case /ebay\.[a-z.]{2,15}$/.test(pageHost):
  627. commonParams.push(
  628. '_trkparms',
  629. '_trksid',
  630. 'ssPageName',
  631. 'amdata',
  632. 'mc',
  633. 'hash',
  634. 'epid',
  635. 'var',
  636. '_ssn',
  637. 'store_name',
  638. 'requested',
  639. 'itmprp',
  640. 'itmmeta',
  641. );
  642. break;
  643. case pageHost.endsWith('jd.com'):
  644. commonParams.splice(commonParams.indexOf('utm_campaign'), 1);
  645. commonParams.push(
  646. 'gx',
  647. 'ad_od',
  648. 'needRecommendFlag',
  649. 'uabt',
  650. 'd',
  651. '_fd',
  652. 'pvid',
  653. 'jxsid',
  654. 'csid',
  655. 'ss_projid',
  656. 'scan_orig',
  657. 'ss_expid',
  658. 'ss_sexpid',
  659. 'ss_ruleid',
  660. 'ss_sruleid',
  661. 'ss_symbol',
  662. 'ss_mtest',
  663. 'sceneval',
  664. );
  665. paramsReg = /^(track|wxa_|spm_|from_)/;
  666. break;
  667. case pageHost.endsWith('yangkeduo.com'):
  668. commonParams.push(
  669. 'gx',
  670. 'ad_od',
  671. 'needRecommendFlag',
  672. 'uabt',
  673. 'd',
  674. 'pxq_secret_key',
  675. 'cpsSignjb_act',
  676. 'launch_pdd',
  677. 'customParameters',
  678. 'duoduo_type',
  679. 'goods_sign',
  680. );
  681. paramsReg = /^(track|from_|utm_|_oak_|_wv|_x_)/;
  682. break;
  683. case /(hoyolab|hoyoverse|mihoyo|miyoushe|mihoyogift)\.com$/.test(pageHost):
  684. // _auth_require _presentation_style _hide_status_bar _landscape _theme _theme_device
  685. commonParams.push('game_version', 'visit_device', 'device_type', 'plat_type');
  686. paramsReg = /^(track|utm|spm_|from_|hyl_|bbs_|mhy_)|_from$/;
  687. (() => {
  688. // /account.(hoyoverse|hoyolab).com$|user.miyoushe.com$/
  689. const css = document.createElement('style');
  690. css.innerText += 'body{overflow: auto !important}';
  691. doc.addEventListener('DOMContentLoaded', () => {
  692. document.head.append(css);
  693. });
  694. })();
  695. customClean(commonParams);
  696. break;
  697. case pageHost.endsWith('douban.com'):
  698. commonParams.push(
  699. 'target_user_id',
  700. 'dcs',
  701. 'dcm',
  702. 'dt_time_source',
  703. 'channel',
  704. 'fullscreen',
  705. 'autorotate',
  706. 'hidenav',
  707. );
  708. break;
  709. case /(imdb|boxofficemojo)\.com$/.test(pageHost):
  710. commonParams.push('rf', 'imdbPageAction', 'u', 'tag');
  711. paramsReg = amznParamsReg;
  712. break;
  713. case pageHost.endsWith('gitee.com'):
  714. (() => {
  715. const intervalID = setInterval(() => {
  716. if (doc.querySelector('.menu.transition.visible')) {
  717. doc.querySelector('.menu.transition.visible').style = 'display: none !important;';
  718. }
  719. }, 50);
  720. document.addEventListener('DOMContentLoaded', () => {
  721. const timeoutId = setTimeout(() => {
  722. clearInterval(intervalID); clearTimeout(timeoutId);
  723. }, 3000);
  724. });
  725. })();
  726. break;
  727. case pageHost.endsWith('xda-developers.com'):
  728. commonParams.push(
  729. 'tag',
  730. 'ascsubtag',
  731. 'asc_refurl',
  732. 'asc_campaign',
  733. 'newsletter_popup',
  734. );
  735. break;
  736. case pageHost.endsWith('####.com'):
  737. commonParams.push('toc_style_id');
  738. break;
  739. case pageHost.endsWith('fiverr.com'):
  740. commonParams.push(
  741. 'pckg_id',
  742. 'funnel',
  743. 'context_type',
  744. 'context_alg',
  745. 'imp_id',
  746. 'pos',
  747. 'seller_online',
  748. 'context',
  749. );
  750. break;
  751. case pageHost.endsWith('newegg.com'):
  752. commonParams.push(
  753. 'cm_sp',
  754. 'nextpage',
  755. );
  756. break;
  757. case pageHost.endsWith('theverge.com'):
  758. commonParams.push(
  759. 'u1',
  760. 'tag',
  761. 'ascsubtag',
  762. 'subId1',
  763. 'subId2',
  764. 'subId3',
  765. );
  766. break;
  767. case pageHost.endsWith('bluestacks.com'):
  768. commonParams.push(
  769. 'platform',
  770. 'client_uuid',
  771. 'app_pkg',
  772. 'platform_cloud',
  773. 'preferred_lang',
  774. 'gaCookie',
  775. 'gclid',
  776. 'clickid',
  777. 'msclkid',
  778. 'affiliateId',
  779. 'offerId',
  780. 'transaction_id',
  781. 'aff_sub',
  782. 'first_landing_page',
  783. 'user_id',
  784. 'incompatible',
  785. 'bluestacks_version',
  786. 'referrer',
  787. 'download_page_referrer',
  788. ); // win_version, mac_version, exit_utm_campaign,
  789. // device_memory, device_cpu_cores
  790. paramsReg = /^device_|(_version|utm_campaign)$/;
  791. break;
  792. case pageHost.endsWith('xiao####shu.com'):
  793. autoClose(
  794. '.login-container',
  795. '.close-button',
  796. doc.querySelector('.login-btn'),
  797. 3700,
  798. );
  799. break;
  800. case pageHost.endsWith('nicovideo.jp'):
  801. commonParams.push(
  802. 'cmnhd_ref',
  803. 'device',
  804. 'site',
  805. 'pos',
  806. );
  807. break;
  808. default: break;
  809. }
  810. const params = commonParams; restoreState(params); cleanLinks(params);
  811. document.addEventListener('DOMContentLoaded', () => {
  812. blockClickEvents(params, 1200);
  813. deferredCleanLinks(params, 1000); deferredCleanLinks(params, 7000);
  814. });
  815. window.onscroll = () => {
  816. const scrolls = doc.documentElement.scrollTop;
  817. if (scrolls - topScroll > 120) { cleanLinks(params); topScroll = scrolls; }
  818. };
  819. return params;
  820. }
  821. // ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦ Bilibili ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
  822. // Remove Bilibili metadata
  823. function removeBiliMetadData() {
  824. const metas = doc.getElementsByTagName('meta');
  825. for (let i = 0; i < metas.length; i += 1) {
  826. if (metas[i].name === 'spm_prefix') { metas[i].remove(); }
  827. }
  828. }
  829. // Remove Bilibili Annoyances [Login popups, Ads]
  830. function removeBiliAnnoyances(delayTime) {
  831. const tid = setTimeout(() => {
  832. let index = 0;
  833. do {
  834. const cardAds = doc.getElementsByTagName('a');
  835. for (let i = 0; i < cardAds.length; i += 1) {
  836. if (cardAds[i].hostname.endsWith('cm.bilibili.com')) {
  837. cardAds[i].parentNode.removeChild(cardAds[i]);
  838. } // bilibili ads
  839. }
  840. index += 1;
  841. } while (index < 2); // bilibili login tips
  842. const traceDivs = doc.getElementsByClassName('bili-video-card');
  843. for (let i = 0; i < traceDivs.length; i += 1) {
  844. if (traceDivs[i].getAttribute('data-report').includes('tianma.')) {
  845. traceDivs[i].setAttribute('data-report', '0');
  846. } // bilibili ads
  847. }
  848. /**
  849. * *******************************************************
  850. * *******************************************************
  851. */
  852. const rightEntyItems = doc.getElementsByClassName('right-entry-item')
  853. || doc.getElementsByClassName('item');
  854. if (rightEntyItems[0] && rightEntyItems[0].innerText.includes('登录')) {
  855. hideElement(['.lt-row', '.bili-login-card', '.bili-mini-mask',
  856. '.is-bottom', '.v-popover-content', '.unlogin-popover'], 30, 6000, false);
  857. const loginTab = rightEntyItems[0].getElementsByTagName('span')[0];
  858. if (/登录/.test(rightEntyItems[0].innerText) && loginTab) {
  859. loginTab.outerHTML = '<a href="https://passport.bilibili.com/login"'
  860. + ' target="_blank" onmouseup="cleanLinks(bilibiliParams)">登录</a>';
  861. }
  862. } clearTimeout(tid);
  863. doc.getElementById('right-bottom-banner').remove();
  864. }, delayTime);
  865. }
  866. // block clicking events (link, button, li)
  867. function blockBClickEvents() {
  868. const handleBClickBub = (e) => { e.stopImmediatePropagation(); };
  869. function blockBLinkEvents() {
  870. const links = doc.getElementsByTagName('a');
  871. for (let i = 0; i < links.length; i += 1) {
  872. if (links[i].getAttribute('data-video-time') === null && hostRegex.test(links[i].hostname)) {
  873. const isLinkJump = links[i].classList.contains('jump-link');
  874. const isLinkJumpVideo = links[i].classList.contains('video-time')
  875. || links[i].classList.contains('video');
  876. if (!(isLinkJump && isLinkJumpVideo)) {
  877. if (pageHost.endsWith('bilibili.com')) {
  878. links[i].removeEventListener('click', handleBClickBub);
  879. links[i].addEventListener('click', handleBClickBub);
  880. }
  881. links[i].removeEventListener('contextmenu', handleBClickBub);
  882. if (links[i].ontouchstart === undefined) {
  883. links[i].addEventListener('contextmenu', handleBClickBub);
  884. }
  885. links[i].removeEventListener('pointerdown', handleBClickBub);
  886. links[i].addEventListener('pointerdown', handleBClickBub);
  887. }
  888. }
  889. }
  890. }
  891. blockBLinkEvents();
  892. function deferredBlockBLinkEvents(delayTime) {
  893. const tid = setTimeout(() => {
  894. cleanLinks(bilibiliParams); removeBiliAnnoyances(0); blockBLinkEvents(); clearTimeout(tid);
  895. }, delayTime);
  896. }
  897. const handleClickFast = () => { deferredBlockBLinkEvents(DELAY_TIME.fast); };
  898. const buttons = doc.getElementsByTagName('button');
  899. for (let i = 0; i < buttons.length; i += 1) {
  900. if (buttons[i].className) {
  901. buttons[i].removeEventListener('click', handleClickFast);
  902. buttons[i].addEventListener('click', handleClickFast);
  903. }
  904. }
  905. const lines = doc.getElementsByTagName('li');
  906. for (let i = 0; i < lines.length; i += 1) {
  907. if (lines[i].className && !lines[i].classList.contains('context-sub-menu-item')) {
  908. lines[i].removeEventListener('click', handleClickFast);
  909. lines[i].addEventListener('click', handleClickFast);
  910. }
  911. }
  912. // iframe - live
  913. if (pageURL.startsWith('https://live.bilibili.com/blackboard/dropdown')) {
  914. document.addEventListener('DOMContentLoaded', () => {
  915. document.addEventListener('click', (e) => { e.stopPropagation(); }, true);
  916. });
  917. }
  918. }
  919. function deferredBlockBClickEvents(delayTime) {
  920. restoreState(bilibiliParams);
  921. const tid = setTimeout(() => { blockBClickEvents(); clearTimeout(tid); }, delayTime);
  922. }
  923. // Loop execution when the mouse moves
  924. function bilibiliListenMoving() {
  925. let x = 0; let y = 0;
  926. if (/live.bilibili.com$/.test(pageHost)
  927. || /^https?:\/\/(www|m).bilibili\.com\/(video|bangumi)/.test(pageURL)) {
  928. window.onpointermove = (e) => {
  929. if (e.clientY < 200) {
  930. cleanLinks(bilibiliParams);
  931. blockBClickEvents();
  932. }
  933. };
  934. } else {
  935. window.onpointermove = (e) => {
  936. if (Math.abs(e.clientX - x) > 20 || Math.abs(e.clientY - y) > 20) {
  937. cleanLinks(bilibiliParams);
  938. blockBClickEvents();
  939. x = e.clientX; y = e.clientY;
  940. }
  941. };
  942. }
  943. }
  944. // Loop execution when scrolling
  945. function biliListenScrolling() {
  946. window.onscroll = () => {
  947. const scrolls = doc.documentElement.scrollTop;
  948. if (scrolls - topScroll > 120) {
  949. cleanLinks(bilibiliParams);
  950. removeBiliAnnoyances(0);
  951. blockBClickEvents();
  952. topScroll = scrolls;
  953. }
  954. };
  955. }
  956. // bilibili search events
  957. function blockBSearchItemEvents() {
  958. function blockSearchEvents() {
  959. // input suggested items
  960. const suggestItems = doc.getElementsByClassName('suggest-item');
  961. const handleBSearchClick = () => { deferredBlockBClickEvents(DELAY_TIME.fast); };
  962. if (suggestItems) {
  963. for (let i = 0; i < suggestItems.length; i += 1) {
  964. suggestItems[i].addEventListener('click', handleBSearchClick, true);
  965. }
  966. }
  967. // search trending items
  968. const topSearchs = doc.getElementsByClassName('trending-item');
  969. if (topSearchs) {
  970. for (let i = 0; i < topSearchs.length; i += 1) {
  971. topSearchs[i].addEventListener('click', handleBSearchClick, true);
  972. }
  973. }
  974. // search history items
  975. const historyItems = doc.getElementsByClassName('history-item');
  976. if (historyItems) {
  977. for (let i = 0; i < historyItems.length; i += 1) {
  978. historyItems[i].addEventListener('click', handleBSearchClick, true);
  979. }
  980. }
  981. }
  982. const handleBSearchClickB = () => {
  983. const tid = setTimeout(() => { blockSearchEvents(); clearTimeout(tid); }, DELAY_TIME.fast);
  984. };
  985. // search input area
  986. if (doc.querySelector('.search-input-el')) {
  987. doc.querySelector('.search-input-el').addEventListener('click', handleBSearchClickB, true);
  988. }
  989. // clear icon
  990. if (doc.querySelector('.clear-icon')) {
  991. doc.querySelector('.clear-icon').addEventListener('click', handleBSearchClickB, true);
  992. }
  993. }
  994. // search.bilibili.com/*
  995. function cleanBSearch() {
  996. blockBSearchItemEvents();
  997. // paging button clicking event
  998. const pageButtons = doc.getElementsByClassName('vui_pagenation--btn'); // div
  999. if (pageButtons) {
  1000. for (let i = 0; i < pageButtons.length; i += 1) {
  1001. pageButtons[i].addEventListener('click', () => { deferredBlockBClickEvents(DELAY_TIME.fast); }, true);
  1002. }
  1003. }
  1004. deferredBlockBClickEvents(DELAY_TIME.normal); deferredCleanLinks(bilibiliParams, DELAY_TIME.slow - 600);
  1005. }
  1006. // www.bilibili.com/video/*
  1007. function cleanBVideoURL() {
  1008. cleanLinks(bilibiliParams);
  1009. doc.addEventListener('DOMContentLoaded', () => {
  1010. if (doc.querySelector('.rec-footer')) {
  1011. doc.querySelector('.rec-footer').addEventListener('click', () => {
  1012. deferredCleanLinks(bilibiliParams, DELAY_TIME.fast);
  1013. deferredBlockBClickEvents(bilibiliParams, DELAY_TIME.fast);
  1014. }, true);
  1015. }
  1016. // Clean copying of video URLs (copy share)
  1017. let toolBar; let sharInner; let sharOuter;
  1018. if (/^\/video\//.test(pagePath)) {
  1019. toolBar = '#arc_toolbar_report'; sharOuter = 'share-btn-outer'; sharInner = 'share-btn-inner';
  1020. } else if (/^\/bangumi\//.test(pagePath)) {
  1021. toolBar = '.toolbar'; sharOuter = 'share-container-id'; sharInner = 'link_copy';
  1022. }
  1023. let vid; const url = new URL(window.location.href);
  1024. const handleWriteText = () => { navigator.clipboard.writeText(pageURL); };
  1025. if (doc.querySelector(toolBar)) {
  1026. doc.querySelector(toolBar).addEventListener('pointermove', () => {
  1027. if (doc.getElementById(sharOuter)) {
  1028. doc.getElementById(sharOuter).removeEventListener('click', handleWriteText);
  1029. doc.getElementById(sharOuter).addEventListener('click', handleWriteText);
  1030. doc.getElementById(sharInner).addEventListener('click', (event) => {
  1031. event.stopImmediatePropagation();
  1032. if (doc.getElementById(sharInner).innerText.includes('精准')) {
  1033. if (pagePath.indexOf('/video/') === 0) {
  1034. vid = doc.querySelector('video') || doc.querySelector('bwp-video'); // Chrome Firefox Edge ..
  1035. } else if (pagePath.indexOf('/bangumi/') === 0) {
  1036. vid = doc.getElementsByTagName('video')[1] || doc.querySelector('bwp-video');
  1037. }
  1038. url.searchParams.set('t', vid.currentTime.toFixed(2));
  1039. navigator.clipboard.writeText(url.toString());
  1040. } else { navigator.clipboard.writeText(pageURL); }
  1041. });
  1042. }
  1043. });
  1044. }
  1045. });
  1046. }
  1047. // live.bilibili.com/*
  1048. function cleanBLive(delayTime) {
  1049. // live.bilibili.com popups
  1050. const livePopupBlock = (selection) => {
  1051. if (selection && doc.getElementById('anchor-guest-box-id')) {
  1052. doc.getElementById('anchor-guest-box-id').style.display = 'none';
  1053. } else if (!selection) {
  1054. doc.getElementById('anchor-guest-box-id').style.display = '';
  1055. }
  1056. const iframes = doc.getElementsByTagName('iframe');
  1057. for (let i = 0; i < iframes.length; i += 1) {
  1058. if (iframes[i].src.includes('live-lottery')) {
  1059. if (selection) {
  1060. iframes[i].style.visibility = 'hidden';
  1061. } else {
  1062. iframes[i].style.visibility = '';
  1063. }
  1064. }
  1065. }
  1066. };
  1067. const tid1 = setTimeout(() => {
  1068. const navis = doc.getElementsByClassName('tabs__tag-item'); // cat
  1069. if (navis) {
  1070. for (let i = 0; i < navis.length; i += 1) {
  1071. navis[i].addEventListener('click', () => {
  1072. deferredCleanLinks(bilibiliParams, DELAY_TIME.fast);
  1073. }, true);
  1074. }
  1075. }
  1076. const tabItems = doc.getElementsByClassName('tab-item'); // sort
  1077. if (tabItems) {
  1078. for (let i = 0; i < tabItems.length; i += 1) {
  1079. tabItems[i].addEventListener('click', () => {
  1080. blockBClickEvents();
  1081. deferredCleanLinks(bilibiliParams, DELAY_TIME.fast);
  1082. }, true);
  1083. }
  1084. } clearTimeout(tid1);
  1085. }, delayTime);
  1086. const intervalID = setInterval(
  1087. livePopupBlock(BlockLivePopups),
  1088. DELAY_TIME.normal * 2,
  1089. );
  1090. const tid2 = setTimeout(() => {
  1091. clearInterval(intervalID);
  1092. clearTimeout(tid2);
  1093. }, DELAY_TIME.slow + 3000 * 300);
  1094. }
  1095. // ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦ Baidu ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
  1096. // Baidu related search, Hot search URL cleaning
  1097. function cleanBaidu() {
  1098. if (pageHost.endsWith('news.baidu.com')) {
  1099. baiduParams.push('toc_style_id', 'share_to', 'track_id');
  1100. }
  1101. restoreState(baiduParams);
  1102. function removeBDAds() {
  1103. const searchAds = document.getElementsByClassName('EC_r###lt');
  1104. if (searchAds) {
  1105. for (let i = 0; i < searchAds.length; i += 1) {
  1106. searchAds[i].remove();
  1107. }
  1108. }
  1109. }
  1110. if (pageHost.endsWith('tieba.baidu.com') && baiduParams.includes('ie')) {
  1111. baiduParams.splice(baiduParams.indexOf('ie'), 1);
  1112. }
  1113. function cleanBDLinks(siteParams) {
  1114. cleanLinks(baiduParams);
  1115. const links = doc.getElementsByTagName('a');
  1116. for (let i = 0; i < links.length; i += 1) {
  1117. if (hostRegex.test(links[i].hostname)) {
  1118. if (links[i].hostname.endsWith('zhidao.baidu.com') && links[i].pathname === '/q') {
  1119. links[i].pathname = '/search';
  1120. }
  1121. links[i].href = links[i].href.replace('from=', '');
  1122. }
  1123. }
  1124. if (doc.querySelector('area')) {
  1125. const areaURL = new URL(doc.querySelector('area').href);
  1126. const params = areaURL.searchParams;
  1127. siteParams.forEach((k) => {
  1128. if (params.has(k)) { params.delete(k); }
  1129. });
  1130. doc.querySelector('area').href = areaURL.href;
  1131. }
  1132. }
  1133. function blockBDTrackingEvents() {
  1134. doc.addEventListener('DOMContentLoaded', () => {
  1135. const links = doc.getElementsByTagName('a');
  1136. for (let i = 0; i < links.length; i += 1) {
  1137. if (links[i].href !== '') {
  1138. links[i].addEventListener('click', () => {
  1139. cleanBDLinks(baiduParams);
  1140. }, true);
  1141. }
  1142. }
  1143. });
  1144. }
  1145. cleanBDLinks(baiduParams); blockBDTrackingEvents();
  1146. if (pagePath === '/s') removeBDAds();
  1147. window.onscroll = () => {
  1148. const scrolls = doc.documentElement.scrollTop;
  1149. if (scrolls - topScroll > 120) {
  1150. cleanLinks(baiduParams); topScroll = scrolls;
  1151. }
  1152. if (pagePath === '/s') { removeBDAds(); } // Baidu search ads
  1153. };
  1154. let x = 0; let y = 0;
  1155. window.onpointermove = (e) => {
  1156. if (Math.abs(e.clientX - x) > 20 || Math.abs(e.clientY - y) > 20) {
  1157. cleanLinks(baiduParams); x = e.clientX; y = e.clientY;
  1158. }
  1159. };
  1160. }
  1161. // ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦ CSDN ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
  1162. function cleanCSDN() {
  1163. restoreState(csdnParams); deferredCleanLinks(csdnParams, DELAY_TIME.normal);
  1164. // CSDN.net tracking events
  1165. function blockCSDNEvents() {
  1166. const links = doc.getElementsByTagName('a');
  1167. for (let i = 0; i < links.length; i += 1) {
  1168. if (links[i].hostname) {
  1169. links[i].addEventListener('click', (e) => {
  1170. e.stopImmediatePropagation();
  1171. });
  1172. }
  1173. }
  1174. }
  1175. window.onpointermove = (e) => {
  1176. if (e.clientY < 170 || e.clientY > 450) {
  1177. cleanLinks(csdnParams); blockCSDNEvents();
  1178. }
  1179. };
  1180. window.onscroll = () => {
  1181. const scrolls = doc.documentElement.scrollTop;
  1182. if (scrolls - topScroll > 120) {
  1183. cleanLinks(csdnParams);
  1184. blockCSDNEvents(); topScroll = scrolls;
  1185. }
  1186. };
  1187. }
  1188. // ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦ Ali Sites ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
  1189. function cleanAliSites() {
  1190. switch (true) { // taobao.com/tmall.com/tmall.hk
  1191. case /(taobao|tmall).(com|hk)$/.test(pageHost):
  1192. aliParams.push(
  1193. 'scm2',
  1194. 'stats_click',
  1195. 'initiative_id',
  1196. 'source',
  1197. 'suggest',
  1198. 'suggest_query',
  1199. 'iconType',
  1200. 'traceId',
  1201. 'relationId',
  1202. 'union_lens',
  1203. 'ref',
  1204. 'ali_trackid',
  1205. 'ak',
  1206. 'detailSharePosition',
  1207. 'topOfferIds',
  1208. 'sp_abtk',
  1209. 'search_condition',
  1210. 'industryCatId',
  1211. 'tbSocialPopKey',
  1212. 'bxsign',
  1213. 'utparam',
  1214. 'eurl',
  1215. 'itemIds',
  1216. 'country',
  1217. 'epid',
  1218. 'user_number_id',
  1219. 'rootPageId',
  1220. 'lwfrom',
  1221. 'disableNav',
  1222. 'es',
  1223. 'rand',
  1224. '_lgt_',
  1225. 'x5referer',
  1226. 'status_bar_transparent',
  1227. 'tracelog',
  1228. );
  1229. break;
  1230. case pageHost.endsWith('fliggy.com'):
  1231. aliParams.push('ad_id', 'am_id', 'cm_id', 'pm_id', '_k');
  1232. break;
  1233. case pageHost.endsWith('1688.com'):
  1234. aliParams.push(
  1235. 'scm2',
  1236. 'topOfferIds',
  1237. '__pageId__',
  1238. 'resourceId',
  1239. 'offerId',
  1240. 'offerIds',
  1241. 'object_id',
  1242. 'udsPoolId',
  1243. 'r###ltType',
  1244. 'cms_id',
  1245. 'pha_html',
  1246. '__existtitle__',
  1247. 'object_type',
  1248. 'delivery_pool_id',
  1249. 'delivery_pool_type',
  1250. 'ilike_session',
  1251. 'tracelog',
  1252. 'clickid',
  1253. 'sessionid',
  1254. 'cosite',
  1255. '_p_isad',
  1256. 'exp',
  1257. 'rootPageId',
  1258. 'lwfrom',
  1259. 'disableNav',
  1260. 'es',
  1261. 'hpageId',
  1262. );
  1263. break;
  1264. case /(lazada|trendyol).[a-z.]{2-10}/.test(pageHost):
  1265. aliParams.push(
  1266. 'shareUniqueId',
  1267. 'clickTrackInfo',
  1268. 'data_prefetch',
  1269. 'at_iframe',
  1270. 'prefetch_replace',
  1271. 'wc',
  1272. );
  1273. break;
  1274. default: break;
  1275. }
  1276. restoreState(aliParams);
  1277. deferredCleanLinks(aliParams, DELAY_TIME.slow);
  1278. doc.addEventListener('DOMContentLoaded', () => {
  1279. blockClickEvents(aliParams, DELAY_TIME.fast);
  1280. });
  1281. window.onscroll = () => {
  1282. const scrolls = doc.documentElement.scrollTop;
  1283. if (scrolls - topScroll > 120) {
  1284. cleanLinks(aliParams);
  1285. blockClickEvents(aliParams, 0); topScroll = scrolls;
  1286. }
  1287. };
  1288. }
  1289. // ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦ Youtube ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
  1290. function cleanYoutube() {
  1291. function blockytLinksRedirection(timeout) {
  1292. setTimeout(() => {
  1293. const outerLinks = document.getElementsByClassName('yt-core-attributed-string--link-inherit-color');
  1294. for (let i = 0; i < outerLinks.length; i += 1) {
  1295. outerLinks[i].addEventListener('click', (e) => {
  1296. e.stopPropagation();
  1297. }, true);
  1298. }
  1299. }, timeout);
  1300. }
  1301. restoreState(ytParams); cleanLinks(ytParams);
  1302. doc.addEventListener('DOMContentLoaded', () => {
  1303. deferredCleanLinks(ytParams, DELAY_TIME.slow);
  1304. blockClickEvents(ytParams, 0);
  1305. blockytLinksRedirection(DELAY_TIME.normal * 2);
  1306. });
  1307. doc.addEventListener('contextmenu', () => {
  1308. cleanLinks(ytParams);
  1309. if (pagePath === '/r###lts') {
  1310. doc.addEventListener('pointerenter', (e) => {
  1311. e.stopPropagation();
  1312. cleanLinks(ytParams);
  1313. }, true);
  1314. }
  1315. window.onscroll = () => {
  1316. const scrolls = doc.documentElement.scrollTop;
  1317. if (scrolls - topScroll > 120) {
  1318. cleanLinks(ytParams);
  1319. blockytLinksRedirection(0);
  1320. topScroll = scrolls;
  1321. }
  1322. };
  1323. // Modifications for CM of youtube player
  1324. const shareURL = new URL('https://youtube.com/watch');
  1325. if (new URL(pageURL).searchParams.has('list')) {
  1326. shareURL.searchParams
  1327. .set('list', new URL(pageURL).searchParams.get('list'));
  1328. }
  1329. if (pagePath.startsWith('/watch')) {
  1330. shareURL.searchParams.set('v', new URL(pageURL).searchParams.get('v'));
  1331. const videoCM = doc.getElementsByClassName('ytp-contextmenu')[0]
  1332. .getElementsByClassName('ytp-menuitem');
  1333. videoCM[1].addEventListener('click', () => {
  1334. navigator.clipboard.writeText(shareURL.href);
  1335. });
  1336. videoCM[2].addEventListener('click', () => {
  1337. shareURL.searchParams.set(
  1338. 't',
  1339. doc.getElementsByTagName('video')[0].currentTime.toFixed(0),
  1340. );
  1341. navigator.clipboard.writeText(shareURL.href);
  1342. });
  1343. }
  1344. if (pagePath.startsWith('/embed')) { // Embedded youtube videos
  1345. shareURL.searchParams.set('v', pagePath.replace('/embed/', ''));
  1346. const videoCM = doc.getElementsByClassName('ytp-contextmenu')[0]
  1347. .getElementsByClassName('ytp-menuitem');
  1348. videoCM[2].addEventListener('click', () => {
  1349. navigator.clipboard.writeText(shareURL.href);
  1350. });
  1351. videoCM[3].addEventListener('click', () => {
  1352. shareURL.searchParams.set(
  1353. 't',
  1354. doc.getElementsByTagName('video')[0].currentTime.toFixed(0),
  1355. );
  1356. navigator.clipboard.writeText(shareURL.href);
  1357. });
  1358. }
  1359. });
  1360. }
  1361. // ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦ Main Function ✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦✦
  1362. (() => {
  1363. // Menu language (May not change properly due to browser settings)
  1364. let MenuClean; let MenuAddParams; let InputTitle; let invalidFormat;
  1365. let MenuRemoveParam; let noSuchParam; let addedParamsMenu;
  1366. let noCustomParamPrompt;
  1367. switch (navigator.language) {
  1368. case 'zh-CN' || 'zh-SG':
  1369. MenuClean = '手动清理链接';
  1370. MenuAddParams = '添加自定义参数(半角英文模式)';
  1371. InputTitle = '请输入单个指定的参数(仅支持字母,数字,下划线,短破折号(-)与任意类型的括号)';
  1372. invalidFormat = '无效的参数格式 ';
  1373. MenuRemoveParam = '移除一个手动添加的参数(页面刷新后生效)';
  1374. noSuchParam = '无此参数';
  1375. addedParamsMenu = '已添加的自定义参数\n\n';
  1376. noCustomParamPrompt = '暂未添加任何的自定义参数';
  1377. break;
  1378. case 'zh-TW' || 'zh-HK':
  1379. MenuClean = '手動清理鏈接';
  1380. MenuAddParams = '添加自定義参数(半角英文模式)';
  1381. InputTitle = '請輸入單個指定的參數(僅支持字母,數字,下劃線,短破折號(-)與任意類型的括號)';
  1382. invalidFormat = '無效的參數格式 ';
  1383. MenuRemoveParam = '移除一個手動添加的參數(頁面刷新後生效)';
  1384. noSuchParam = '無此參數';
  1385. addedParamsMenu = '已添加的自定義參數\n\n';
  1386. noCustomParamPrompt = '暫未添加任何的自定義參數';
  1387. break;
  1388. default: // English and others
  1389. MenuClean = 'Retry link cleaning';
  1390. MenuAddParams = 'Add a custom parameter (English Mode)';
  1391. InputTitle = 'Please enter a single parameter below \n(only support '
  1392. + 'letters, numbers, underscore, en-dash and all types of brackets):';
  1393. invalidFormat = 'Not a valid parameter format ';
  1394. MenuRemoveParam = 'Remove a custom parameter (Effect after refresh)';
  1395. noSuchParam = 'No such parameter.';
  1396. addedParamsMenu = 'Get all custom added params:\n\n';
  1397. noCustomParamPrompt = 'No added custom parameters now!';
  1398. break;
  1399. } // -._~:/?#[]@!$&'()*+,;=
  1400. // Add custom params from the Script menu (Submenu of addons)
  1401. function addCustomParam(inputParam, storedArray) {
  1402. if (/^[a-zA-Z0-9()[\]{}<>_-]*$/.test(inputParam)) {
  1403. let list; // eslint-disable-next-line no-undef
  1404. if (GM_getValue(pageHost)) { // eslint-disable-next-line no-undef
  1405. list = GM_getValue(pageHost);
  1406. } else {
  1407. list = [];
  1408. } // eslint-disable-next-line no-undef
  1409. if (inputParam) { list.push(inputParam); GM_setValue(pageHost, list); }
  1410. list.forEach((v) => {
  1411. if (!storedArray.includes(v)) { storedArray.push(v); }
  1412. });
  1413. } else {
  1414. alert(invalidFormat);
  1415. }
  1416. }
  1417. // get all custom added param
  1418. function getCustomParams() {
  1419. let list; // eslint-disable-next-line no-undef
  1420. if (GM_getValue(pageHost)) { // eslint-disable-next-line no-undef
  1421. list = GM_getValue(pageHost);
  1422. } else {
  1423. list = [];
  1424. } // eslint-disable-next-line no-undef
  1425. return list;
  1426. }
  1427. // Remove a parameter that has been added from the script menu
  1428. function removeCustomAddedParam(inputParam) {
  1429. if (inputParam !== null && inputParam !== undefined) {
  1430. let list; // eslint-disable-next-line no-undef
  1431. if (GM_getValue(pageHost)) { // eslint-disable-next-line no-undef
  1432. list = GM_getValue(pageHost);
  1433. } else {
  1434. list = [];
  1435. }
  1436. if (list.includes(inputParam)) {
  1437. list = list.filter((item) => item !== inputParam); // eslint-disable-next-line no-undef
  1438. GM_setValue(pageHost, list);
  1439. } else {
  1440. alert(noSuchParam);
  1441. }
  1442. }
  1443. }
  1444. let siteParams;// For script menu
  1445. switch (true) {
  1446. case pageHost.endsWith('youtube.com'):
  1447. siteParams = ytParams; cleanYoutube(siteParams);
  1448. break;
  1449. case pageHost.endsWith('baidu.com'):
  1450. siteParams = baiduParams; cleanBaidu(); cleanLinks(baiduParams);
  1451. break;
  1452. case /amazon\.[a-z.]{2,15}$/.test(pageHost):
  1453. siteParams = amaznParams; paramsReg = amznParamsReg;
  1454. customClean(siteParams, paramsReg);
  1455. break; // REST: space passport account message member t app manga show link biligame mall pay
  1456. case /(bilibili|biligame)\.com$/.test(pageHost): // && pagePath !== '/mall/upower-pay/'
  1457. siteParams = bilibiliParams; paramsReg = biliParamsReg;
  1458. restoreState(bilibiliParams);
  1459. cleanLinks(bilibiliParams);
  1460. blockBClickEvents();
  1461. if (pageHost.endsWith('www.bilibili.com')) cleanBVideoURL();
  1462. if (pageHost.endsWith('search.bilibili.com')) cleanBSearch();
  1463. if (pageHost.endsWith('live.bilibili.com')) cleanBLive(DELAY_TIME.normal);
  1464. doc.addEventListener('DOMContentLoaded', () => {
  1465. biliListenScrolling(); bilibiliListenMoving();
  1466. removeBiliMetadData();
  1467. deferredBlockBClickEvents(1000);
  1468. });
  1469. break;
  1470. case aliSitesReg.test(pageHost):
  1471. siteParams = aliParams; paramsReg = aliParamsReg;
  1472. cleanAliSites();
  1473. break;
  1474. case pageHost.endsWith('csdn.net'):
  1475. siteParams = csdnParams; cleanCSDN();
  1476. break;
  1477. case /(youku|tudou)\.com$/.test(pageHost):
  1478. siteParams = youkuTudouParams; paramsReg = aliParamsReg;
  1479. customClean(siteParams);
  1480. break;
  1481. case /(tiktok|douyin)\.com$/.test(pageHost):
  1482. siteParams = douyinParams; customClean(siteParams);
  1483. // '#login-pannel', '.dy-account-close',
  1484. break;
  1485. default:
  1486. siteParams = commonClean();
  1487. break;
  1488. }
  1489. addCustomParam('', siteParams);
  1490. // show all custom added param
  1491. function showCustomParams() {
  1492. const list = getCustomParams(siteParams);
  1493. if (list.length > 0) {
  1494. alert(addedParamsMenu + list.join(', '));
  1495. } else {
  1496. alert(noCustomParamPrompt);
  1497. }
  1498. } // eslint-disable-next-line no-undef
  1499. GM_registerMenuCommand(MenuClean, () => { // Menu: Retry clean all links
  1500. restoreState(siteParams);
  1501. cleanLinks(siteParams);
  1502. console.log(baiduParams);
  1503. }, 'C');
  1504. // eslint-disable-next-line no-undef
  1505. GM_registerMenuCommand(MenuAddParams, () => { // Menu: Add a custom param
  1506. addCustomParam(prompt(InputTitle, ''), siteParams);
  1507. });
  1508. // eslint-disable-next-line no-undef
  1509. GM_registerMenuCommand(MenuRemoveParam, () => { // Menu: Remove a custom param
  1510. const list = getCustomParams(siteParams);
  1511. if (list.length > 0) {
  1512. const inputParam = prompt(`${addedParamsMenu + list.join(', ')}`, '');
  1513. removeCustomAddedParam(inputParam);
  1514. } else {
  1515. alert(noCustomParamPrompt);
  1516. }
  1517. });
  1518. // eslint-disable-next-line no-undef
  1519. GM_registerMenuCommand(addedParamsMenu, showCustomParams);
  1520. window.addEventListener('urlchange', () => {
  1521. restoreState(siteParams);
  1522. cleanLinks(siteParams);
  1523. blockClickEvents(siteParams, 0);
  1524. });
  1525. window.addEventListener('keydown', (e) => { // [Alt + Shift + X]
  1526. if (e.key === 'X' && e.altKey && e.shiftKey) {
  1527. restoreState(siteParams);
  1528. cleanLinks(siteParams);
  1529. if (pageHost.includes('bilibili.com')) removeBiliAnnoyances(0);
  1530. }
  1531. });
  1532. })();
  1533. })();
  1534. /*
  1535. # Changelog
  1536. v0.7.8 2024.09.27
  1537. - Clear more tracking elements on bilibili|nicovideo|google|microsoft|ebay.
  1538. - Optimised the clean condtions on baidu search r###lt.
  1539. - Various script optimisations.
  1540. - Add some menus to get or delete custom added params. (Thanks to @JerryYang-30)
  1541. v0.7.7 2024.03.21
  1542. - Fix some issues on douyin.com|hoyolab.com under certain conditions.
  1543. - Fix an issus that this script may keep preventing users to pay for bili ups.
  1544. - Certain functions optimisations.
  1545. v0.7.6.2 2024.03.14
  1546. - Fix an issue that certain pages of bilibili may not be functional.
  1547. v0.7.6.1 2024.03.12
  1548. - Fix an issue that certain pages of bilibili may not be functional.
  1549. v0.7.6 2024.03.12
  1550. - Clean more parameters on google.com.
  1551. - Remove a banner ad on bilibili's video page.
  1552. - Adjust cleanup scope on t.bilibili.com.
  1553. - Fix an issue that some contents may not be loaded properly on Zhihu or other sites.
  1554. v0.7.5 2023.11.21
  1555. - Resotore necessary parameters for baidu.com|qq.com in some cases.
  1556. - Minor adjustments.
  1557. v0.7.4 2023.10.22
  1558. - Clean more tracking parameters on 1688|microsoft|linkedin|bluestacks.com and for all.
  1559. - Skip the links redirection on youtube video.
  1560. - Minor improvements.
  1561. v0.7.3 2023.09.28
  1562. - Clean more tracking parameters on (newegg|bestbuy|skype|office|microsoft365|douban).com.
  1563. - Minor issue fixes.
  1564. v0.7.2 2023.09.16
  1565. - Fixed an issue that some prompts unable to close on live.bilibili.com.
  1566. - Fixed an issue that some contents may not be loaded properly.
  1567. - Fixed an issue that certain login prompts may failed to popup.
  1568. v0.7.1 2023.09.10
  1569. - Restore the essential parameters for discord callbacks.
  1570. - Clean more parameters.
  1571. v0.7.0 2023.09.08
  1572. - Clean more tracking params on bestbuy|amazon|baidu|douyin|ebay|jd.
  1573. - Improves the performance on ali sites.
  1574. - Minor issues fixes and improvements.
  1575. v0.6.12 2023.08.28
  1576. - Minor optimisations to be compatible with page adjustments of zhihu.com.
  1577. v0.6.11 2023.08.24
  1578. - Fixed an issue when preventing certain events may cause parts of the page malfunctional.
  1579. - Fixed an issue that some contents on the video page of bilibili failed to load.
  1580. - Minor issues fixes.
  1581. v0.6.10 2023.08.19
  1582. - Fix an issue where the CM for soem sites may fail to prompt in mobile-view mode.
  1583. v0.6.9 2023.08.15
  1584. - Clean more parameters common, (bilibili|1688|taobao|pixiv|fiverr).
  1585. - Improve performance on ali sites (reduce regex mathcing words).
  1586. - Minor issues fixes and performance improvments.
  1587. v0.6.8 2023.07.02
  1588. - Temporarily hide annoying content on `gitee.com`.
  1589. - Clean more parameters for ali sties includes `jiyoujia|fliggy.com`.
  1590. - Minor issuss fixes and performance improvemets.
  1591. v0.6.7 2023.06.24
  1592. - Clean more parameters for `all|dzen.ru|yangkeduo.com|imdb|boxofficemojo|qq|bilibili.com`.
  1593. - Clean all parameters whose names match `^spm|scm`, optimised the regexp matching.
  1594. - Allow using en-dash `(-)` on the function of add custom parameters.
  1595. - Performance improvements.
  1596. v0.6.6.1 2023.06.15
  1597. - Fixed an issue where the missing existence detection for bilibili may cause numerous error messages (Check before use).
  1598. v0.6.6 2023.06.15
  1599. - Remove more tracking parameters on `Amazon|LinkedIn.com|ebay|Youtube.com|Imdb|Bilibili|Apple.com` and common parameters.
  1600. - Allow adding custom parameters to the websites that in additional cleaning.
  1601. - Block more tracking events within its iframe, remove ad-links`(right-bottom-banner|bannerAd)` on bilibili.com.
  1602. - Performance improvements and issue fixes.
  1603. v0.6.5 2023.06.07
  1604. - Clean more tracking params on `Google|Bilibili|Youtube|Stackoverflow|Bing.com|Xbox.com|Facebook|Amazon`, block more tracking events.
  1605. - Clean tracking params at the hash of URLs on `Google`.
  1606. - Allow using numbers and other types of brackets on the function of add custom parameters.
  1607. - More precise domain name matching. (function includes() >> startsWith/endsWith/Regular Expression).
  1608. - Fix most timeout issues, and other issue fixes and performance improvements (events listening optimisations).
  1609. - Additional feature: hide login popups for `zhihu.com|hoyolab.com`.
  1610. v0.6.4 2023.06.02
  1611. - Reduce event blocking scope that binds to the elements `<a>` (capturing >> bubbling).
  1612. - Clean more tracking params on `linkedin|tmall|facebook|google|ebay.com`, block tracking events on `linkedin.com`.
  1613. - Clean copying of video urls after right-click at the main video on `youtube.com` (unshorten without tracking params).
  1614. - Other improvements.
  1615. v0.6.3 2023.05.26
  1616. - Description optimisation (Script menu).
  1617. - Script optimisation, update excludes.
  1618. - Remove more parameters for `Amazon, Taobao, Reddit`, bilibili.com/bangumi.
  1619. - Add a function of quick cleaning with keyboard (Shift + Alt + X), find in the script code to custom: `e.key === 'X'`.
  1620. v0.6.2.2 2023.05.22
  1621. - Regex checking (when add custom param) optimisation (allow using `[]` in parameter).
  1622. v0.6.2.1 2023.05.22
  1623. - Script language optimisation.
  1624. v0.6.2 2023.05.22
  1625. - Script logic and performance optimisation.
  1626. - Add format validation before adding params (from GM_setValue to storage);
  1627. - Add a script menu function which can remove a custom added parameter.
  1628. - Remove more tracking params.
  1629. - Remove Baidu Search ad r###lts (Testing).
  1630. v0.6.1 2023.05.18
  1631. - Fix an error about array merging, from Array.push() to Array.concat().
  1632. - Clean more params for common sites and `Amazon`, `weibo|stackoverflow|tmall.com`.
  1633. - Reconstruct the functions of history (bind urlchange event to pushState and replaceState).
  1634. - Custom cleaning for `Amazon`.
  1635. - Added a submenu to support adding custom params for current site (host).
  1636. v0.6.0 2023.05.15
  1637. - Clean more parameters for `(douban|imdb|vk|weibo|163|126|baidu.com)|yeah.net`.
  1638. - Resote some parameters for `xda-developers.com`.
  1639. - Add a function of copy cleaning precise time on the video pages of `bilibili`.
  1640. - Clean up copy link behavior on context menu.
  1641. - Script code and regexps matching optimisation, fix several bugs.
  1642. v0.5.8 2023.05.10
  1643. - Fix an issue where the script submenu on github.com was not displayed successfully.
  1644. - Clean copy texts when share video on the video page of bilibili.
  1645. - Clean more parameters for `douyin|tiktok|zhihu|douban|twitter|xda-developers|baidu|####.com`.
  1646. - Block signin popups once when enter the pages of zhihu.com.
  1647. - Remove more params for `hoyolab|hoyoverse|mihoyo|miyoushe|miyougift.com` with futnion-commonClean.
  1648. - Timeuout logic optimisation.
  1649. v0.5.7 2023.05.05
  1650. - Optiomise the monitoring of certain events.
  1651. - Remove more parameters for `github|medium|xda-developers|youku.(com)`.
  1652. - Bug fixes.
  1653. v0.5.6 2023.04.28
  1654. - Restore a necessary parameter for baidu.com.
  1655. v0.5.5 2023.04.28
  1656. - Restore normall events within the bili-live player under right-menu clicking.
  1657. - Fixed some coding errors and bug fixes.
  1658. - Update script icon.
  1659. - Add more tracking parameters.
  1660. - Several optimisations, improve cleaning speed.
  1661. v0.5.2 2023.04.20
  1662. - Update site params (add, remove) (Duplicate or necessary parameters for certain sites).
  1663. - Add a condition before bind a event-listenser to button tags.
  1664. - Manually cleaning: Add a script menu on tampermonkey's drop-down menu during default situations.
  1665. - Fixed a problem that clicking to switch page number was invalid (Add label attribute url verificaiton).
  1666. - Code reduction.
  1667. v0.5.1 2023.04.15
  1668. - Fix some bugs where block clicking-events on empty `<a>` link
  1669. - Update excludes pages.
  1670. - Clean some tracking links under space.bilibili.com after click expand more games.
  1671. - Clean `<a>` links with `data-url` as its target url instead of `href`.
  1672. - Clean the params at embedded youtube videos.
  1673. v0.5.0 2023.04.09
  1674. - Added tmall.hk.
  1675. - Added common cleaning to support all websites.
  1676. - Now this script can clean common contents for all sites and specific cleaning for certain sites.
  1677. - Performance optimisation.
  1678. v0.4.10 2023.04.04
  1679. - Added 1688.com.
  1680. - Script operating improvements.
  1681. v0.4.9 2023.04.03
  1682. - Clean Ali sites URLs and block tracking events.
  1683. - alibaba.com
  1684. - alibabagroup.com
  1685. - aliyun.com
  1686. - aliexpress.com
  1687. - alimama.com
  1688. - taobao.com
  1689. - tmall.com
  1690. - youku.com
  1691. - Minor bug fixes.
  1692. v0.4.8-2023.03.25
  1693. - Script optimisation.
  1694. - Minor bug fixes.
  1695. v0.4.7-2023.03.14
  1696. - Clean Youku URLs. [Youku.com].(Testing)
  1697. - Code reduction.
  1698. - Performance optimisation and bug fixes.
  1699. v0.4.6-2023.03.11
  1700. - Clean more baidu links. [Baidu]
  1701. - Clean CSDN URLs. [csdn.net]
  1702. - Script optimisation and bug fixes.
  1703. - Code reduction.
  1704. v0.4.5 2023.03.09
  1705. - Clean more URL under Baidu.com, replace search URL state. [Baidu]
  1706. - Script optimisation and bug fixes. [bilibili]
  1707. - Code reduction.
  1708. v0.4.4 2023.03.05
  1709. - Restore history state at live.bilibili.com. [Bilibili]
  1710. - Clean Bilibili Manga & Show links. [manga/show.bilibili.com]
  1711. - Clean redundant params at douyin.com search page. [Douyin]
  1712. - Code reduction.
  1713. v0.4.3.1 2023.03.01
  1714. - Clean more links at live.bilibili.com. [Bilibili]
  1715. - Script optimisation.
  1716. v0.4.3 2023.02.24
  1717. - Block more tracking events. [Bilibili]
  1718. - Clean more links.[Bilibili]
  1719. - Restore link jump events at comment area. [Bilibili]
  1720. - Script optimisation. [Bilibili]
  1721. v0.4.2.1 2023.02.22
  1722. - Restore `<a>` link click-events on precise time jump at comment area.[www.bilibili.com/video]
  1723. v0.4.2 2023.02.07
  1724. - Optimised events at the search-input-block. [Bilibili]
  1725. - Bug fixes. [search.bilibili.com, www.bilibili.com]
  1726. v0.4.1.2 2023.01.28
  1727. - Bug fixes and performance optimisation. [Bilibili]
  1728. v0.4.1.1 2023.01.25
  1729. - Expanded the effective pages of the script. [Bilibili]
  1730. v0.4.1.0 2023.01.23
  1731. - Performance optimisation and bug fixes.
  1732. - Code reduction.
  1733. v0.4.0.1 2023.01.21
  1734. - Clean other untracked links. [space.bilibili.com]
  1735. - Several bugs fixes. [bilibili.com]
  1736. v0.4.0 2023.01.20
  1737. - Clean Bilibili Video page collections clicking event URL state changes. [www.bilibili.com/video/]
  1738. - Clean Bilibili Search tracking events. [search.bilibili.com]
  1739. - Clean other tracking events (top-menu clicking). [Bilibili]
  1740. v0.3.8.3 2023.01.20
  1741. - Fixed tracking event after video sorting navigation bar items clicked. [space.bilibili.com]
  1742. v0.3.8.2 2023.01.19
  1743. - Fixed navibar items click events [www.bilibili.com/v/popular].
  1744. v0.3.8.1 2023.01.13
  1745. - Clean more links of Baidu.com
  1746. v0.3.8 2023.01.06
  1747. - Block Card-Ads for Bilibili. (And now blocked banner-ads & card-ads for Bilibili)
  1748. - Block [Lucky Draw (The Selection)] popup at [live.bilibili.com]. Disabled by default.
  1749. - (SET [{BlockLivePopups} = true] to enable it.)
  1750. - The script may add menus to unlock custom setting.
  1751. v0.3.7.1 2023.01.02
  1752. - Fixed [space.bilibili.com] effects after paged, navi-bar clicked or menu-item clicked.
  1753. - Added support to clean tracking url at [search.bilibili.com].
  1754. v0.3.7 2023-01-02
  1755. - Naming optimisation.
  1756. - Script handling optimisation. (Bilibili)
  1757. - Added support to block part of Bilibili Ads.
  1758. v0.3.6 2022.12.28
  1759. - Optimise Baidu related search URL, paging URL processing method.
  1760. v0.3.5 2022.12.27
  1761. - Script logic optimisation.
  1762. v0.3.4 2022.12.23
  1763. - Code optimisation. Fixed script's effect range. [Bilibili]
  1764. v0.3.3 2022.12.23
  1765. - Added site support:Clean Baidu <Related Search> URLs.
  1766. - Script optimisations. [space.bilibili.com]
  1767. v0.3.2 2022.12.22
  1768. - Restore pushstate session (address bar url display, replace history). [Bilibili]
  1769. - Minor optimisations. [Bilibili]
  1770. v0.3.1 2022.12.22
  1771. - Optimized the effective range. [Bilibili]
  1772. v0.3 2022.12.22
  1773. - Added Bilibili Home page, Popular/Rank page, now it can takeeffect on most pages. [Bilibili]
  1774. v0.2 2022.12.21
  1775. - Added missing tags. [Bilibili]
  1776. v0.1 2022.12.20
  1777. - Initial release.
  1778. */