移除广告内嵌脚本

这是一个由AI生成的脚本,通过关键词匹配来移除网页中的内嵌广告脚本。不能保证100%成功,可以在脚本菜单中管理排除的网页和关键词,脚本已经内置一些常见的关键词,若还有广告,可以自行添加Math.random,platform,navigator,new Function,new Date()尝试去除。

安装此脚本?
作者推荐脚本

您可能也喜欢加多重buff的广告拦截脚本

安装此脚本
  1. // ==UserScript==
  2. // @name 移除广告内嵌脚本
  3. // @namespace https://gf.qytechs.cn/zh-CN/users/1373566
  4. // @version 1.5.1.5
  5. // @license MIT
  6. // @description 这是一个由AI生成的脚本,通过关键词匹配来移除网页中的内嵌广告脚本。不能保证100%成功,可以在脚本菜单中管理排除的网页和关键词,脚本已经内置一些常见的关键词,若还有广告,可以自行添加Math.random,platform,navigator,new Function,new Date()尝试去除。
  7. // @author copilot & cheatgpt
  8. // @match http*://*/*
  9. // @exclude *://*.github.com/*
  10. // @exclude *://scriptcat.org/*
  11. // @exclude *://gf.qytechs.cn/*
  12. // @exclude *://github.com/*
  13. // @exclude *://*.google.*/*
  14. // @exclude *://x.com/*
  15. // @exclude *://twitter.com/*
  16. // @exclude *://*.bing.*/*
  17. // @exclude *://*.baidu.*/*
  18. // @exclude *://*.yandex.*/*
  19. // @exclude *://*.iqiyi.com/*
  20. // @exclude *://*.qq.com/*
  21. // @exclude *://*.v.qq.com/*
  22. // @exclude *://*.sohu.com/*
  23. // @exclude *://*.mgtv.com/*
  24. // @exclude *://*.ifeng.com/*
  25. // @exclude *://*.pptv.com/*
  26. // @exclude *://*.sina.com.cn/*
  27. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAXhSURBVGiB7VpdbBRVGD3n7g/bH8v2JynsNgTa7hIbfdhqIoIao2IkQSVAK9KWogRMiDHRB19MSH3QFxONJiY2sUJxS7RJI/iiRhEDhCaaFqix0XbbIukfFNqCL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/iLtKARYU+J1P96DgR9jJjPo0wxH9jMELWHiZPftoYCRLvMlpEwMzjAI0mJmMC+Aq96VCaq3dJm+xyuYMTrG1BUors9dSXDbXETOAry+mCkFADeFG9sLGgpevbbv2l+LaDHGwNrDTqfdxmMIX9XZm4J8nEibKQMq01EBMCsscmLMNr1lpHJkYiGv1J+Xo5gxADAbYHauY8WOa8CRhTy9leJGt8dqwQ6Ar4FYFd0BNHdVDf6QUJspA0pFy0EELbHEA0CgevQmBMejgXhlJNzlaXK3epvcV61W/gHyXb14gbSO3pnab0pbIoK3Md8twKZwYhGhUY9CKI3RBvGot7nIvZBDopTgBoAF844V0USkfnJCnopZejGQsIS0kG2aVk4BcBDo7u7pP23E77YNnvLOuC8BXEtAcDviRfszfn/JdSFPBIP8sK+2v8OMcNMGAi8PjxT73Vst5OYQ2JDw3l6JUKhJ26nEclCAbwK1/QMAMGafecc5Y58huFqg3RLBdZKXRdM6AreGfk10t1myAQDorR44CeCk2aQ9VUNtAPbpYyOVIxMjwKHk5CXG8muVdGPZQLrx/zUQDAYTrtpTiRh6BJhvYDyyQZJOp/OBVAgzi/z8/AfJeW9CxoD580ArgAORhlLqS5/P9z7JtH+lFJE8EXldr19EzgELvhNnZGR0A3OLqn8r9N+JoyXU2dk5ISJ7RWQqneJM4I6maXs7OjomAcCi3zM0NNRTWFh4luQmkvnp0WeI30Wk8vz587H/K6GD1efzbcTs01FWSqQZgOQEyd/a2tpaAYTSreeu4m8HsQDCyNnesgAAAABJRU5ErkJggg==
  28. // @grant GM_setValue
  29. // @grant GM_getValue
  30. // @grant GM_registerMenuCommand
  31. // @run-at document-start
  32. // ==/UserScript==
  33.  
  34. (function() {
  35. 'use strict';
  36. const REMOVE_AD_SCRIPTS_KEYWORDS_KEY = 'removeAdScriptsKeywords';
  37. const EXCLUDE_SITES_KEY = 'excludeSites';
  38. const DEFAULT_KEYWORDS = [
  39. 'htmlAds',
  40. '_ffc1();',
  41. '_ffc2();',
  42. '_ffc3();',
  43. '_ffc4();',
  44. '_ffp();',
  45. 'kbbaidu1();',
  46. 'kbbaidu2();',
  47. 'kbbaidu3();',
  48. 'html5player.checkVideoAds',
  49. 'ads_codes',
  50. '{return void 0!==b[a]?b[a]:a}).join("")}',
  51. '-${scripts[randomIndex]}',
  52. '-${scripts[Math.random()',
  53. '"https://"+Date.parse(new Date())+',
  54. '"https://"+(new Date().getDate())+',
  55. 'https://hongosi.xn--',
  56. 'https://{randomstr}.',
  57. 'new Function(t)()',
  58. 'new Function(b)()',
  59. 'new Function(c)()',
  60. 'new Function(t);',
  61. 'new Function(b);',
  62. 'new Function(c);',
  63. 'new Function(\'d\',e)',
  64. 'new Function(document[',
  65. 'function updateCarousel()',
  66. 'Math.floor(2147483648 * Math.random());',
  67. 'Math.floor(Math.random()*url.length)',
  68. 'Math.floor(Math.random() * urls.length)',
  69. 'new Date()[\'getTime\']()',
  70. 'Math.floor(((new Date()).getTime()',
  71. '&&navigator[',
  72. '=navigator;',
  73. 'navigator.platform){setTimeout(function',
  74. 'disableDebugger',
  75. 'blockDeveloperTools',
  76. '["Date"]())[\'getTime\']()',
  77. '</\'+\'s\'+\'c\'+\'ri\'+\'pt\'+\'>\');',
  78. '<\\/\'+\'s\'+\'c\'+\'ri\'+\'pt\'+\'>\');',
  79. 'class=\\"zdhf\\"',
  80. '(\'#htmlContenthtml\').html',
  81. 'D.createElement(\'span\');',
  82. 'class=\\"app_tj\\"',
  83. 'window.$m(',
  84. 'jsjiami.com.v4',
  85. 'histats.com',
  86. 'pc.stgowan.com'
  87. ];
  88. let keywords = GM_getValue(REMOVE_AD_SCRIPTS_KEYWORDS_KEY, []);
  89. let excludeList = GM_getValue(EXCLUDE_SITES_KEY, []);
  90. let removedScriptsInfo = [];
  91.  
  92. const saveKeywords = () => GM_setValue(REMOVE_AD_SCRIPTS_KEYWORDS_KEY, keywords);
  93. const saveExcludeList = () => GM_setValue(EXCLUDE_SITES_KEY, excludeList);
  94. const createStyledElement = (tagName, styles) => {
  95. const element = document.createElement(tagName);
  96. Object.assign(element.style, styles);
  97. return element;
  98. };
  99. const getKeywordsForCurrentSite = () => {
  100. const siteKeywords = keywords
  101. .filter(k => k.startsWith(`${window.location.hostname}:`))
  102. .map(k => k.split(':').slice(1).join(':'));
  103. return siteKeywords.length > 0 ? siteKeywords : DEFAULT_KEYWORDS;
  104. };
  105. const removeSpecificScript = () => {
  106. if (excludeList.includes(window.location.hostname)) {
  107. console.log('Site excluded:', window.location.hostname);
  108. return;
  109. }
  110. const currentKeywords = getKeywordsForCurrentSite();
  111. document.querySelectorAll('script').forEach(script => {
  112. const matchedKeywords = currentKeywords.filter(k => script.innerHTML.includes(k));
  113. if (matchedKeywords.length) {
  114. removedScriptsInfo.push({
  115. keywords: matchedKeywords,
  116. content: script.innerHTML
  117. });
  118. script.remove();
  119. console.log('Removed script:', script);
  120. }
  121. });
  122. };
  123. const addKeyword = () => {
  124. const newKeyword = prompt('请输入要添加的关键词:');
  125. if (newKeyword) {
  126. const siteKeyword = `${window.location.hostname}:${newKeyword}`;
  127. if (!keywords.some(k => k.startsWith(`${window.location.hostname}:`))) {
  128. keywords.push(...DEFAULT_KEYWORDS.map(k => `${window.location.hostname}:${k}`));
  129. }
  130. keywords.push(siteKeyword);
  131. saveKeywords();
  132. alert(`关键词已添加: ${newKeyword}`);
  133. }
  134. };
  135. const showKeywords = () => alert('当前关键词:\n' + getKeywordsForCurrentSite().join('\n'));
  136. const showRemovedScriptsInfo = () => {
  137. if (!removedScriptsInfo.length) return alert('没有移除任何脚本。');
  138. const info = removedScriptsInfo.map((item, i) =>
  139. `脚本 ${i + 1}:\n匹配关键词: ${item.keywords.join(', ')}\n脚本内容:\n${item.content.slice(0, 1000)}\n`
  140. ).join('\n');
  141. alert('移除的脚本信息:\n\n' + info);
  142. };
  143. const manageSite = operation => {
  144. const site = window.location.hostname;
  145. if (operation === 'exclude' && !excludeList.includes(site)) {
  146. excludeList.push(site);
  147. saveExcludeList();
  148. alert(`当前网址已排除: ${site}`);
  149. } else if (operation === 'add' && excludeList.includes(site)) {
  150. excludeList = excludeList.filter(s => s !== site);
  151. saveExcludeList();
  152. alert(`当前网址已从排除列表移除: ${site}`);
  153. } else {
  154. alert(`当前网址${operation === 'exclude' ? '已在' : '不在'}排除列表中`);
  155. }
  156. };
  157. const editKeywords = () => {
  158. const overlay = createStyledElement('div', {
  159. position: 'fixed',
  160. top: 0,
  161. left: 0,
  162. width: '100%',
  163. height: '100%',
  164. backgroundColor: 'rgba(0,0,0,0.5)',
  165. zIndex: '9998'
  166. });
  167. const container = createStyledElement('div', {
  168. position: 'fixed',
  169. top: '50%',
  170. left: '50%',
  171. transform: 'translate(-50%, -50%)',
  172. zIndex: '9999',
  173. width: '80vw',
  174. maxWidth: '600px',
  175. backgroundColor: '#f8f9fa',
  176. borderRadius: '8px',
  177. padding: '20px'
  178. });
  179. const editor = createStyledElement('textarea', {
  180. width: '100%',
  181. height: '300px',
  182. border: '2px solid #4a90e2',
  183. borderRadius: '4px',
  184. padding: '15px',
  185. fontFamily: 'monospace',
  186. fontSize: '14px'
  187. });
  188. const buttonContainer = createStyledElement('div', {
  189. display: 'flex',
  190. gap: '10px',
  191. marginTop: '15px',
  192. justifyContent: 'flex-end'
  193. });
  194. const buttonStyle = {
  195. padding: '8px 20px',
  196. color: 'white',
  197. border: 'none',
  198. borderRadius: '4px',
  199. cursor: 'pointer',
  200. fontSize: '14px'
  201. };
  202. editor.value = getKeywordsForCurrentSite().join('\n');
  203. const saveButton = createStyledElement('button', {
  204. ...buttonStyle,
  205. backgroundColor: '#4CAF50'
  206. });
  207. saveButton.textContent = '保存';
  208. saveButton.onclick = () => {
  209. keywords = keywords.filter(k => !k.startsWith(`${window.location.hostname}:`))
  210. .concat(editor.value.split('\n').map(k => k.trim()).filter(k => k).map(k => `${window.location.hostname}:${k}`));
  211. saveKeywords();
  212. document.body.removeChild(overlay);
  213. document.body.removeChild(container);
  214. alert('关键词已更新');
  215. };
  216. const resetButton = createStyledElement('button', {
  217. ...buttonStyle,
  218. backgroundColor: '#f44336'
  219. });
  220. resetButton.textContent = '重置';
  221. resetButton.onclick = () => {
  222. if (confirm('确定重置为默认关键词?')) {
  223. keywords = keywords.filter(k => !k.startsWith(`${window.location.hostname}:`));
  224. editor.value = DEFAULT_KEYWORDS.join('\n');
  225. saveKeywords();
  226. alert('已恢复默认关键词');
  227. }
  228. };
  229. buttonContainer.append(saveButton, resetButton);
  230. container.append(editor, buttonContainer);
  231. document.body.append(overlay, container);
  232. };
  233. const showInlineScripts = () => {
  234. const scripts = Array.from(document.querySelectorAll('script'))
  235. .filter(s => s.innerHTML.trim())
  236. .map((s, i) => `脚本 ${i + 1}:\n${s.innerHTML.trim()}\n`)
  237. .join('\n');
  238. alert(scripts ? '网页中的内嵌脚本:\n\n' + scripts : '没有找到内嵌脚本');
  239. };
  240. const cleanGMData = () => {
  241. const siteMap = {};
  242. keywords.forEach(k => {
  243. const [site, ...rest] = k.split(':');
  244. const key = rest.join(':');
  245. siteMap[site] = siteMap[site] || new Set();
  246. siteMap[site].add(key);
  247. });
  248. const sites = Object.keys(siteMap);
  249. if (!sites.length) return alert('没有找到任何网站数据');
  250. const overlay = createStyledElement('div', {
  251. position: 'fixed',
  252. top: 0,
  253. left: 0,
  254. width: '100%',
  255. height: '100%',
  256. backgroundColor: 'rgba(0,0,0,0.5)',
  257. zIndex: '9998'
  258. });
  259. const container = createStyledElement('div', {
  260. position: 'fixed',
  261. top: '50%',
  262. left: '50%',
  263. transform: 'translate(-50%, -50%)',
  264. zIndex: '9999',
  265. width: '80vw',
  266. maxWidth: '600px',
  267. backgroundColor: '#f8f9fa',
  268. borderRadius: '8px',
  269. padding: '20px',
  270. maxHeight: '80vh',
  271. overflowY: 'auto'
  272. });
  273. const title = createStyledElement('h3', {
  274. margin: '0 0 15px 0',
  275. color: '#212529'
  276. });
  277. title.textContent = '选择清理方式';
  278.  
  279. const select = createStyledElement('select', {
  280. width: '100%',
  281. padding: '8px',
  282. marginBottom: '15px',
  283. borderRadius: '4px',
  284. border: '1px solid #4a90e2'
  285. });
  286. select.innerHTML = '<option value="all">清理所有默认关键词数据</option><option value="specific">选择特定网站清理</option>';
  287.  
  288. const siteSelectContainer = createStyledElement('div', {
  289. display: 'none',
  290. marginBottom: '15px'
  291. });
  292. const siteSelect = createStyledElement('select', {
  293. width: '100%',
  294. padding: '8px',
  295. borderRadius: '4px',
  296. border: '1px solid #4a90e2'
  297. });
  298. siteSelect.innerHTML = '<option value="">选择网站</option>' + sites.map(s => `<option value="${s}">${s}</option>`).join('');
  299. siteSelectContainer.appendChild(siteSelect);
  300.  
  301. select.onchange = () => siteSelectContainer.style.display = select.value === 'specific' ? 'block' : 'none';
  302.  
  303. const buttonContainer = createStyledElement('div', {
  304. display: 'flex',
  305. gap: '10px',
  306. justifyContent: 'flex-end'
  307. });
  308. const buttonStyle = {
  309. padding: '8px 20px',
  310. color: 'white',
  311. border: 'none',
  312. borderRadius: '4px',
  313. cursor: 'pointer',
  314. fontSize: '14px'
  315. };
  316.  
  317. const confirmButton = createStyledElement('button', {
  318. ...buttonStyle,
  319. backgroundColor: '#4CAF50'
  320. });
  321. confirmButton.textContent = '确认';
  322. confirmButton.onclick = () => {
  323. const mode = select.value;
  324. let report = 'GM数据清理报告:\n\n';
  325. let cleanedCount = 0;
  326. const defaultSet = new Set(DEFAULT_KEYWORDS);
  327.  
  328. if (mode === 'all') {
  329. if (!confirm('确定要清理所有与默认关键词一致的数据吗?')) return;
  330. const sitesToRemove = [];
  331. for (const site in siteMap) {
  332. const siteKeywords = siteMap[site];
  333. const isExactMatch = siteKeywords.size === defaultSet.size && [...siteKeywords].every(k => defaultSet.has(k)) && [...defaultSet].every(k => siteKeywords.has(k));
  334. report += `网站: ${site}\n关键词数量: ${siteKeywords.size}\n`;
  335. if (isExactMatch) {
  336. sitesToRemove.push(site);
  337. cleanedCount++;
  338. } else {
  339. if (siteKeywords.size !== defaultSet.size) {
  340. report += `原因: 数量不匹配 (默认: ${defaultSet.size}, 网站: ${siteKeywords.size})\n`;
  341. }
  342. const extraKeywords = [...siteKeywords].filter(k => !defaultSet.has(k));
  343. const missingKeywords = [...defaultSet].filter(k => !siteKeywords.has(k));
  344. if (extraKeywords.length > 0) {
  345. report += `原因: 多余关键词: ${extraKeywords.join(', ')}\n`;
  346. }
  347. if (missingKeywords.length > 0) {
  348. report += `原因: 缺少关键词: ${missingKeywords.join(', ')}\n`;
  349. }
  350. report += '\n';
  351. }
  352. }
  353. if (cleanedCount) {
  354. keywords = keywords.filter(k => !sitesToRemove.some(s => k.startsWith(`${s}:`)));
  355. saveKeywords();
  356. report += `共清理 ${cleanedCount} 个与默认关键词一致的网站数据`;
  357. } else {
  358. report += '没有找到与默认关键词完全一致的网站数据';
  359. }
  360. } else if (mode === 'specific') {
  361. const selectedSite = siteSelect.value;
  362. if (!selectedSite) return alert('请选择一个网站');
  363. if (!confirm(`确定要清理 ${selectedSite} 的关键词数据吗?`)) return;
  364. const siteKeywords = siteMap[selectedSite];
  365. report += `网站: ${selectedSite}\n关键词数量: ${siteKeywords.size}\n关键词: ${[...siteKeywords].join(', ')}\n\n`;
  366. keywords = keywords.filter(k => !k.startsWith(`${selectedSite}:`));
  367. saveKeywords();
  368. report += `已清理 ${selectedSite} 的所有关键词数据`;
  369. cleanedCount = 1;
  370. }
  371. document.body.removeChild(overlay);
  372. document.body.removeChild(container);
  373. alert(report);
  374. };
  375. const cancelButton = createStyledElement('button', {
  376. ...buttonStyle,
  377. backgroundColor: '#f44336'
  378. });
  379. cancelButton.textContent = '取消';
  380. cancelButton.onclick = () => {
  381. document.body.removeChild(overlay);
  382. document.body.removeChild(container);
  383. };
  384. buttonContainer.append(confirmButton, cancelButton);
  385. container.append(title, select, siteSelectContainer, buttonContainer);
  386. document.body.append(overlay, container);
  387. };
  388. const observer = new MutationObserver(mutations => {
  389. mutations.forEach(m => {
  390. m.addedNodes.forEach(node => {
  391. if (node.tagName === 'SCRIPT') removeSpecificScript();
  392. });
  393. });
  394. });
  395. observer.observe(document.documentElement, {
  396. childList: true,
  397. subtree: true
  398. });
  399. removeSpecificScript();
  400. GM_registerMenuCommand('排除当前网址', () => manageSite('exclude'));
  401. GM_registerMenuCommand('拦截当前网址', () => manageSite('add'));
  402. GM_registerMenuCommand('添加关键词', addKeyword);
  403. GM_registerMenuCommand('显示关键词', showKeywords);
  404. GM_registerMenuCommand('编辑关键词', editKeywords);
  405. GM_registerMenuCommand('移除脚本日志', showRemovedScriptsInfo);
  406. GM_registerMenuCommand('网页内嵌脚本查看', showInlineScripts);
  407. GM_registerMenuCommand('GM关键词数据清理', cleanGMData);
  408. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址