RU AdList JS Fixes

try to take over the world!

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

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