RU AdList JS Fixes

try to take over the world!

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

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