RU AdList JS Fixes

try to take over the world!

目前為 2017-03-04 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 20170304.2
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. var win = (unsafeWindow || window),
  18. // http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  19. isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
  20. isChrome = !!window.chrome && !!window.chrome.webstore,
  21. isSafari = (Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 ||
  22. (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.safari || safari.pushNotification)),
  23. isFirefox = typeof InstallTrigger !== 'undefined';
  24.  
  25. // NodeList iterator polyfill (mostly for Safari)
  26. // https://jakearchibald.com/2014/iterators-gonna-iterate/
  27. if (!NodeList.prototype[Symbol.iterator]) {
  28. NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
  29. }
  30.  
  31. // Options
  32. var opts = {
  33. 'useWSIFunc': useWSI
  34. };
  35. (function(){
  36. function optsCall(callback) {
  37. // Register event listener
  38. var key = "optsCallEvent_" + Math.random().toString(36).substr(2),
  39. cb = callback.func.bind(callback.name);
  40. window.addEventListener(key, cb, false);
  41. // Generate and dispatch synthetic event
  42. var ev = document.createEvent("HTMLEvents");
  43. ev.initEvent(key, true, false);
  44. window.dispatchEvent(ev);
  45. // Remove listener
  46. window.removeEventListener(key, cb, false);
  47. }
  48. function initOptsHandler() {
  49. /*jshint validthis:true */
  50. opts[this] = GM_getValue(this, true);
  51. if(opts[this]) {
  52. opts[this+'Func']();
  53. }
  54. }
  55. optsCall({
  56. func: initOptsHandler,
  57. name: 'useWSI'
  58. });
  59. // show options page
  60. function openOptions() {
  61. var ovl = document.createElement('div'),
  62. inner = document.createElement('div');
  63. ovl.style = (
  64. 'position: fixed;'+
  65. 'top:0; left:0;'+
  66. 'bottom: 0; right: 0;'+
  67. 'background: rgba(0,0,0,0.85);'+
  68. 'z-index: 2147483647;'+
  69. 'padding: 5em'
  70. );
  71. inner.style = (
  72. 'background: whitesmoke;'+
  73. 'font-size: 10pt;'+
  74. 'color: black;'+
  75. 'padding: 1em'
  76. );
  77. inner.textContent = 'JS Fixes Options: (reload page to apply)';
  78. inner.appendChild(document.createElement('br'));
  79. inner.appendChild(document.createElement('br'));
  80. ovl.addEventListener('click', function(e){
  81. if (e.target === ovl) {
  82. ovl.parentNode.removeChild(ovl);
  83. e.preventDefault();
  84. }
  85. e.stopPropagation();
  86. }, false);
  87. // append checkbox with label function
  88. function addCheckbox(optName, optLabel) {
  89. var c = document.createElement('input'),
  90. l = document.createElement('label');
  91. c.type = 'checkbox';
  92. c.id = optName;
  93. optsCall({
  94. func:function(){
  95. c.checked = GM_getValue(this);
  96. },
  97. name:optName
  98. });
  99. c.addEventListener('click', function(e) {
  100. optsCall({
  101. func:function(){
  102. GM_setValue(this, e.target.checked);
  103. opts[this] = e.target.checked;
  104. },
  105. name:optName
  106. });
  107. }, true);
  108. l.textContent = optLabel;
  109. l.setAttribute('for', optName);
  110. inner.appendChild(c);
  111. inner.appendChild(l);
  112. inner.appendChild(document.createElement('br'));
  113. }
  114. // append checkboxes
  115. addCheckbox('useWSI', 'Use WebSocket filter. Disable if experience problems with WebSocket connections.');
  116. document.body.appendChild(ovl);
  117. ovl.appendChild(inner);
  118. }
  119. // monitor keys pressed for Ctrl+Alt+Shift+J > s > f code
  120. var opPos = 0, opKey = 'Jsf', isNotKey;
  121. document.addEventListener('keydown', function(e) {
  122. isNotKey = (e.key.length > 1);
  123. if ((e.key === opKey[opPos] || isNotKey) &&
  124. (!!opPos || e.altKey && e.ctrlKey)) {
  125. opPos += (isNotKey ? 0 : 1);
  126. e.stopPropagation();
  127. e.preventDefault();
  128. } else {
  129. opPos = 0;
  130. }
  131. if (opPos === opKey.length) {
  132. opPos = 0;
  133. openOptions();
  134. }
  135. }, false);
  136. })();
  137.  
  138. // Creates and return protected style (unless protection is manually disabled).
  139. // Protected style will re-add itself on removal and remaind enabled on attempt to disable it.
  140. function createStyle(rules, props, skip_protect) {
  141. var root = document.documentElement;
  142.  
  143. function _protect(style) {
  144. Object.defineProperty(style, 'sheet', {
  145. value: style.sheet,
  146. enumerable: true
  147. });
  148. Object.defineProperty(style, 'disabled', {
  149. get: function() {return true;}, //pretend to be disabled
  150. set: function() {},
  151. enumerable: true
  152. });
  153. }
  154.  
  155. function _create() {
  156. var style = root.appendChild(document.createElement('style')),
  157. prop, rule;
  158. style.type = 'text/css';
  159. for (prop in props) {
  160. if (style[prop] !== undefined) {
  161. style[prop] = props[prop];
  162. }
  163. }
  164. function insertRule(rule) {
  165. try {
  166. style.sheet.insertRule(rule, 0);
  167. } catch (e) {
  168. console.error(e);
  169. }
  170. }
  171. if (typeof rules === 'string') {
  172. insertRule(rules);
  173. } else {
  174. rules.forEach(insertRule);
  175. }
  176. if (!skip_protect) {
  177. _protect(style);
  178. }
  179. return style;
  180. }
  181.  
  182. var style = _create();
  183. if (skip_protect) {
  184. return style;
  185. }
  186.  
  187. var o = new MutationObserver(function(ms){
  188. var m, node, rule;
  189. for (m of ms) {
  190. for (node of m.removedNodes) {
  191. if (node === style) {
  192. (new Promise(function(resolve){
  193. setTimeout(function(resolve){
  194. resolve(_create());
  195. }, 0, resolve);
  196. })).then(function(st){
  197. style = st;
  198. });
  199. }
  200. }
  201. }
  202. });
  203. o.observe(root, {childList:true});
  204.  
  205. return style;
  206. }
  207.  
  208. // https://greasyfork.org/scripts/19144-websuckit/
  209. function useWSI() {
  210. // check does browser support Proxy and WebSocket
  211. if (typeof Proxy !== 'function' ||
  212. typeof WebSocket !== 'function') {
  213. return;
  214. }
  215.  
  216. function getWrappedCode(removeSelf) {
  217. var text = getWrappedCode.toString()+WSI.toString();
  218. text = (
  219. '(function(){"use strict";'+
  220. text.replace(/\/\/[^\r\n]*/g,'').replace(/[\s\r\n]+/g,' ')+
  221. '(new WSI(self||window)).init();'+
  222. '})();\n'+
  223. (removeSelf?'var s = document.currentScript; if (s) {s.parentNode.removeChild(s);}':'')
  224. );
  225. return text;
  226. }
  227.  
  228. function WSI(win, safeWin) {
  229. safeWin = safeWin || win;
  230. var masks = [], filter;
  231. for (filter of [// blacklist
  232. '||10root25.website^', '||24video.xxx^',
  233. '||adlabs.ru^', '||adspayformymortgage.win^', '||aviabay.ru^',
  234. '||bgrndi.com^', '||brokeloy.com^',
  235. '||cnamerutor.ru^',
  236. '||docfilms.info^', '||dreadfula.ru^',
  237. '||et-code.ru^',
  238. '||film-doma.ru^',
  239. '||free-torrent.org^', '||free-torrent.pw^',
  240. '||free-torrents.org^', '||free-torrents.pw^',
  241. '||game-torrent.info^', '||gocdn.ru^',
  242. '||hdkinoshka.com^', '||hghit.com^', '||hindcine.net^',
  243. '||kiev.ua^', '||kinotochka.net^',
  244. '||kinott.com^', '||kinott.ru^', '||kuveres.com^',
  245. '||lepubs.com^', '||luxadv.com^', '||luxup.ru^', '||luxupcdna.com^',
  246. '||mail.ru^', '||marketgid.com^', '||mxtads.com^',
  247. '||nickhel.com^',
  248. '||oconner.biz^', '||oconner.link^',
  249. '||pkpojhc.com^',
  250. '||psma01.com^', '||psma02.com^', '||psma03.com^',
  251. '||recreativ.ru^', '||redtram.com^', '||regpole.com^', '||rootmedia.ws^', '||ruttwind.com^',
  252. '||skidl.ru^',
  253. '||torvind.com^', '||trafmag.com^',
  254. '||webadvert-gid.ru^', '||webadvertgid.ru^',
  255. '||xxuhter.ru^',
  256. '||yuiout.online^',
  257. '||zoom-film.ru^'
  258. ]) {
  259. masks.push(new RegExp(
  260. filter.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  261. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  262. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  263. .replace(/^\|\|/,'^wss?:\\/+([^\/.]+\\.)*'),
  264. 'i'));
  265. }
  266.  
  267. function isBlocked(url) {
  268. for (var mask of masks) {
  269. if (mask.test(url)) {
  270. return true;
  271. }
  272. }
  273. return false;
  274. }
  275.  
  276. var realWebSocket = win.WebSocket;
  277. function wsGetter (target, name) {
  278. try {
  279. if (typeof realWebSocket.prototype[name] === 'function') {
  280. if (name === 'close' || name === 'send') { // send also closes connection
  281. target.readyState = realWebSocket.CLOSED;
  282. }
  283. return (
  284. function fake() {
  285. console.log('[WSI] Invoked function "'+name+'"', '| Tracing', (new Error()));
  286. return;
  287. }
  288. );
  289. }
  290. if (typeof realWebSocket.prototype[name] === 'number') {
  291. return realWebSocket[name];
  292. }
  293. } catch(ignore) {}
  294. return target[name];
  295. }
  296.  
  297. function createWebSocketWrapper(target) {
  298. return new Proxy(realWebSocket, {
  299. construct: function (target, args) {
  300. var url = args[0];
  301. console.log('[WSI] Opening socket on ' + url + ' \u2026');
  302. if (isBlocked(url)) {
  303. console.log("[WSI] Blocked.");
  304. return new Proxy({
  305. url: url,
  306. readyState: realWebSocket.OPEN
  307. }, {
  308. get: wsGetter
  309. });
  310. }
  311. return new target(args[0], args[1]);
  312. }
  313. });
  314. }
  315.  
  316. function WorkerWrapper() {
  317. var realWorker = win.Worker;
  318. function wrappedWorker(resourceURI) {
  319. var isBlobURL = /^blob:/i,
  320. xhr = null,
  321. _callbacks = new WeakMap(),
  322. _worker = null,
  323. _terminate = false,
  324. _onerror = null,
  325. _onmessage = null,
  326. _messages = [],
  327. _events = [],
  328. /*jshint validthis:true */
  329. _self = this;
  330.  
  331. function callbackWrapper(func) {
  332. if (typeof func !== 'function') {
  333. return undefined;
  334. }
  335. return (
  336. function callback() {
  337. func.apply(_self, arguments);
  338. }
  339. );
  340. }
  341.  
  342. _self.terminate = function(){
  343. _terminate = true;
  344. if (_worker) {
  345. _worker.terminate();
  346. }
  347. };
  348. Object.defineProperty(_self, 'onmessage', {
  349. get: function() {
  350. return _onmessage;
  351. },
  352. set: function(val) {
  353. _onmessage = val;
  354. if (_worker) {
  355. _worker.onmessage = callbackWrapper(val);
  356. }
  357. }
  358. });
  359. Object.defineProperty(_self, 'onerror', {
  360. get: function() {
  361. return _onerror;
  362. },
  363. set: function(val) {
  364. _onerror = val;
  365. if (_worker) {
  366. _worker.onerror = callbackWrapper(val);
  367. }
  368. }
  369. });
  370. _self.postMessage = function(message){
  371. if (_worker) {
  372. _worker.postMessage(message);
  373. } else {
  374. _messages.push(message);
  375. }
  376. };
  377. _self.terminate = function() {
  378. _terminate = true;
  379. if (_worker) {
  380. _worker.terminate();
  381. }
  382. };
  383. _self.addEventListener = function(){
  384. if (typeof arguments[1] !== 'function') {
  385. return;
  386. }
  387. if (!_callbacks.has(arguments[1])) {
  388. _callbacks.set(arguments[1], callbackWrapper(arguments[1]));
  389. }
  390. arguments[1] = _callbacks.get(arguments[1]);
  391. if (_worker) {
  392. _worker.addEventListener.apply(_worker, arguments);
  393. } else {
  394. _events.push(['addEventListener', arguments]);
  395. }
  396. };
  397. _self.removeEventListener = function(){
  398. if (typeof arguments[1] !== 'function' || !_callbacks.has(arguments[1])) {
  399. return;
  400. }
  401. arguments[1] = _callbacks.get(arguments[1]);
  402. _callbacks.delete(arguments[1]);
  403. if (_worker) {
  404. _worker.removeEventListener.apply(_worker, arguments);
  405. } else {
  406. _events.push(['removeEventListener', arguments]);
  407. }
  408. };
  409.  
  410. if (!isBlobURL.test(resourceURI)) {
  411. _worker = new realWorker(resourceURI);
  412. return; // not a blob, no need to wrap
  413. }
  414.  
  415. xhr = new XMLHttpRequest();
  416. xhr.responseType = 'blob';
  417. try {
  418. xhr.open('GET', resourceURI, true);
  419. } catch(ignore) {
  420. _worker = new realWorker(resourceURI);
  421. return; // failed to open connection, unable to continue wrapping procedure
  422. }
  423. (new Promise(function(resolve, reject){
  424. if (xhr.readyState !== XMLHttpRequest.OPENED) {
  425. // connection wasn't opened, unable to continue wrapping procedure
  426. return reject();
  427. }
  428. xhr.onload = function(){
  429. if (this.status === 200) {
  430. var reader = new FileReader();
  431. reader.addEventListener("loadend", function() {
  432. resolve(new realWorker(URL.createObjectURL(
  433. new Blob([getWrappedCode(false)+this.result])
  434. )));
  435. });
  436. reader.readAsText(this.response);
  437. }
  438. };
  439. xhr.send();
  440. })).then(function(val) {
  441. _worker = val;
  442. _worker.onerror = callbackWrapper(_onerror);
  443. _worker.onmessage = callbackWrapper(_onmessage);
  444. var _e;
  445. while(_events.length) {
  446. _e = _events.shift();
  447. _worker[_e[0]].apply(_worker, _e[1]);
  448. }
  449. while(_messages.length) {
  450. _worker.postMessage(_messages.shift());
  451. }
  452. if (_terminate) {
  453. _worker.terminate();
  454. }
  455. }).catch(function(){});
  456.  
  457. }
  458. win.Worker = wrappedWorker.bind(safeWin);
  459. }
  460.  
  461. function CreateElementWrapper() {
  462. var realCreateElement = Document.prototype.createElement,
  463. code = encodeURIComponent('<scr'+'ipt>'+getWrappedCode(true)+'</scr'+'ipt>\n'),
  464. isDataURL = /^data:/i,
  465. isBlobURL = /^blob:/i;
  466.  
  467. function frameRewrite(e) {
  468. var f = e.target,
  469. w = f.contentWindow;
  470. if (!f.src || (w && isBlobURL.test(f.src))) {
  471. w.WebSocket = createWebSocketWrapper();
  472. }
  473. if (isDataURL.test(f.src) && f.src.indexOf(code) < 0) {
  474. f.src = f.src.replace(',',',' + code);
  475. }
  476. }
  477.  
  478. function wrappedCreateElement(name) {
  479. /*jshint validthis:true */
  480. var el = realCreateElement.apply(this, arguments);
  481. if (el.tagName === 'IFRAME') {
  482. el.addEventListener('load', frameRewrite, false);
  483. }
  484. return el;
  485. }
  486. Document.prototype.createElement = wrappedCreateElement;
  487.  
  488. document.addEventListener('DOMContentLoaded', function(){
  489. for (var ifr of document.querySelectorAll('IFRAME')) {
  490. ifr.addEventListener('load', frameRewrite, false);
  491. }
  492. }, false);
  493. }
  494.  
  495. this.init = function() {
  496. win.WebSocket = createWebSocketWrapper();
  497. if (!(/firefox/i.test(navigator.userAgent))) {
  498. WorkerWrapper(); // skip WorkerWrapper in Firefox
  499. }
  500. if (typeof document !== 'undefined') {
  501. CreateElementWrapper();
  502. }
  503. };
  504. }
  505.  
  506. if (isFirefox) {
  507. var script = document.createElement('script');
  508. script.appendChild(document.createTextNode(getWrappedCode(true)));
  509. document.head.insertBefore(script, document.head.firstChild);
  510. return; //we don't want to call functions on page from here in Fx, so exit
  511. }
  512.  
  513. (new WSI((unsafeWindow||self||window),(self||window))).init();
  514. }
  515.  
  516. if (!isFirefox) { // scripts for non-Firefox browsers
  517.  
  518. // https://greasyfork.org/scripts/14720-it-s-not-important
  519. (function(){
  520. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig;
  521.  
  522. function unimportanter(el, si) {
  523. if (!imptt.test(si) || el.style.display === 'none') {
  524. return 0; // get out if we have nothing to do here
  525. }
  526. if (el.nodeName === 'IFRAME' && el.src &&
  527. el.src.slice(0,17) === 'chrome-extension:') {
  528. return 0; // Web of Trust uses this method to add their frame
  529. }
  530. var so = si.replace(imptt, function(){return arguments[1];}), ret = 0;
  531. if (si !== so) {
  532. ret = 1;
  533. el.setAttribute('style', so);
  534. }
  535. return ret;
  536. }
  537.  
  538. function logger(c) {
  539. if (c) {
  540. console.log('Some page elements became a bit less important.');
  541. }
  542. }
  543.  
  544. function checkTarget(node, cnt) {
  545. if (!(node && node.getAttribute)) {
  546. return 0;
  547. }
  548. var si = node.getAttribute('style');
  549. if (si && si.indexOf('!') > -1) {
  550. cnt += unimportanter(node, si);
  551. }
  552. return cnt;
  553. }
  554.  
  555. var observer = new MutationObserver(function(mutations) {
  556. setTimeout(function(ms) {
  557. var cnt = 0, m, node;
  558. for (m of ms) {
  559. cnt = checkTarget(m.target, cnt);
  560. for (node of m.addedNodes) {
  561. cnt += checkTarget(node, cnt);
  562. }
  563. }
  564. logger(cnt);
  565. }, 0, mutations);
  566. });
  567.  
  568. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  569.  
  570. win.addEventListener ("load", function(){
  571. var c = 0, imp;
  572. for (imp of document.querySelectorAll('[style*="!"]')) {
  573. c+= checkTarget(imp, c);
  574. }
  575. logger(c);
  576. }, false);
  577. })();
  578.  
  579. }
  580.  
  581. if (/^https?:\/\/(mail\.yandex\.|music\.yandex\.|news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href)) {
  582. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  583. (function(){
  584. var adWords = ['Яндекс.Директ','Реклама','Ad'];
  585. function remove(node) {
  586. node.parentNode.removeChild(node);
  587. }
  588. // Generic ads removal and fixes
  589. function removeGenericAds() {
  590. var s, i;
  591. s = document.querySelector('.serp-header');
  592. if (s) {
  593. s.style.marginTop='0';
  594. }
  595. for (s of document.querySelectorAll('.serp-adv__head + .serp-item, #adbanner, .serp-adv, .b-spec-adv, div[class*="serp-adv__"]:not(.serp-adv__found):not(.serp-adv__displayed)')) {
  596. remove(s);
  597. }
  598. }
  599. // Search ads
  600. function removeSearchAds() {
  601. var s, item;
  602. for (s of document.querySelectorAll('.serp-block, .serp-item, .search-item')) {
  603. item = s.querySelector('.label, .serp-item__label, .document__provider-name');
  604. if (item && adWords.indexOf(item.textContent) > -1) {
  605. remove(s);
  606. console.log('Ads removed.');
  607. }
  608. }
  609. }
  610. // Search link tracking
  611. function disableLinkTracking() {
  612. function removeTracking() {
  613. for (var a of document.querySelectorAll('A[href^="http"][onmousedown]')) {
  614. a.removeAttribute('onmousedown');
  615. }
  616. }
  617. var o = new MutationObserver(function(ms) {
  618. var m, node;
  619. for (m of ms) {
  620. if (m.addedNodes.length) {
  621. removeTracking();
  622. }
  623. }
  624. });
  625. o.observe(document.body, {childList: true, subtree: true});
  626. }
  627. // News ads
  628. function removeNewsAds() {
  629. for (var s of document.querySelectorAll(
  630. '.page-content__left > *,'+
  631. '.page-content__right > *:not(.page-content__col),'+
  632. '.page-content__right > .page-content__col > *'
  633. )) {
  634. if (s.textContent.indexOf(adWords[0]) > -1 ||
  635. (s.clientHeight < 15 && s.classList.contains('rubric'))) {
  636. remove(s);
  637. console.log('Ads removed.');
  638. }
  639. }
  640. }
  641. // Music ads
  642. function removeMusicAds() {
  643. for (var s of document.querySelectorAll('.ads-block')) {
  644. remove(s);
  645. }
  646. }
  647. // Mail ads
  648. function removeMailAds() {
  649. var slice = Array.prototype.slice,
  650. nodes = slice.call(document.querySelectorAll('.ns-view-folders')),
  651. node, len, classes, cls;
  652. for (node of nodes) {
  653. if (!len || len > node.classList.length) {
  654. len = node.classList.length;
  655. }
  656. }
  657. node = nodes.pop();
  658. while (node) {
  659. if (node.classList.length > len) {
  660. for (cls of slice.call(node.classList)) {
  661. if (cls.indexOf('-') === -1) {
  662. remove(node);
  663. break;
  664. }
  665. }
  666. }
  667. node = nodes.pop();
  668. }
  669. }
  670. // News fixes
  671. function removePageAdsClass() {
  672. if (document.body.classList.contains("b-page_ads_yes")){
  673. document.body.classList.remove("b-page_ads_yes");
  674. console.log('Page ads class removed.');
  675. }
  676. }
  677. // Function to attach an observer to monitor dynamic changes on the page
  678. function pageUpdateObserver(func, obj, params) {
  679. if (obj) {
  680. var o = new MutationObserver(func);
  681. o.observe(obj,(params || {childList:true, subtree:true}));
  682. }
  683. }
  684. // Cleaner
  685. document.addEventListener ('DOMContentLoaded', function() {
  686. removeGenericAds();
  687. if (win.location.hostname.search(/^mail\./i) === 0) {
  688. pageUpdateObserver(function(ms, o){
  689. var aside = document.querySelector('.mail-Layout-Aside');
  690. if (aside) {
  691. o.disconnect();
  692. pageUpdateObserver(removeMailAds, aside);
  693. }
  694. }, document.querySelector('BODY'));
  695. removeMailAds();
  696. } else if (win.location.hostname.search(/^music\./i) === 0) {
  697. pageUpdateObserver(removeMusicAds, document.querySelector('.sidebar'));
  698. removeMusicAds();
  699. } else if (win.location.hostname.search(/^news\./i) === 0) {
  700. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  701. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  702. removeNewsAds();
  703. removePageAdsClass();
  704. } else {
  705. pageUpdateObserver(removeSearchAds, document.querySelector('.main__content'));
  706. removeSearchAds();
  707. disableLinkTracking();
  708. }
  709. });
  710. })();
  711. return; //skip fixes for other sites
  712. }
  713.  
  714. // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix v0.8 (adapted)
  715. document.addEventListener ('DOMContentLoaded', function() {
  716. var tmp;
  717. function log (e) {
  718. console.log('Moonwalk&HDGo&Kodik FIX: ' + e + ' player in ' + win.location.href);
  719. }
  720. if (win.adv_enabled !== undefined && win.condition_detected !== undefined) { // moonwalk
  721. log('Moonwalk');
  722. if (win.adv_enabled) {
  723. win.adv_enabled = false;
  724. }
  725. win.condition_detected = false;
  726. if (win.MXoverrollCallback) {
  727. document.addEventListener('click', function catcher(e){
  728. e.stopPropagation();
  729. win.MXoverrollCallback.call(window);
  730. document.removeEventListener('click', catcher, true);
  731. }, true);
  732. }
  733. } else if (win.stat_url !== undefined && win.is_html5 !== undefined && win.is_wp8 !== undefined) { // hdgo
  734. log('HDGo');
  735. document.body.onclick = null;
  736. tmp = document.querySelector('#swtf');
  737. if (tmp) {
  738. tmp.style.display = 'none';
  739. }
  740. if (win.banner_second !== undefined) {
  741. win.banner_second = 0;
  742. }
  743. if (win.$banner_ads !== undefined) {
  744. win.$banner_ads = false;
  745. }
  746. if (win.$new_ads !== undefined) {
  747. win.$new_ads = false;
  748. }
  749. if (win.createCookie !== undefined) {
  750. win.createCookie('popup','true','999');
  751. }
  752. if (win.canRunAds !== undefined && win.canRunAds !== true) {
  753. win.canRunAds = true;
  754. }
  755. } else if (win.MXoverrollCallback && win.iframeSearch !== undefined) { // kodik
  756. log('Kodik');
  757. tmp = document.querySelector('.play_button');
  758. if (tmp) {
  759. tmp.onclick = win.MXoverrollCallback.bind(window);
  760. }
  761. win.IsAdBlock = false;
  762. }
  763. }, false);
  764.  
  765. // function to search and remove nodes by content
  766. // selector - standard CSS selector to define set of nodes to check
  767. // words - regular expression to check content of the suspicious nodes
  768. // params - object with multiple extra parameters:
  769. // .hide - set display to none instead of removing from the page
  770. // .parent - parent node to remove if content is found in the child node
  771. // .siblings - number of simling nodes to remove (excluding text nodes)
  772. function scRemove(e) {e.parentNode.removeChild(e);}
  773. function scHide(e) {
  774. var s = e.getAttribute('style')||'',
  775. h = ';display:none!important;';
  776. if (s.indexOf(h) < 0) {
  777. e.setAttribute('style', s+h);
  778. }
  779. }
  780. function scissors (selector, words, scope, params) {
  781. var remFunc = (params.hide ? scHide : scRemove),
  782. iterFunc = (params.siblings > 0 ?
  783. 'nextSibling' :
  784. 'previousSibling'),
  785. toRemove = [],
  786. siblings,
  787. node;
  788. for (node of scope.querySelectorAll(selector)) {
  789. if (words.test(node.innerHTML) || !node.childNodes.length) {
  790. // drill up to the specified parent node if required
  791. if (params.parent) {
  792. while(node !== scope && !(node.matches(params.parent))) {
  793. node = node.parentNode;
  794. }
  795. }
  796. if (node === scope) {
  797. break;
  798. }
  799. toRemove.push(node);
  800. // add multiple nodes if defined more than one sibling
  801. siblings = Math.abs(params.siblings) || 0;
  802. while (siblings) {
  803. node = node[iterFunc];
  804. toRemove.push(node);
  805. if (node.nodeType === Node.ELEMENT_NODE) {
  806. siblings -= 1; //count only element nodes
  807. }
  808. }
  809. }
  810. }
  811. for (node of toRemove) {
  812. remFunc(node);
  813. }
  814. return toRemove.length;
  815. }
  816.  
  817. // function to perform multiple checks if ads inserted with a delay
  818. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  819. // also does 1 extra check when a page completely loads
  820. // selector and words - passed dow to scissors
  821. // params - object with multiple extra parameters:
  822. // .root - selector to narrow down scope to scan;
  823. // .observe - if true then check will be performed continuously;
  824. // Other parameters passed down to scissors.
  825. function gardener(selector, words, params) {
  826. params = params || {};
  827. var scope = document,
  828. nonstop = false;
  829. // narrow down scope to a specific element
  830. if (params.root) {
  831. scope = scope.querySelector(params.root);
  832. if (!scope) {// exit if the root element is not present on the page
  833. return 0;
  834. }
  835. }
  836. // add observe mode if required
  837. if (params.observe) {
  838. if (typeof MutationObserver === 'function') {
  839. var o = new MutationObserver(function(ms){
  840. for (var m of ms) {
  841. if (m.addedNodes.length) {
  842. scissors(selector, words, scope, params);
  843. }
  844. }
  845. });
  846. o.observe(scope, {childList:true, subtree: true});
  847. } else {
  848. nonstop = true;
  849. }
  850. }
  851. // wait for a full page load to do one extra cut
  852. win.addEventListener('load',function(){
  853. scissors(selector, words, scope, params);
  854. });
  855. // do multiple cuts until ads removed
  856. function cut(sci, s, w, sc, p, i) {
  857. if (i > 0) {
  858. i -= 1;
  859. }
  860. if (i && !sci(s, w, sc, p)) {
  861. setTimeout(cut, 100, sci, s, w, sc, p, i);
  862. }
  863. }
  864. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  865. }
  866.  
  867. function preventBackgroundRedirect() {
  868. // create "cose_me" event to call high-level window.close()
  869. var key = Math.random().toString(36).substr(2);
  870. window.addEventListener('close_me_'+key, function(e) {
  871. window.close();
  872. });
  873.  
  874. // window.open wrapper
  875. function pbrLander() {
  876. var orgOpen = window.open.bind(window),
  877. idx = String.prototype.indexOf,
  878. event = new CustomEvent("close_me_%key%", {});
  879. function closeWindow(){
  880. // site went to a new tab and attempts to unload
  881. // call for high-level close through event
  882. window.dispatchEvent(event);
  883. }
  884. // window.open wrapper
  885. function open(){
  886. console.log(arguments, window.location.host);
  887. if (arguments[0] &&
  888. (idx.call(arguments[0], window.location.host) > -1 ||
  889. idx.call(arguments[0], '://') === -1)) {
  890. window.addEventListener('unload', closeWindow, true);
  891. }
  892. orgOpen.apply(window, arguments);
  893. }
  894. window.open = open.bind(window);
  895. // Node.createElement wrapper to prevent click-dispatch in Google Chrome and similar browsers
  896. var realCreateElement = Document.prototype.createElement;
  897. function wrappedCreateElement(name) {
  898. /*jshint validthis:true */
  899. var el = realCreateElement.apply(this, arguments);
  900. if (el.tagName === 'A') {
  901. el.addEventListener('click', function(e){
  902. if (!e.target.parentNode || !e.isTrusted) {
  903. window.addEventListener('unload', closeWindow, true);
  904. }
  905. }, false);
  906. }
  907. return el;
  908. }
  909. Document.prototype.createElement = wrappedCreateElement;
  910. }
  911.  
  912. // land wrapper on the page
  913. var script = document.createElement('script');
  914. script.appendChild(document.createTextNode('('+pbrLander.toString().replace(/%key%/g,key)+')();'));
  915. document.head.insertBefore(script, document.head.firstChild);
  916. script.parentNode.removeChild(script);
  917. console.log("Background redirect prevention enabled.");
  918. }
  919.  
  920. function preventPopups() {
  921. if (isFirefox) {
  922. var s = document.createElement('script');
  923. s.textContent = 'var win = self, isFirefox = !1; ('+preventPopups.toString()+')();';
  924. document.documentElement.appendChild(s);
  925. document.documentElement.removeChild(s);
  926. }
  927. win.open = function(){
  928. console.log('Site attempted to open a new window', arguments);
  929. return {};
  930. };
  931. window.open = win.open;
  932. var realCreateElement = Document.prototype.createElement;
  933. function wrappedCreateElement(name) {
  934. /*jshint validthis:true */
  935. var el = realCreateElement.apply(this, arguments);
  936. if (el.tagName === 'A') {
  937. el.addEventListener('click', function(e){
  938. if (!e.target.parentNode || !e.isTrusted) {
  939. e.preventDefault();
  940. console.log('Blocked suspicious click event', e, 'on', e.target);
  941. }
  942. }, false);
  943. }
  944. return el;
  945. }
  946. Document.prototype.createElement = wrappedCreateElement;
  947. }
  948.  
  949. function forbidServiceWorker() {
  950. if (!("serviceWorker" in navigator)) {
  951. return;
  952. }
  953. var svr = navigator.serviceWorker.ready;
  954. Object.defineProperty(navigator, 'serviceWorker', {
  955. value: {
  956. register: function(){
  957. console.log('Registration of serviceWorker ' + arguments[0] + ' blocked.');
  958. return new Promise(function(){});
  959. },
  960. ready: new Promise(function(){}),
  961. addEventListener:function(){}
  962. }
  963. });
  964. document.addEventListener('DOMContentLoaded', function() {
  965. if (!svr) {
  966. return;
  967. }
  968. svr.then(function(sw) {
  969. console.log('Found existing serviceWorker:', sw);
  970. console.log('Attempting to unregister...');
  971. sw.unregister().then(function() {
  972. console.log('Unregistered! :)');
  973. }).catch(function(err) {
  974. console.log('Unregistration failed. :(', err);
  975. console.log('Try to remove it manually:');
  976. console.log(' 1. Open: chrome://serviceworker-internals/ (Google Chrome and alike) or about:serviceworkers (Mozilla Firefox) in a new tab.');
  977. console.log(' 2. Search there for one with "'+document.domain+'" in the name.');
  978. console.log(' 3. Use buttons in the same block with service you found to stop it and uninstall/unregister.');
  979. });
  980. }).catch(function(err) {
  981. console.log("Lol, it failed on it's own. -_-", err);
  982. });
  983. }, false);
  984. }
  985.  
  986. function forbidShadowRoot() {
  987. var cloneNode = Element.prototype.cloneNode,
  988. skipTags = ['HTML', 'STYLE', 'SCRIPT'];
  989. function replacer(func) {
  990. return function() {
  991. if (skipTags.indexOf(this.tagName)>-1) {
  992. return func.apply(this, arguments);
  993. }
  994. console.log('Prevented', func.name, 'on', this);
  995. return func.apply(cloneNode.call(this), arguments);
  996. };
  997. }
  998. for (var func of ['createShadowRoot', 'attachShadow']) {
  999. if (func in Element.prototype) {
  1000. Element.prototype[func] = replacer(Element.prototype[func]);
  1001. }
  1002. }
  1003. }
  1004.  
  1005. function errorAndLoadEventsFilter() {
  1006. var toString = Function.prototype.toString,
  1007. addEventListener = Element.prototype.addEventListener,
  1008. removeEventListener = Element.prototype.removeEventListener,
  1009. hasAttribute = Element.prototype.hasAttribute,
  1010. evtMap = new WeakMap();
  1011. Element.prototype.addEventListener = function(evt, func, capt) {
  1012. if (evt === 'error' || evt === 'load') {
  1013. if (!evtMap.get(func)) {
  1014. evtMap.set(func, function() {
  1015. if (hasAttribute.call(this, 'src')) {
  1016. func.apply(this, arguments);
  1017. } else {
  1018. console.log('Blocked', evt, 'handler', toString.call(func), 'on', this);
  1019. }
  1020. });
  1021. }
  1022. }
  1023. addEventListener.call(this, evt, (evtMap.get(func) ? evtMap.get(func) : func), capt);
  1024. };
  1025. Element.prototype.removeEventListener = function(evt, func, capt) {
  1026. removeEventListener.call(this, evt, (evtMap.get(func) ? evtMap.get(func) : func), capt);
  1027. };
  1028. Object.defineProperty(HTMLElement.prototype, 'onload', {
  1029. set: function(func) {
  1030. if (this.loadHandler) {
  1031. removeEventListener.call(this, 'load', this.loadHandler, false);
  1032. }
  1033. this.loadHandler = func;
  1034. if (func) {
  1035. addEventListener.call(this, 'load', func, false);
  1036. }
  1037. return func;
  1038. },
  1039. get: function() {
  1040. return this.loadHandler;
  1041. }
  1042. });
  1043. Object.defineProperty(HTMLElement.prototype, 'onerror', {
  1044. set: function(func) {
  1045. this.errorHandler = func;
  1046. console.log('Blocked error handler', toString.call(func), 'on', this);
  1047. return func;
  1048. },
  1049. get: function() {
  1050. return this.errorHandler;
  1051. }
  1052. });
  1053. }
  1054.  
  1055. var scripts = {};
  1056. // prevent popups and redirects block
  1057. var preventPopupsNow = { 'now': preventPopups },
  1058. preventBackgroundRedirectNow = { 'now': preventBackgroundRedirect },
  1059. apiBreaker = {
  1060. 'now': function() {
  1061. // prevents site from using Shadow DOM
  1062. forbidShadowRoot();
  1063. // prevents site from using error events and blocks load events without src
  1064. errorAndLoadEventsFilter();
  1065. console.log('API breaker applied.');
  1066. }
  1067. };
  1068. // Popups
  1069. scripts['chaturbate.com'] = preventPopupsNow;
  1070. scripts['dfiles.ru'] = preventPopupsNow;
  1071. scripts['mirrorcreator.com'] = preventPopupsNow;
  1072. scripts['openload.co'] = preventPopupsNow;
  1073. scripts['radikal.ru'] = preventPopupsNow;
  1074. scripts['tapochek.net'] = preventPopupsNow;
  1075. scripts['thepiratebay.org'] = preventPopupsNow;
  1076. scripts['zippyshare.com'] = preventPopupsNow;
  1077. // Background redirects
  1078. scripts['mediafire.com'] = preventBackgroundRedirectNow;
  1079. scripts['megapeer.org'] = preventBackgroundRedirectNow;
  1080. scripts['megapeer.ru'] = preventBackgroundRedirectNow;
  1081. scripts['turbobit.net'] = preventBackgroundRedirectNow;
  1082. // API breaker
  1083. scripts['24tv.ua'] = apiBreaker;
  1084. scripts['football24.ua'] = apiBreaker;
  1085. scripts['sinoptik.com.ru'] = apiBreaker;
  1086. scripts['sinoptik.ua'] = apiBreaker;
  1087.  
  1088. // other
  1089. scripts['4pda.ru'] = {
  1090. 'now': function() {
  1091. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  1092. var isForum = document.location.href.search('/forum/') !== -1,
  1093. hStyle;
  1094.  
  1095. function remove(n) {
  1096. if (n) {
  1097. n.parentNode.removeChild(n);
  1098. }
  1099. }
  1100.  
  1101. function afterClean() {
  1102. hStyle.disabled = true;
  1103. remove(hStyle);
  1104. }
  1105.  
  1106. function beforeClean() {
  1107. // attach styles before document displayed
  1108. hStyle = createStyle([
  1109. 'html { overflow-y: scroll }',
  1110. 'section[id] {'+(
  1111. 'position: absolute;'+
  1112. 'width: 100%'
  1113. )+'}',
  1114. 'article + aside * { display: none !important }',
  1115. '#header + div:after {'+(
  1116. 'content: "";'+
  1117. 'position: fixed;'+
  1118. 'top: 0;'+
  1119. 'left: 0;'+
  1120. 'width: 100%;'+
  1121. 'height: 100%;'+
  1122. 'background-color: #E6E7E9'
  1123. )+'}',
  1124. // http://codepen.io/Beaugust/pen/DByiE
  1125. '@keyframes spin { 100% { transform: rotate(360deg) } }',
  1126. 'article + aside:after {'+(
  1127. 'content: "";'+
  1128. 'position: absolute;'+
  1129. 'width: 150px;'+
  1130. 'height: 150px;'+
  1131. 'top: 150px;'+
  1132. 'left: 50%;'+
  1133. 'margin-top: -75px;'+
  1134. 'margin-left: -75px;'+
  1135. 'box-sizing: border-box;'+
  1136. 'border-radius: 100%;'+
  1137. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  1138. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  1139. 'animation: spin 2s infinite linear'
  1140. )+'}'
  1141. ], {id:'ubrHider'}, true);
  1142.  
  1143. // display content of a page if time to load a page is more than 2 seconds to avoid
  1144. // blocking access to a page if it is loading for too long or stuck in a loading state
  1145. setTimeout(2000, afterClean);
  1146. }
  1147.  
  1148. createStyle([
  1149. '#nav .use-ad { display: block !important }',
  1150. 'article:not(.post) + article:not(#id), a[target="_blank"] img[height="90"] { display: none !important }'
  1151. ]);
  1152.  
  1153. if (!isForum) {
  1154. beforeClean();
  1155. }
  1156.  
  1157. // save links to non-overridden functions to use later
  1158. var oGA = Element.prototype.getAttribute,
  1159. oSA = Element.prototype.setAttribute,
  1160. protectedElems;
  1161. // protect/hide changed attributes in case site attempt to restore them
  1162. function styleProtector(eventMode) {
  1163. var oRAN = Element.prototype.removeAttributeNode,
  1164. isStyleText = function(t){ return t === 'style'; },
  1165. isStyleAttr = function(a){ return a instanceof Attr && a.nodeName === 'style'; },
  1166. returnUndefined = function(){},
  1167. protectedElems = new WeakMap();
  1168. function protoOverride(element, functionName, isStyleCheck, returnIfProtected) {
  1169. var oF = element.prototype[functionName], r;
  1170. element.prototype[functionName] = function(){
  1171. if (protectedElems.get(this) !== undefined && isStyleCheck(arguments[0])) {
  1172. return returnIfProtected(protectedElems.get(this), arguments, this);
  1173. }
  1174. r = oF.apply(this, arguments);
  1175. return r;
  1176. };
  1177. }
  1178. protoOverride(Element, 'removeAttribute', isStyleText, returnUndefined);
  1179. protoOverride(Element, 'hasAttribute', isStyleText, function(o) {
  1180. return o.oldStyle !== null;
  1181. });
  1182. protoOverride(Element, 'setAttribute', isStyleText, function(o, args) {
  1183. o.oldStyle = args[1];
  1184. });
  1185. protoOverride(Element, 'getAttribute', isStyleText, function(o) {
  1186. return o.oldStyle;
  1187. });
  1188. if (eventMode) {
  1189. var e = document.createEvent('Event');
  1190. e.initEvent('protoOverride', false, false);
  1191. window.protectedElems = protectedElems;
  1192. window.dispatchEvent(e);
  1193. } else {
  1194. return protectedElems;
  1195. }
  1196. }
  1197. if (isFirefox) {
  1198. var s = document.createElement('script');
  1199. s.textContent = '(' + styleProtector.toString() + ')(true);' +
  1200. 'var s = document.currentScript; if (s) {s.parentNode.removeChild(s);}';
  1201. window.addEventListener('protoOverride', function protoOverrideCallback(e){
  1202. if (win.protectedElems) {
  1203. protectedElems = win.protectedElems;
  1204. delete win.protectedElems;
  1205. }
  1206. document.removeEventListener('protoOverride', protoOverrideCallback, true);
  1207. }, true);
  1208. document.documentElement.appendChild(s);
  1209. } else {
  1210. protectedElems = styleProtector(false);
  1211. }
  1212.  
  1213. // clean a page
  1214. window.addEventListener('DOMContentLoaded', function(){
  1215. var rem, si, itm;
  1216. function width(){ return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0; }
  1217. function height(){ return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0; }
  1218.  
  1219.  
  1220. if (isForum) {
  1221. si = document.querySelector('#logostrip');
  1222. if (si) {
  1223. remove(si.parentNode.nextSibling);
  1224. }
  1225. }
  1226.  
  1227. if (document.location.href.search('/forum/dl/') !== -1) {
  1228. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  1229. ';background-color:black!important');
  1230. for (itm of document.querySelectorAll('body>div')) {
  1231. if (!itm.querySelector('.dw-fdwlink')) {
  1232. remove(itm);
  1233. }
  1234. }
  1235. }
  1236.  
  1237. if (isForum) { // Do not continue if it's a forum
  1238. return;
  1239. }
  1240.  
  1241. si = document.querySelector('#header');
  1242. if (si) {
  1243. rem = si.previousSibling;
  1244. while (rem) {
  1245. si = rem.previousSibling;
  1246. remove(rem);
  1247. rem = si;
  1248. }
  1249. }
  1250.  
  1251. for (itm of document.querySelectorAll('#nav li[class]')) {
  1252. if (itm && itm.querySelector('a[href^="/tag/"]')) {
  1253. remove(itm);
  1254. }
  1255. }
  1256.  
  1257. var style, result;
  1258. for (itm of document.querySelectorAll('DIV, A')) {
  1259. if (itm.tagName ==='DIV' && itm.offsetWidth > 0.95 * width() && itm.offsetHeight > 0.85 * height()) {
  1260. style = window.getComputedStyle(itm, null);
  1261. result = [];
  1262. if (style.backgroundImage !== 'none') {
  1263. result.push('background-image:none!important');
  1264. }
  1265. if (style.backgroundColor !== 'transparent' &&
  1266. style.backgroundColor !== 'rgba(0, 0, 0, 0)') {
  1267. result.push('background-color:transparent!important');
  1268. }
  1269. if (result.length) {
  1270. if (itm.getAttribute('style')) {
  1271. result.unshift(itm.getAttribute('style'));
  1272. }
  1273. (function(){
  1274. var fakeStyle = {
  1275. 'backgroundImage': itm.style.backgroundImage,
  1276. 'backgroundColor': itm.style.backgroundColor
  1277. };
  1278. try {
  1279. Object.defineProperty(itm, 'style', {
  1280. value: new Proxy(itm.style, {
  1281. get: function(target, prop){
  1282. if (fakeStyle.hasOwnProperty(prop)) {
  1283. return fakeStyle[prop];
  1284. } else {
  1285. return target[prop];
  1286. }
  1287. },
  1288. set: function(target, prop, value){
  1289. if (fakeStyle.hasOwnProperty(prop)) {
  1290. fakeStyle[prop] = value;
  1291. } else {
  1292. target[prop] = value;
  1293. }
  1294. return value;
  1295. }
  1296. }),
  1297. enumerable: true
  1298. });
  1299. } catch (e) {
  1300. console.log('Unable to protect style property.', e);
  1301. }
  1302. })();
  1303. if (protectedElems) {
  1304. protectedElems.set(itm, {oldStyle: oGA.call(itm, 'style')});
  1305. }
  1306. oSA.call(itm, 'style', result.join(';'));
  1307. }
  1308. }
  1309. if (itm.tagName ==='A' && (itm.offsetWidth > 0.95 * width() || itm.offsetHeight > 0.85 * height())) {
  1310. if (protectedElems) {
  1311. protectedElems.set(itm, {oldStyle: oGA.call(itm, 'style')});
  1312. }
  1313. oSA.call(itm, 'style', 'display:none!important');
  1314. }
  1315. }
  1316.  
  1317. for (itm of document.querySelectorAll('ASIDE>DIV')) {
  1318. if ( ((itm.querySelector('script, iframe, a[href*="/ad/www/"]') ||
  1319. itm.querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  1320. !itm.classList.contains('post') ) || !itm.childNodes.length ) {
  1321. remove(itm);
  1322. }
  1323. }
  1324.  
  1325. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  1326.  
  1327. // display content of the page
  1328. afterClean();
  1329. });
  1330. }
  1331. };
  1332.  
  1333. scripts['allmovie.pro'] = function() {
  1334. // pretend to be Android to make site use different played for ads
  1335. if (isSafari) {
  1336. return;
  1337. }
  1338. Object.defineProperty(navigator, 'userAgent', {
  1339. get: function(){ return 'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19'; },
  1340. enumerable: true
  1341. });
  1342. };
  1343. scripts['rufilmtv.org'] = scripts['allmovie.pro'];
  1344.  
  1345. scripts['anidub-online.ru'] = function() {
  1346. var script = document.createElement('script');
  1347. script.type = "text/javascript";
  1348. script.innerHTML = "function ogonekstart1() {}";
  1349. document.getElementsByTagName('head')[0].appendChild(script);
  1350.  
  1351. var style = document.createElement('style');
  1352. style.type = 'text/css';
  1353. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  1354. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  1355. document.head.appendChild(style);
  1356. };
  1357. scripts['online.anidub.com'] = scripts['anidub-online.ru'];
  1358.  
  1359. scripts['fs.to'] = function() {
  1360. function skipClicker(i) {
  1361. if (!i) {
  1362. return;
  1363. }
  1364. var skip = document.querySelector('.b-aplayer-banners__close');
  1365. if (skip) {
  1366. skip.click();
  1367. } else {
  1368. setTimeout(skipClicker, 100, i-1);
  1369. }
  1370. }
  1371. setTimeout(skipClicker, 100, 30);
  1372.  
  1373. createStyle([
  1374. '.l-body-branding *,'+
  1375. '.b-styled__item-central,'+
  1376. '.b-styled__content-right,'+
  1377. '.b-styled__section-central,'+
  1378. 'div[id^="adsProxy-"]'+
  1379. '{display:none!important}',
  1380. 'body {background-image:url(data:image/png;base64,'+
  1381. 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACX'+
  1382. 'BIWXMAAC4jAAAuIwF4pT92AAAADUlEQVR42mOQUdL5DwACMgFq'+
  1383. 'BC3ttwAAAABJRU5ErkJggg==)!important}'
  1384. ]);
  1385.  
  1386. if (/\/(view_iframe|iframeplayer)\//i.test(document.location.pathname)) {
  1387. var p = document.querySelector('#player:not([preload="auto"])'),
  1388. m = document.querySelector('.main'),
  1389. adStepper = function(p) {
  1390. if (p.currentTime < p.duration) {
  1391. p.currentTime += 1;
  1392. }
  1393. },
  1394. adSkipper = function(f, p) {
  1395. f.click();
  1396. p.waitAfterSkip = false;
  1397. p.longerSkipper = false;
  1398. console.log('Пропустили.');
  1399. },
  1400. cl = function(p) {
  1401. var faster = document.querySelector('.b-aplayer__html5-desktop-skip'),
  1402. series = document.querySelector('.b-aplayer__actions-series');
  1403.  
  1404. function clickSelected() {
  1405. var s = document.querySelector('.b-aplayer__popup-series-episodes .selected a');
  1406. if (s) {
  1407. s.click();
  1408. }
  1409. }
  1410.  
  1411. if ((!faster || faster.style.display !== 'block') && series && !p.seriesClicked) {
  1412. series.click();
  1413. p.seriesClicked = true;
  1414. p.longerSkipper = true;
  1415. setTimeout(clickSelected, 1000);
  1416. p.pause();
  1417. }
  1418.  
  1419. function skipListener() {
  1420. if (p.waitAfterSkip) {
  1421. console.log('В процессе пропуска…');
  1422. return;
  1423. }
  1424. p.pause();
  1425. if (!p.classList.contains('m-hidden')) {
  1426. p.classList.add('m-hidden');
  1427. }
  1428. if (faster && p.currentTime &&
  1429. win.getComputedStyle(faster).display === 'block' &&
  1430. !faster.querySelector('.b-aplayer__html5-desktop-skip-timer')) {
  1431. p.waitAfterSkip = true;
  1432. setTimeout(adSkipper, (p.longerSkipper?3:1)*1000, faster, p);
  1433. console.log('Доступен быстрый пропуск…');
  1434. } else {
  1435. setTimeout(adStepper, 1000, p);
  1436. }
  1437. }
  1438.  
  1439. p.addEventListener('timeupdate', skipListener, false);
  1440. },
  1441. o = new MutationObserver(function (ms) {
  1442. var m, node;
  1443. for (m of ms) {
  1444. for (node of m.addedNodes) {
  1445. if (node.id === 'player' &&
  1446. node.nodeName === 'VIDEO' &&
  1447. node.getAttribute('preload') !== 'auto') {
  1448. cl(node);
  1449. }
  1450. }
  1451. }
  1452. });
  1453. if (p.nodeName === 'VIDEO') {
  1454. cl(p);
  1455. } else {
  1456. o.observe(m, {childList: true});
  1457. }
  1458. }
  1459. };
  1460. scripts['brb.to'] = scripts['fs.to'];
  1461. scripts['cxz.to'] = scripts['fs.to'];
  1462.  
  1463. scripts['drive2.ru'] = function() {
  1464. gardener('.c-block:not([data-metrika="recomm"]),.o-grid__item', />Реклама<\//i);
  1465. };
  1466.  
  1467. scripts['fishki.net'] = function() {
  1468. gardener('.drag_list > .drag_element, .list-view > .paddingtop15', /543769|Новости партнеров/);
  1469. };
  1470.  
  1471. scripts['gidonline.club'] = {
  1472. 'now': function() {
  1473. createStyle('.tray > div[style] {display: none!important}');
  1474. }
  1475. };
  1476. scripts['gidonlinekino.com'] = scripts['gidonline.club'];
  1477.  
  1478. scripts['hdgo.cc'] = {
  1479. 'now': function(){
  1480. var o = new MutationObserver(function(ms) {
  1481. var m, node;
  1482. for (m of ms) {
  1483. for (node of m.addedNodes) {
  1484. if (node.tagName === 'SCRIPT' && node.getAttribute('onerror') !== null) {
  1485. node.removeAttribute('onerror');
  1486. }
  1487. }
  1488. }
  1489. });
  1490. o.observe(document, {childList:true, subtree: true});
  1491. }
  1492. };
  1493. scripts['couber.be'] = scripts['hdgo.cc'];
  1494. scripts['46.30.43.38'] = scripts['hdgo.cc'];
  1495.  
  1496. scripts['gismeteo.ru'] = {
  1497. 'DOMContentLoaded': function() {
  1498. gardener('div > a[target^="_"]', /Яндекс\.Директ/i, { root: 'body', observe: true, parent: 'div[class*="frame"]' });
  1499. }
  1500. };
  1501.  
  1502. scripts['hdrezka.me'] = {
  1503. 'now': function() {
  1504. Object.defineProperty(win, 'fuckAdBlock', {
  1505. value: {
  1506. onDetected: function() {
  1507. console.log('Pretending to be an ABP detector.');
  1508. }
  1509. }
  1510. });
  1511. Object.defineProperty(win, 'ab', {
  1512. value: false,
  1513. enumerable: true
  1514. });
  1515. },
  1516. 'DOMContentLoaded': function() {
  1517. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  1518. }
  1519. };
  1520.  
  1521. scripts['imageban.ru'] = {
  1522. 'now': preventBackgroundRedirect,
  1523. 'DOMContentLoaded': function() {
  1524. win.addEventListener('unload', function() {
  1525. if (!window.location.hash) {
  1526. window.location.replace(window.location+'#');
  1527. } else {
  1528. window.location.hash = '';
  1529. }
  1530. }, true);
  1531. }
  1532. };
  1533.  
  1534. scripts['megogo.net'] = {
  1535. 'now': function() {
  1536. Object.defineProperty(win, "adBlock", {
  1537. value : false,
  1538. enumerable : true
  1539. });
  1540. Object.defineProperty(win, "showAdBlockMessage", {
  1541. value : function () {},
  1542. enumerable : true
  1543. });
  1544. }
  1545. };
  1546.  
  1547. scripts['naruto-base.su'] = function() {
  1548. gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  1549. };
  1550.  
  1551. scripts['overclockers.ru'] = {
  1552. 'now': function() {
  1553. createStyle('.fixoldhtml {display:block!important}');
  1554. if (!isChrome && !isOpera) {
  1555. return; // Looks like my code works only in Chrome-like browsers
  1556. }
  1557. var noContentYet = true;
  1558. function jWrap() {
  1559. var _$ = win.$, _e = _$.extend;
  1560. win.$ = function() {
  1561. var _ret = _$.apply(window, arguments);
  1562. if (_ret[0] === document.body) {
  1563. _ret.html = function() {
  1564. console.log('Anti-adblock prevented.');
  1565. };
  1566. }
  1567. return _ret;
  1568. };
  1569. win.$.extend = function() {
  1570. return _e.apply(_$, arguments);
  1571. };
  1572. win.jQuery = win.$;
  1573. }
  1574. (function jReady() {
  1575. if (!win.$ && noContentYet) {
  1576. setTimeout(jReady, 0);
  1577. } else {
  1578. jWrap();
  1579. }
  1580. })();
  1581. document.addEventListener ('DOMContentLoaded', function(){
  1582. noContentYet = false;
  1583. }, false);
  1584. }
  1585. };
  1586. scripts['forums.overclockers.ru'] = {
  1587. 'now': function() {
  1588. createStyle('.needblock {position: fixed; left: -10000px}');
  1589. Object.defineProperty(win, 'adblck', {
  1590. value: 'no',
  1591. enumerable: true
  1592. });
  1593. }
  1594. };
  1595.  
  1596. scripts['pb.wtf'] = function() {
  1597. createStyle('.reques,#result,tbody.row1:not([id]) {display: none !important}');
  1598. // image in the slider in the header
  1599. gardener('a[href$="=="]', /img/i, {root:'.release-navbar', observe:true, parent:'div'});
  1600. // ads in blocks on the page
  1601. gardener('a[href^="/"]', /<img\s.*<br>/i, {root:'#main_content', observe:true, parent:'div[class]'});
  1602. // line above topic content
  1603. gardener('.re_top1', /./, {root:'#main_content', parent:'.hidden-sm'});
  1604. };
  1605. scripts['piratbit.org'] = scripts['pb.wtf'];
  1606. scripts['piratbit.ru'] = scripts['pb.wtf'];
  1607.  
  1608. scripts['pesnik.su'] = {
  1609. 'now': function() {
  1610. win.Worker = function(){
  1611. console.log('Site attempted to create a WebWorker:', arguments);
  1612. return {postMessage:function(){}};
  1613. };
  1614. }
  1615. };
  1616.  
  1617. scripts['pikabu.ru'] = function() {
  1618. gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  1619. };
  1620.  
  1621. scripts['rp5.ru'] = function() {
  1622. createStyle('#bannerBottom {display: none!important}');
  1623. var co = document.querySelector('#content'), i, nodes;
  1624. if (!co) {
  1625. return;
  1626. }
  1627. nodes = co.parentNode.childNodes;
  1628. i = nodes.length;
  1629. while (i--) {
  1630. if (nodes[i] !== co) {
  1631. nodes[i].parentNode.removeChild(nodes[i]);
  1632. }
  1633. }
  1634. };
  1635. scripts['rp5.by'] = scripts['rp5.ru'];
  1636. scripts['rp5.ua'] = scripts['rp5.ru'];
  1637.  
  1638. scripts['rustorka.com'] = {
  1639. 'now': function() {
  1640. createStyle('.header > div:not(.head-block) a, #sidebar1 img, #logo img {opacity:0!important}', {
  1641. id: 'tempHidingStyles'
  1642. }, true);
  1643. preventPopups();
  1644. },
  1645. 'DOMContentLoaded': function() {
  1646. for (var o of document.querySelectorAll('IMG, A')) {
  1647. if ((o.clientWidth === 728 && o.clientHeight === 90) ||
  1648. (o.clientWidth === 300 && o.clientHeight === 250)) {
  1649. while (o && o.tagName !== 'A') {
  1650. o = o.parentNode;
  1651. }
  1652. if (o) {
  1653. o.setAttribute('style', 'display: none !important');
  1654. }
  1655. }
  1656. }
  1657. var s = document.querySelector('#tempHidingStyles');
  1658. s.parentNode.removeChild(s);
  1659. }
  1660. };
  1661. scripts['rumedia.ws'] = scripts['rustorka.com'];
  1662.  
  1663. scripts['sport-express.ru'] = function() {
  1664. gardener('.js-relap__item',/>Реклама\s+<\//, {root:'.container', observe: true});
  1665. };
  1666.  
  1667. scripts['sports.ru'] = function() {
  1668. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.aside-news-block'});
  1669. gardener('.material-list__item', /Реклама/i, {root:'.columns-layout', observe: true});
  1670. // extra functionality: shows/hides panel at the top depending on scroll direction
  1671. createStyle([
  1672. '.user-panel__fixed { transition: top 0.2s ease-in-out!important; }',
  1673. '.user-panel-up { top: -40px!important }'
  1674. ], {id: 'userPanelSlide'}, false);
  1675. (function lookForPanel() {
  1676. var panel = document.querySelector('.user-panel__fixed');
  1677. if (!panel) {
  1678. setTimeout(lookForPanel, 100);
  1679. } else {
  1680. window.addEventListener('wheel', function(e){
  1681. if (e.deltaY > 0 && !panel.classList.contains('user-panel-up')) {
  1682. panel.classList.add('user-panel-up');
  1683. } else
  1684. if (e.deltaY < 0 && panel.classList.contains('user-panel-up')) {
  1685. panel.classList.remove('user-panel-up');
  1686. }
  1687. }, false);
  1688. }
  1689. })();
  1690. };
  1691.  
  1692. scripts['www.ukr.net'] = scripts['sinoptik.com.ru'];
  1693.  
  1694. scripts['vk.com'] = function() {
  1695. gardener('div[data-post-id]', /wall_marked_as_ads/, {root: '#page_wall_posts', observe: true});
  1696. };
  1697.  
  1698. scripts['yap.ru'] = function() {
  1699. var words = /member1438|Administration/;
  1700. gardener('form > table[id^="p_row_"]', words);
  1701. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  1702. };
  1703. scripts['yaplakal.com'] = scripts['yap.ru'];
  1704.  
  1705. scripts['reactor.cc'] = {
  1706. 'now': function() {
  1707. win.open = (function(){ throw new Error('Redirect prevention.'); }).bind(window);
  1708. },
  1709. 'click': function(e) {
  1710. var node = e.target;
  1711. if (node.nodeType === Node.ELEMENT_NODE &&
  1712. node.style.position === 'absolute' &&
  1713. node.style.zIndex > 0)
  1714. node.parentNode.removeChild(node);
  1715. },
  1716. 'DOMContentLoaded': function() {
  1717. var words = new RegExp(
  1718. 'блокировщика рекламы'
  1719. .split('')
  1720. .map(function(e){return e+'[\u200b\u200c\u200d]*';})
  1721. .join('')
  1722. .replace(' ', '\\s*')
  1723. .replace(/[аоре]/g, function(e){return ['[аa]','[оo]','[рp]','[еe]']['аоре'.indexOf(e)];}),
  1724. 'i'),
  1725. can;
  1726. function deeper(spider) {
  1727. var c, l, n;
  1728. if (words.test(spider.innerText)) {
  1729. if (spider.nodeType === Node.TEXT_NODE) {
  1730. return true;
  1731. }
  1732. c = spider.childNodes;
  1733. l = c.length;
  1734. n = 0;
  1735. while(l--) {
  1736. if (deeper(c[l]), can) {
  1737. n++;
  1738. }
  1739. }
  1740. if (n > 0 && n === c.length && spider.offsetHeight < 750) {
  1741. can.push(spider);
  1742. }
  1743. return false;
  1744. }
  1745. return true;
  1746. }
  1747. function probe(){
  1748. if (words.test(document.body.innerText)) {
  1749. can = [];
  1750. deeper(document.body);
  1751. var i = can.length, j, spider;
  1752. while(i--) {
  1753. spider = can[i];
  1754. if (spider.offsetHeight > 10 && spider.offsetHeight < 750) {
  1755. spider.setAttribute('style', 'background:none!important');
  1756. }
  1757. }
  1758. }
  1759. }
  1760. var o = new MutationObserver(probe);
  1761. o.observe(document,{childList:true, subtree:true});
  1762. }
  1763. };
  1764. scripts['joyreactor.cc'] = scripts['reactor.cc'];
  1765. scripts['pornreactor.cc'] = scripts['reactor.cc'];
  1766.  
  1767. scripts['auto.ru'] = function() {
  1768. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  1769. var userAdsListAds = [
  1770. '.listing-list > .listing-item',
  1771. '.listing-item_type_fixed.listing-item'
  1772. ];
  1773. var catalogAds = [
  1774. 'div[class*="layout_catalog-inline"]',
  1775. 'div[class$="layout_horizontal"]'
  1776. ];
  1777. var otherAds = [
  1778. '.advt_auto',
  1779. '.sidebar-block',
  1780. '.pager-listing + div[class]',
  1781. '.card > div[class][style]',
  1782. '.sidebar > div[class]',
  1783. '.main-page__section + div[class]',
  1784. '.listing > tbody'];
  1785. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', observe:true});
  1786. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', observe:true});
  1787. gardener(otherAds.join(','), words);
  1788. };
  1789.  
  1790. scripts['rsload.net'] = {
  1791. 'load': function() {
  1792. var dis = document.querySelector('.cb-disabless');
  1793. if (dis) {
  1794. dis.click();
  1795. }
  1796. },
  1797. 'click': function(e) {
  1798. var t = e.target;
  1799. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href))) {
  1800. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  1801. }
  1802. }
  1803. };
  1804.  
  1805. var domain = document.domain, name;
  1806. while (domain.indexOf('.') !== -1) {
  1807. if (scripts.hasOwnProperty(domain)) {
  1808. if (typeof scripts[domain] === 'function') {
  1809. document.addEventListener ('DOMContentLoaded', scripts[domain], false);
  1810. }
  1811. for (name in scripts[domain]) {
  1812. if (name !== 'now') {
  1813. (name === 'load' ? window : document)
  1814. .addEventListener (name, scripts[domain][name], false);
  1815. } else {
  1816. scripts[domain][name]();
  1817. }
  1818. }
  1819. }
  1820. domain = domain.slice(domain.indexOf('.') + 1);
  1821. }
  1822. })();