RU AdList JS Fixes

try to take over the world!

目前為 2016-10-01 提交的版本,檢視 最新版本

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