RU AdList JS Fixes

try to take over the world!

当前为 2016-09-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 2016-09-21:0
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var win = (unsafeWindow || window),
  16. inIFrame = (function() {
  17. try {
  18. return win.self !== win.top;
  19. } catch (ignore) {
  20. return true;
  21. }
  22. })();
  23.  
  24. // NodeList iterator polyfill (mostly for Safari)
  25. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  26. if (!NodeList.prototype[Symbol.iterator]) {
  27. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  28. }
  29.  
  30. // Creates and return protected style (unless protection is manually disabled).
  31. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  32. function createStyle(rules, props, skip_protect) {
  33. var root = document.head;
  34.  
  35. function _protect(style) {
  36. Object.defineProperty(style, 'sheet', {
  37. value: style.sheet,
  38. enumerable: true
  39. });
  40. Object.defineProperty(style, 'disabled', {
  41. get: function() {return true;}, //pretend to be disabled
  42. set: function() {},
  43. enumerable: true
  44. });
  45. }
  46.  
  47. function _create() {
  48. var style = root.appendChild(document.createElement('style')),
  49. prop, rule;
  50. style.type = 'text/css';
  51. for (prop in props) {
  52. if (style.hasOwnProperty(prop)) {
  53. style[prop] = props[prop];
  54. }
  55. }
  56. for (rule of rules) {
  57. try {
  58. style.sheet.insertRule(rule, 0);
  59. } catch (e) {
  60. console.error(e);
  61. }
  62. }
  63. if (!skip_protect) {
  64. _protect(style);
  65. }
  66. return style;
  67. }
  68.  
  69. var style = _create();
  70. if (skip_protect) {
  71. return style;
  72. }
  73.  
  74. var o = new MutationObserver(function(ms){
  75. var m, node, rule;
  76. for (m of ms) {
  77. for (node of m.removedNodes) {
  78. if (node === style) {
  79. style = _create();
  80. }
  81. }
  82. }
  83. });
  84. o.observe(root, {childList:true});
  85.  
  86. return style;
  87. }
  88.  
  89. // https://gf.qytechs.cn/scripts/19144-websuckit/
  90. (function() {
  91. function getWrappedCode(removeSelf) {
  92. var text = getWrappedCode.toString()+WSI.toString();
  93. text = (
  94. '(function(){"use strict";'+
  95. text.replace(/\/\/[^\r\n]*/g,'').replace(/[\s\r\n]+/g,' ')+
  96. '(new WSI(self||window)).init();'+
  97. '})();'+
  98. (removeSelf?'var s = document.currentScript; if (s) {s.parentNode.removeChild(s);}':'')
  99. );
  100. return text;
  101. }
  102.  
  103. function WSI(win, safeWin) {
  104. safeWin = safeWin || win;
  105. var masks = [], filter;
  106. for (filter of [// blacklist
  107. '||24video.xxx^',
  108. '||adlabs.ru^',
  109. '||bgrndi.com^',
  110. '||brokeloy.com^',
  111. '||cnamerutor.ru^',
  112. '||docfilms.info^',
  113. '||dreadfula.ru^',
  114. '||et-code.ru^',
  115. '||free-torrent.org^',
  116. '||free-torrent.pw^',
  117. '||free-torrents.org^',
  118. '||free-torrents.pw^',
  119. '||game-torrent.info^',
  120. '||gocdn.ru^',
  121. '||hdkinoshka.com^',
  122. '||hghit.com^',
  123. '||kinotochka.net^',
  124. '||kuveres.com^',
  125. '||lepubs.com^',
  126. '||luxadv.com^',
  127. '||luxup.ru^',
  128. '||mail.ru^',
  129. '||marketgid.com^',
  130. '||mxtads.com^',
  131. '||oconner.biz^',
  132. '||abbp1.website',
  133. '||psma01.com^',
  134. '||psma02.com^',
  135. '||psma03.com^',
  136. '||recreativ.ru^',
  137. '||regpole.com^',
  138. '||ruttwind.com^',
  139. '||skidl.ru^',
  140. '||torvind.com^',
  141. '||trafmag.com^',
  142. '||xxuhter.ru^',
  143. '||yuiout.online^'
  144. ]) {
  145. masks.push(new RegExp(
  146. filter.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  147. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  148. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  149. .replace(/^\|\|/,'^wss?:\\/+([^\/.]+\\.)*'),
  150. 'i'));
  151. }
  152.  
  153. function isBlocked(url) {
  154. for (var mask of masks) {
  155. if (mask.test(url)) {
  156. return true;
  157. }
  158. }
  159. return false;
  160. }
  161.  
  162. function WebSocketWrapper() {
  163. var realWebSocket = win.WebSocket;
  164. // check does browser support Proxy and WebSocket
  165. if (typeof Proxy !== 'function' ||
  166. typeof WebSocket !== 'function') {
  167. return;
  168. }
  169.  
  170. function wsGetter (target, name) {
  171. console.log('[WSI] Registered call to property "', name, '"');
  172. try {
  173. if (typeof realWebSocket.prototype[name] === 'function') {
  174. if (name === 'close' || name === 'send') { // send also closes connection
  175. target.readyState = realWebSocket.CLOSED;
  176. }
  177. return function(){return;};
  178. }
  179. if (typeof realWebSocket.prototype[name] === 'number') {
  180. return realWebSocket[name];
  181. }
  182. } catch(ignore) {}
  183. return target[name];
  184. }
  185.  
  186. win.WebSocket = new Proxy(realWebSocket, {
  187. construct: function (target, args) {
  188. var url = args[0];
  189. console.log('[WSI] Opening socket on', url, '\u2026');
  190. if (isBlocked(url)) {
  191. console.log("[WSI] Blocked.");
  192. return new Proxy({url: url, readyState: realWebSocket.OPEN}, {
  193. get: wsGetter
  194. });
  195. }
  196. return new target(args[0], args[1]);
  197. }
  198. });
  199. }
  200.  
  201. function WorkerWrapper() {
  202. var realWorker = win.Worker;
  203. function wrappedWorker(resourceURI) {
  204. var _worker = null,
  205. _terminate = false,
  206. _onerror = null,
  207. _onmessage = null,
  208. _messages = [],
  209. _events = [],
  210. _self = this;
  211.  
  212. (new Promise(function(resolve,reject){
  213. var xhrLoadEnd = function() {
  214. resolve(new realWorker(URL.createObjectURL(
  215. new Blob([getWrappedCode(false)+this.result])
  216. )));
  217. };
  218. var xhr = new XMLHttpRequest();
  219. xhr.open('GET', resourceURI, true);
  220. xhr.responseType = 'blob';
  221. xhr.onload = function(){
  222. if (this.status === 200) {
  223. var reader = new FileReader();
  224. reader.addEventListener("loadend", xhrLoadEnd);
  225. reader.readAsText(this.response);
  226. }
  227. };
  228. xhr.send();
  229. })).then(function(val) {
  230. _worker = val;
  231. _worker.onerror = _onerror;
  232. _worker.onmessage = _onmessage;
  233. var _e;
  234. while(_events.length) {
  235. _e = _events.shift();
  236. _worker[_e[0]].apply(_worker, _e[1]);
  237. }
  238. while(_messages.length) {
  239. _worker.postMessage(_messages.shift());
  240. }
  241. if (_terminate) {
  242. _worker.terminate();
  243. }
  244. });
  245.  
  246. _self.terminate = function(){
  247. _terminate = true;
  248. if (_worker) {
  249. _worker.terminate();
  250. }
  251. };
  252. Object.defineProperty(_self, 'onmessage', {
  253. get:function(){
  254. return _onmessage;
  255. },
  256. set:function(val){
  257. _onmessage = val;
  258. if (_worker) {
  259. _worker.onmessage = val;
  260. }
  261. }
  262. });
  263. Object.defineProperty(_self, 'onerror', {
  264. get:function(){
  265. return _onerror;
  266. },
  267. set:function(val){
  268. _onerror = val;
  269. if (_worker) {
  270. _worker.onmessage = val;
  271. }
  272. }
  273. });
  274. _self.postMessage = function(message){
  275. if (_worker) {
  276. _worker.postMessage(message);
  277. } else {
  278. _messages.push(message);
  279. }
  280. };
  281. _self.terminate = function() {
  282. _terminate = true;
  283. if (_worker) {
  284. _worker.terminate();
  285. }
  286. };
  287. _self.addEventListener = function(){
  288. if (_worker) {
  289. _worker.addEventListener.apply(_worker, arguments);
  290. } else {
  291. _events.push(['addEventListener',arguments]);
  292. }
  293. };
  294. _self.removeEventListener = function(){
  295. if (_worker) {
  296. _worker.removeEventListener.apply(_worker, arguments);
  297. } else {
  298. _events.push(['removeEventListener',arguments]);
  299. }
  300. };
  301. }
  302. win.Worker = wrappedWorker.bind(safeWin);
  303. }
  304.  
  305. function CreateElementWrapper() {
  306. var realCreateElement = document.createElement.bind(document),
  307. code = escape('<scr'+'ipt>'+getWrappedCode(true)+'</scr'+'ipt>');
  308.  
  309. function frameRewrite(e) {
  310. var f = e.target;
  311. if (f.src && /^data:text/i.test(f.src) && f.src.indexOf(code) < 0) {
  312. f.src = f.src.replace(',',',' + code);
  313. }
  314. }
  315.  
  316. function wrappedCreateElement(name) {
  317. if (name && name.toUpperCase &&
  318. name.toUpperCase() === 'IFRAME') {
  319. var ifr = realCreateElement.apply(document, arguments);
  320. ifr.addEventListener('load', frameRewrite, false);
  321. return ifr;
  322. }
  323. return realCreateElement.apply(document, arguments);
  324. }
  325. document.createElement = wrappedCreateElement.bind(document);
  326.  
  327. document.addEventListener('DOMContentLoaded', function(){
  328. for (var ifr of document.getElementsByTagName('IFRAME')) {
  329. ifr.addEventListener('load', frameRewrite, false);
  330. }
  331. }, false);
  332. }
  333.  
  334. this.init = function() {
  335. WebSocketWrapper();
  336. WorkerWrapper();
  337. if (typeof document !== 'undefined') {
  338. CreateElementWrapper();
  339. }
  340. };
  341. }
  342.  
  343. if (/firefox/i.test(navigator.userAgent)) {
  344. var script = document.createElement('script');
  345. script.appendChild(document.createTextNode(getWrappedCode()));
  346. document.head.insertBefore(script, document.head.firstChild);
  347. return; //we don't want to call functions on page from here in Fx, so exit
  348. }
  349.  
  350. (new WSI((unsafeWindow||self||window),(self||window))).init();
  351. })();
  352.  
  353. if (!(/firefox/i.test(navigator.userAgent))) { // scripts for non-Firefox browsers
  354.  
  355. // https://gf.qytechs.cn/scripts/14720-it-s-not-important
  356. (function(){
  357. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig;
  358.  
  359. function unimportanter(el, si) {
  360. if (!imptt.test(si) || el.style.display === 'none') {
  361. return 0; // get out if we have nothing to do here
  362. }
  363. if (el.nodeName === 'IFRAME' && el.src &&
  364. el.src.slice(0,17) === 'chrome-extension:') {
  365. return 0; // Web of Trust uses this method to add their frame
  366. }
  367. var so = si.replace(imptt, function(){return arguments[1];}), ret = 0;
  368. if (si !== so) {
  369. ret = 1;
  370. el.setAttribute('style', so);
  371. }
  372. return ret;
  373. }
  374.  
  375. function logger(c) {
  376. if (c) {
  377. console.log('Some page elements became a bit less important.');
  378. }
  379. }
  380.  
  381. function checkTarget(node, cnt) {
  382. if (!(node && node.getAttribute)) {
  383. return 0;
  384. }
  385. var si = node.getAttribute('style');
  386. if (si && si.indexOf('!') > -1) {
  387. cnt += unimportanter(node, si);
  388. }
  389. return cnt;
  390. }
  391.  
  392. var observer = new MutationObserver(function(mutations) {
  393. setTimeout(function(ms) {
  394. var cnt = 0, m, node;
  395. for (m of ms) {
  396. cnt = checkTarget(m.target, cnt);
  397. for (node of m.addedNodes) {
  398. cnt += checkTarget(node, cnt);
  399. }
  400. }
  401. logger(cnt);
  402. }, 0, mutations);
  403. });
  404.  
  405. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  406.  
  407. win.addEventListener ("load", function(){
  408. var c = 0, imp;
  409. for (imp of document.querySelectorAll('[style*="!"]')) {
  410. c+= checkTarget(imp, c);
  411. }
  412. logger(c);
  413. }, false);
  414. })();
  415.  
  416. }
  417.  
  418. if (/^https?:\/\/(news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href)) {
  419. // https://gf.qytechs.cn/en/scripts/809-no-yandex-ads
  420. (function(){
  421. var adWords = ['Яндекс.Директ','Реклама','Ad'];
  422. function remove(node) {
  423. node.parentNode.removeChild(node);
  424. }
  425. // Generic ads removal and fixes
  426. function removeGenericAds() {
  427. var s, i;
  428. s = document.querySelector('.serp-header');
  429. if (s) {
  430. s.style.marginTop='0';
  431. }
  432. for (s of document.querySelectorAll('.serp-adv__head + .serp-item, #adbanner, .serp-adv, .b-spec-adv, div[class*="serp-adv__"]')) {
  433. remove(s);
  434. }
  435. }
  436. // Search ads
  437. function removeSearchAds() {
  438. var s, item;
  439. for (s of document.querySelectorAll('.serp-block, .serp-item, .search-item')) {
  440. item = s.querySelector('.label, .serp-item__label, .document__provider-name');
  441. if (item && adWords.indexOf(item.textContent) > -1) {
  442. remove(s);
  443. console.log('Ads removed.');
  444. }
  445. }
  446. }
  447. // News ads
  448. function removeNewsAds() {
  449. var s;
  450. for (s of document.querySelectorAll('.page-content__left > *,.page-content__right > *:not(.page-content__col),.page-content__right > .page-content__col > *')) {
  451. if (s.textContent.indexOf(adWords[0]) > -1) {
  452. remove(s);
  453. console.log('Ads removed.');
  454. }
  455. }
  456. }
  457. // News fixes
  458. function removePageAdsClass() {
  459. if (document.body.classList.contains("b-page_ads_yes")){
  460. document.body.classList.remove("b-page_ads_yes");
  461. console.log('Page ads class removed.');
  462. }
  463. }
  464. // Function to attach an observer to monitor dynamic changes on the page
  465. function pageUpdateObserver(func, obj, params) {
  466. if (obj) {
  467. var o = new MutationObserver(func);
  468. o.observe(obj,(params || {childList:true, subtree:true}));
  469. }
  470. }
  471. // Cleaner
  472. document.addEventListener ("DOMContentLoaded", function() {
  473. removeGenericAds();
  474. if (win.location.hostname.search(/^news\./i) === 0) {
  475. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  476. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  477. removeNewsAds();
  478. removePageAdsClass();
  479. } else {
  480. pageUpdateObserver(removeSearchAds, document.querySelector('.main__content'));
  481. removeSearchAds();
  482. }
  483. });
  484. })();
  485. return; //skip fixes for other sites
  486. }
  487.  
  488. // https://gf.qytechs.cn/en/scripts/14470-4pda-unbrender
  489. if (/(^|\.)4pda\.ru$/i.test(window.location.hostname)) {
  490. (function() {
  491. var isForum = document.location.href.search('/forum/') !== -1,
  492. hStyle;
  493.  
  494. function remove(n) {
  495. if (n) {
  496. n.parentNode.removeChild(n);
  497. }
  498. }
  499.  
  500. function afterClean() {
  501. hStyle.disabled = true;
  502. remove(hStyle);
  503. }
  504.  
  505. function beforeClean() {
  506. // attach styles before document displayed
  507. hStyle = createStyle([
  508. 'html { overflow-y: scroll }',
  509. 'article + aside * { display: none !important }',
  510. '#header + div:after {'+(
  511. 'content: "";'+
  512. 'position: fixed;'+
  513. 'top: 0;'+
  514. 'left: 0;'+
  515. 'width: 100%;'+
  516. 'height: 100%;'+
  517. 'background-color: #E6E7E9'
  518. )+'}',
  519. // http://codepen.io/Beaugust/pen/DByiE
  520. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  521. 'article + aside:after {'+(
  522. 'content: "";'+
  523. 'position: absolute;'+
  524. 'width: 150px;'+
  525. 'height: 150px;'+
  526. 'top: 150px;'+
  527. 'left: 50%;'+
  528. 'margin-top: -75px;'+
  529. 'margin-left: -75px;'+
  530. 'box-sizing: border-box;'+
  531. 'border-radius: 100%;'+
  532. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  533. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  534. 'animation: spin 2s infinite linear'
  535. )+'}'
  536. ], {id:'ubrHider'}, true);
  537.  
  538. // display content of a page if time to load a page is more than 2 seconds to avoid
  539. // blocking access to a page if it is loading for too long or stuck in a loading state
  540. setTimeout(2000, afterClean);
  541. }
  542.  
  543. createStyle([
  544. '#nav .use-ad {display: block !important;}',
  545. 'article:not(.post) + article:not(#id) { display: none !important }'
  546. ]);
  547.  
  548. if (!isForum) {
  549. beforeClean();
  550. }
  551.  
  552. // clean a page
  553. window.addEventListener('DOMContentLoaded', function(){
  554. var rem, si, itm;
  555. function width(){ return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0; }
  556. function height(){ return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0; }
  557.  
  558.  
  559. if (isForum) {
  560. si = document.querySelector('#logostrip');
  561. if (si) {
  562. remove(si.parentNode.nextSibling);
  563. }
  564. }
  565.  
  566. if (document.location.href.search('/forum/dl/') !== -1) {
  567. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  568. ';background-color:black!important');
  569. for (itm of document.querySelectorAll('body>div')) {
  570. if (!itm.querySelector('.dw-fdwlink')) {
  571. remove(itm);
  572. }
  573. }
  574. }
  575.  
  576. if (isForum) { // Do not continue if it's a forum
  577. return;
  578. }
  579.  
  580. si = document.querySelector('#header');
  581. if (si) {
  582. rem = si.previousSibling;
  583. while (rem) {
  584. si = rem.previousSibling;
  585. remove(rem);
  586. rem = si;
  587. }
  588. }
  589.  
  590. for (itm of document.querySelectorAll('#nav li[class]')) {
  591. if (itm && itm.querySelector('a[href^="/tag/"]')) {
  592. remove(itm);
  593. }
  594. }
  595.  
  596. var style, result;
  597. for (itm of document.querySelectorAll('DIV')) {
  598. if (itm.offsetWidth > 0.95 * width() && itm.offsetHeight > 0.9 * height()) {
  599. style = window.getComputedStyle(itm, null);
  600. result = [];
  601. if(style.backgroundImage !== 'none') {
  602. result.push('background-image:none!important');
  603. }
  604. if(style.backgroundColor !== 'transparent') {
  605. result.push('background-color:transparent!important');
  606. }
  607. if (result.length) {
  608. if (itm.getAttribute('style')) {
  609. result.unshift(itm.getAttribute('style'));
  610. }
  611. itm.setAttribute('style', result.join(';'));
  612. }
  613. }
  614. }
  615.  
  616. for (itm of document.querySelectorAll('ASIDE>DIV')) {
  617. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  618. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  619. !itm.classList.contains('post') ) || !itm.childNodes.length ) {
  620. remove(itm);
  621. }
  622. }
  623.  
  624. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  625.  
  626. // display content of the page
  627. afterClean();
  628. });
  629. })();
  630. return;
  631. }
  632.  
  633. // https://gf.qytechs.cn/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.6
  634. document.addEventListener ("DOMContentLoaded", function() {
  635. if (!inIFrame) {
  636. return;
  637. }
  638. var tmp;
  639. function log (e) {
  640. console.log('Moonwalk&HDGo&Kodik FIX: ' + e + ' player in ' + win.location.href);
  641. }
  642. if (win.adv_enabled !== undefined && win.condition_detected !== undefined) {
  643. log('Moonwalk');
  644. win.adv_enabled = false;
  645. win.condition_detected = false;
  646. } else if (win.banner_second !== undefined && win.$banner_ads !== undefined) {
  647. log('HDGo');
  648. win.banner_second = 0;
  649. win.$banner_ads = false;
  650. win.$new_ads = false;
  651. win.canRunAds = true;
  652. tmp = document.body.querySelector('#swtf');
  653. if (tmp) {
  654. tmp.style.display = 'none';
  655. }
  656. } else if (win.MXoverrollCallback !== undefined && win.iframeSearch !== undefined) {
  657. log('Kodik');
  658. win.IsAdBlock = false;
  659. win.iframeSearch = null;
  660. tmp = document.getElementsByClassName('play_button')[0];
  661. if (tmp) {
  662. tmp.onclick = win.MXoverrollCallback.bind(window);
  663. }
  664. }
  665. }, false);
  666.  
  667. // function to search and remove nodes by content
  668. // selector - standard CSS selector to define set of nodes to check
  669. // words - regular expression to check content of the suspicious nodes
  670. // params - object with multiple extra parameters:
  671. // .hide - set display to none instead of removing from the page
  672. // .parent - parent node to remove if content is found in the child node
  673. // .siblings - number of simling nodes to remove (excluding text nodes)
  674. function scRemove(e) {e.parentNode.removeChild(e);}
  675. function scHide(e) {
  676. var s = e.getAttribute('style')||'',
  677. h = ';display:none!important;';
  678. if (s.indexOf(h) < 0) {
  679. e.setAttribute('style', s+h);
  680. }
  681. }
  682. function scissors (selector, words, scope, params) {
  683. var remFunc = (params.hide ? scHide : scRemove),
  684. iterFunc = (params.siblings > 0 ?
  685. 'nextSibling' :
  686. 'previousSibling'),
  687. toRemove = [],
  688. siblings,
  689. node;
  690. for (node of scope.querySelectorAll(selector)) {
  691. if (words.test(node.innerHTML) || !node.childNodes.length) {
  692. // drill up to the specified parent node if required
  693. if (params.parent) {
  694. while(node !== scope && !(node.matches(params.parent))) {
  695. node = node.parentNode;
  696. }
  697. }
  698. if (node === scope) {
  699. break;
  700. }
  701. toRemove.push(node);
  702. // add multiple nodes if defined more than one sibling
  703. siblings = Math.abs(params.siblings) || 0;
  704. while (siblings) {
  705. node = node[iterFunc];
  706. toRemove.push(node);
  707. if (node.nodeType === 1) {
  708. siblings -= 1; //count only element nodes
  709. }
  710. }
  711. }
  712. }
  713. for (node of toRemove) {
  714. remFunc(node);
  715. }
  716. return toRemove.length;
  717. }
  718.  
  719. // function to perform multiple checks if ads inserted with a delay
  720. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  721. // also does 1 extra check when a page completely loads
  722. // selector and words - passed dow to scissors
  723. // params - object with multiple extra parameters:
  724. // .root - selector to narrow down scope to scan;
  725. // .observe - if true then check will be performed continuously;
  726. // Other parameters passed down to scissors.
  727. function gardener(selector, words, params) {
  728. params = params || {};
  729. var scope = document.body,
  730. nonstop = false;
  731. // narrow down scope to a specific element
  732. if (params.root) {
  733. scope = scope.querySelector(params.root);
  734. if (!scope) {// exit if the root element is not present on the page
  735. return 0;
  736. }
  737. }
  738. // add observe mode if required
  739. if (params.observe) {
  740. if (typeof MutationObserver === 'function') {
  741. var o = new MutationObserver(function(ms){
  742. for (var m of ms) {
  743. if (m.addedNodes.length) {
  744. scissors(selector, words, scope, params);
  745. }
  746. }
  747. });
  748. o.observe(scope, {childList:true, subtree: true});
  749. } else {
  750. nonstop = true;
  751. }
  752. }
  753. // wait for a full page load to do one extra cut
  754. win.addEventListener('load',function(){
  755. scissors(selector, words, scope, params);
  756. });
  757. // do multiple cuts until ads removed
  758. function cut(sci, s, w, sc, p, i) {
  759. if (i > 0) {
  760. i -= 1;
  761. }
  762. if (i && !sci(s, w, sc, p)) {
  763. setTimeout(cut, 100, sci, s, w, sc, p, i);
  764. }
  765. }
  766. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  767. }
  768.  
  769. function preventBackgroundRedirect() {
  770. // create "cose_me" event to call high-level window.close()
  771. var key = Math.random().toString(36).substr(2);
  772. window.addEventListener('close_me_'+key, function(e) {
  773. console.log('event!');
  774. window.close();
  775. });
  776.  
  777. // window.open wrapper
  778. function pbrLander() {
  779. var orgOpen = window.open.bind(window);
  780. function closeWindow(){
  781. // site went to a new tab and attempts to unload
  782. // call for high-level close through event
  783. var event = new CustomEvent("close_me_%key%", {});
  784. window.dispatchEvent(event);
  785. }
  786. function open(){
  787. var idx = String.prototype.indexOf;
  788. if (arguments[0] &&
  789. (idx.call(arguments[0], window.location.host) > -1 ||
  790. idx.call(arguments[0], '://') === -1)) {
  791. window.addEventListener('unload', closeWindow, true);
  792. }
  793. orgOpen.apply(window, arguments);
  794. }
  795. window.open = open.bind(window);
  796. var s = document.currentScript;
  797. if (s) {s.parentNode.removeChild(s);}
  798. }
  799.  
  800. // land wrapper on the page
  801. var script = document.createElement('script');
  802. script.appendChild(document.createTextNode('('+pbrLander.toString().replace(/%key%/g,key)+')();'));
  803. document.head.insertBefore(script,document.head.firstChild);
  804. console.log("Background redirect prevention enabled.");
  805. }
  806.  
  807. function forbidServiceWorker() {
  808. if (!("serviceWorker" in navigator)) {
  809. return;
  810. }
  811. var svr = navigator.serviceWorker.ready;
  812. Object.defineProperty(navigator, 'serviceWorker', {
  813. value: {
  814. register: function(){
  815. console.log('Registration of serviceWorker', arguments[0], 'blocked.');
  816. return new Promise(function(){});
  817. },
  818. ready: new Promise(function(){}),
  819. addEventListener:function(){}
  820. }
  821. });
  822. document.addEventListener('DOMContentLoaded', function() {
  823. if (!svr) {
  824. return;
  825. }
  826. svr.then(function(sw) {
  827. console.log('Found existing serviceWorker:', sw);
  828. console.log('Attempting to unregister...');
  829. sw.unregister().then(function() {
  830. console.log('Unregistered! :)');
  831. }).catch(function(err) {
  832. console.log('Unregistration failed. :(', err);
  833. console.log('Try to remove it manually:');
  834. console.log(' 1. Open: chrome://serviceworker-internals/ (Google Chrome and alike) or about:serviceworkers (Mozilla Firefox) in a new tab.');
  835. console.log(' 2. Search there for one with "'+document.domain+'" in the name.');
  836. console.log(' 3. Use buttons in the same block with service you found to stop it and uninstall/unregister.');
  837. });
  838. }).catch(function(err) {
  839. console.log("Lol, it failed on it's own. -_-", err);
  840. });
  841. }, false);
  842. }
  843.  
  844. var scripts = {};
  845. scripts['fs.to'] = function() {
  846. function skipClicker(i) {
  847. if (!i) {
  848. return;
  849. }
  850. var skip = document.querySelector('.b-aplayer-banners__close');
  851. if (skip) {
  852. skip.click();
  853. } else {
  854. setTimeout(skipClicker, 100, i-1);
  855. }
  856. }
  857. setTimeout(skipClicker, 100, 30);
  858.  
  859. createStyle([
  860. '.l-body-branding *,'+
  861. '.b-styled__item-central,'+
  862. '.b-styled__content-right,'+
  863. '.b-styled__section-central,'+
  864. 'div[id^="adsProxy-"]'+
  865. '{display:none!important}',
  866. 'body {background-image:url(data:image/png;base64,'+
  867. 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACX'+
  868. 'BIWXMAAC4jAAAuIwF4pT92AAAADUlEQVR42mOQUdL5DwACMgFq'+
  869. 'BC3ttwAAAABJRU5ErkJggg==)!important}'
  870. ]);
  871.  
  872. if (/\/(view_iframe|iframeplayer)\//i.test(document.location.pathname)) {
  873. var p = document.querySelector('#player:not([preload="auto"])'),
  874. m = document.querySelector('.main'),
  875. adStepper = function(p) {
  876. if (p.currentTime < p.duration) {
  877. p.currentTime += 1;
  878. }
  879. },
  880. adSkipper = function(f, p) {
  881. f.click();
  882. p.waitAfterSkip = false;
  883. p.longerSkipper = false;
  884. console.log('Пропустили.');
  885. },
  886. cl = function(p) {
  887. var faster = document.querySelector('.b-aplayer__html5-desktop-skip'),
  888. series = document.querySelector('.b-aplayer__actions-series');
  889.  
  890. function clickSelected() {
  891. var s = document.querySelector('.b-aplayer__popup-series-episodes .selected a');
  892. if (s) {
  893. s.click();
  894. }
  895. }
  896.  
  897. if ((!faster || faster.style.display !== 'block') && series && !p.seriesClicked) {
  898. series.click();
  899. p.seriesClicked = true;
  900. p.longerSkipper = true;
  901. setTimeout(clickSelected, 1000);
  902. p.pause();
  903. }
  904.  
  905. function skipListener() {
  906. if (p.waitAfterSkip) {
  907. console.log('В процессе пропуска…');
  908. return;
  909. }
  910. p.pause();
  911. if (!p.classList.contains('m-hidden')) {
  912. p.classList.add('m-hidden');
  913. }
  914. if (faster && p.currentTime &&
  915. win.getComputedStyle(faster).display === 'block' &&
  916. !faster.querySelector('.b-aplayer__html5-desktop-skip-timer')) {
  917. p.waitAfterSkip = true;
  918. setTimeout(adSkipper, (p.longerSkipper?3:1)*1000, faster, p);
  919. console.log('Доступен быстрый пропуск…');
  920. } else {
  921. setTimeout(adStepper, 1000, p);
  922. }
  923. }
  924.  
  925. p.addEventListener('timeupdate', skipListener, false);
  926. },
  927. o = new MutationObserver(function (ms) {
  928. var m, node;
  929. for (m of ms) {
  930. for (node of m.addedNodes) {
  931. if (node.id === 'player' &&
  932. node.nodeName === 'VIDEO' &&
  933. node.getAttribute('preload') !== 'auto') {
  934. cl(node);
  935. }
  936. }
  937. }
  938. });
  939. if (p.nodeName === 'VIDEO') {
  940. cl(p);
  941. } else {
  942. o.observe(m, {childList: true});
  943. }
  944. }
  945. };
  946. scripts['brb.to'] = scripts['fs.to'];
  947. scripts['cxz.to'] = scripts['fs.to'];
  948.  
  949. scripts['drive2.ru'] = function() {
  950. gardener('.c-block', />Реклама<\/|\.relap\..*display:\s?none/i);
  951. };
  952.  
  953. scripts['fishki.net'] = function() {
  954. gardener('.main-post', /543769|Реклама/);
  955. };
  956.  
  957. scripts['hdgo.cc'] = {
  958. 'now': function(){
  959. var o = new MutationObserver(function(ms) {
  960. var m, node;
  961. for (m of ms) {
  962. for (node of m.addedNodes) {
  963. if (node.tagName === 'SCRIPT' && node.getAttribute('onerror') !== null) {
  964. node.removeAttribute('onerror');
  965. }
  966. }
  967. }
  968. });
  969. o.observe(document, {childList:true, subtree: true});
  970. }
  971. };
  972. scripts['couber.be'] = scripts['hdgo.cc'];
  973. scripts['46.30.43.38'] = scripts['hdgo.cc'];
  974.  
  975. scripts['hdrezka.me'] = {
  976. 'now': function() {
  977. Object.defineProperty(win, 'fuckAdBlock', {
  978. value: {
  979. onDetected: function() {
  980. console.log('Pretending to be an ABP detector.');
  981. }
  982. }
  983. });
  984. Object.defineProperty(win, 'ab', { value: false });
  985. },
  986. 'DOMContentLoaded': function() {
  987. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  988. }
  989. };
  990.  
  991. scripts['naruto-base.su'] = function() {
  992. gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  993. };
  994.  
  995. scripts['pb.wtf'] = function() {
  996. createStyle(['.reques,#result,tbody.row1:not([id]) {display: none !important}']);
  997. // image in the slider in the header
  998. gardener('a[href$="=="]', /img/i, {root:'.release-navbar', observe:true, parent:'div'});
  999. // ads in blocks on the page
  1000. gardener('a[href^="/"]', /<img\s.*<br>/i, {root:'#main_content', observe:true, parent:'div[class]'});
  1001. // line above topic content
  1002. gardener('.re_top1', /./, {root:'#main_content', parent:'.hidden-sm'});
  1003. };
  1004. scripts['piratbit.org'] = scripts['pb.wtf'];
  1005. scripts['piratbit.ru'] = scripts['pb.wtf'];
  1006.  
  1007. scripts['pikabu.ru'] = function() {
  1008. gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  1009. };
  1010.  
  1011. scripts['rustorka.com'] = function() {
  1012. var s = document.head.childNodes, i = s.length;
  1013. if (i < 5) {
  1014. while(i--) {
  1015. if (s[i].httpEquiv && s[i].httpEquiv === 'refresh') {
  1016. win.close();
  1017. }
  1018. }
  1019. }
  1020. gardener('span[class],ul[class],span[id],ul[id]', /\/\d{12,}\.php/i, {root:'#sidebar1', observe:true});
  1021. gardener('div[id][style*="!important"]', /!important/i);
  1022. };
  1023. scripts['rumedia.ws'] = scripts['rustorka.com'];
  1024.  
  1025. scripts['sports.ru'] = function() {
  1026. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.aside-news-block'});
  1027. };
  1028.  
  1029. scripts['turbobit.net'] = {'now': preventBackgroundRedirect};
  1030.  
  1031. scripts['yap.ru'] = function() {
  1032. var words = /member1438|Administration/;
  1033. gardener('form > table[id^="p_row_"]', words);
  1034. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  1035. };
  1036. scripts['yaplakal.com'] = scripts['yap.ru'];
  1037.  
  1038. scripts['reactor.cc'] = {
  1039. 'now': preventBackgroundRedirect,
  1040. 'DOMContentLoaded': function() {
  1041. var words = new RegExp(
  1042. 'блокировщика рекламы'
  1043. .split('')
  1044. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  1045. .join('')
  1046. .replace(' ', '\\s*')
  1047. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  1048. 'i'),
  1049. can;
  1050. function deeper(spider) {
  1051. var c, l, n;
  1052. if (words.test(spider.innerText)) {
  1053. if (spider.nodeType === Node.TEXT_NODE) {
  1054. return true;
  1055. }
  1056. c = spider.childNodes;
  1057. l = c.length;
  1058. n = 0;
  1059. while(l--) {
  1060. if (deeper(c[l]), can) {
  1061. n++;
  1062. }
  1063. }
  1064. if (n > 0 && n === c.length && spider.offsetHeight < 750) {
  1065. can.push(spider);
  1066. }
  1067. return false;
  1068. }
  1069. return true;
  1070. }
  1071. function probe(){
  1072. if (words.test(document.body.innerText)) {
  1073. can = [];
  1074. deeper(document.body);
  1075. var i = can.length, j, spider;
  1076. while(i--) {
  1077. spider = can[i];
  1078. if (spider.offsetHeight > 10 && spider.offsetHeight < 750) {
  1079. spider.setAttribute('style', 'background:none!important');
  1080. }
  1081. }
  1082. }
  1083. }
  1084. var o = new MutationObserver(probe);
  1085. o.observe(document,{childList:true, subtree:true});
  1086. }
  1087. };
  1088. scripts['joyreactor.cc'] = scripts['reactor.cc'];
  1089. scripts['pornreactor.cc'] = scripts['reactor.cc'];
  1090.  
  1091. scripts['auto.ru'] = function() {
  1092. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  1093. var userAdsListAds = [
  1094. '.listing-list > .listing-item',
  1095. '.listing-item_type_fixed.listing-item'
  1096. ];
  1097. var catalogAds = [
  1098. 'div[class*="layout_catalog-inline"]',
  1099. 'div[class$="layout_horizontal"]'
  1100. ];
  1101. var otherAds = [
  1102. '.advt_auto',
  1103. '.sidebar-block',
  1104. '.pager-listing + div[class]',
  1105. '.card > div[class][style]',
  1106. '.sidebar > div[class]',
  1107. '.main-page__section + div[class]',
  1108. '.listing > tbody'];
  1109. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', observe:true});
  1110. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', observe:true});
  1111. gardener(otherAds.join(','), words);
  1112. };
  1113.  
  1114. scripts['online.anidub.com'] = function() {
  1115. var script = document.createElement('script');
  1116. script.type = "text/javascript";
  1117. script.innerHTML = "function ogonekstart1() {}";
  1118. document.getElementsByTagName('head')[0].appendChild(script);
  1119.  
  1120. var style = document.createElement('style');
  1121. style.type = 'text/css';
  1122. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  1123. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  1124. document.head.appendChild(style);
  1125. };
  1126.  
  1127. scripts['rsload.net'] = function() {
  1128. win.addEventListener('load', function() {
  1129. var dis = document.querySelector('.cb-disable');
  1130. if (dis) {
  1131. dis.click();
  1132. }
  1133. });
  1134. document.addEventListener('click',function(e){
  1135. var t = e.target;
  1136. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href))) {
  1137. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  1138. }
  1139. });
  1140. };
  1141.  
  1142. scripts['imageban.ru'] = {
  1143. 'now': preventBackgroundRedirect,
  1144. 'DOMContentLoaded': function() {
  1145. win.addEventListener('unload', function() {
  1146. if (!window.location.hash) {
  1147. window.location.replace(window.location+'#');
  1148. } else {
  1149. window.location.hash = '';
  1150. }
  1151. }, true);
  1152. }
  1153. };
  1154.  
  1155. var domain = document.domain, name;
  1156. while (domain.indexOf('.') !== -1) {
  1157. if (scripts.hasOwnProperty(domain)) {
  1158. if (typeof scripts[domain] === 'function') {
  1159. document.addEventListener ('DOMContentLoaded', scripts[domain], false);
  1160. }
  1161. for (name in scripts[domain]) {
  1162. if (name !== 'now') {
  1163. document.addEventListener (name, scripts[domain][name], false);
  1164. } else {
  1165. scripts[domain].now();
  1166. }
  1167. }
  1168. }
  1169. domain = domain.slice(domain.indexOf('.') + 1);
  1170. }
  1171. })();

QingJ © 2025

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