RU AdList JS Fixes

try to take over the world!

当前为 2016-10-13 提交的版本,查看 最新版本

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