RU AdList JS Fixes

try to take over the world!

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

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