RU AdList JS Fixes

try to take over the world!

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

  1. // ==UserScript==
  2. // @name RU AdList JS Fixes
  3. // @namespace ruadlist_js_fixes
  4. // @version 1.3.17
  5. // @description try to take over the world!
  6. // @author lainverse & dimisa
  7. // @match *://*/*
  8. // @grant unsafeWindow
  9. // @grant window.close
  10. // @grant GM_addStyle
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. var win = unsafeWindow || window;
  17. function inIFrame() {
  18. try {
  19. return win.self !== win.top;
  20. } catch (ignore) {
  21. return true;
  22. }
  23. }
  24.  
  25. // https://greasyfork.org/scripts/19144-websuckit/
  26. (function() {
  27. var scriptText = '';
  28.  
  29. function WebSocketWrapper() {
  30. // check if the browser supports Proxy and WebSocket
  31. if (typeof Proxy !== 'function' ||
  32. typeof WebSocket !== 'function') {
  33. return;
  34. }
  35. var to_block = [
  36. '||24video.xxx',
  37. '||adlabs.ru',
  38. '||bgrndi.com^',
  39. '||brokeloy.com^',
  40. '||dreadfula.ru^',
  41. '||et-code.ru^',
  42. '||free-torrent.org^',
  43. '||free-torrent.pw^',
  44. '||free-torrents.org^',
  45. '||free-torrents.pw^',
  46. '||game-torrent.info^',
  47. '||gocdn.ru^',
  48. '||hghit.com^',
  49. '||kinotochka.net^',
  50. '||kuveres.com^',
  51. '||lepubs.com^',
  52. '||luxup.ru^',
  53. '||mail.ru^',
  54. '||marketgid.com^',
  55. '||mxtads.com^',
  56. '||oconner.biz^',
  57. '||poolnoodle.tech',
  58. '||psma01.com^',
  59. '||psma02.com^',
  60. '||psma03.com^',
  61. '||recreativ.ru^',
  62. '||regpole.com^',
  63. '||skidl.ru^',
  64. '||torvind.com^',
  65. '||trafmag.com^',
  66. '||xxuhter.ru^',
  67. '||yuiout.online^'
  68. ];
  69. var masks = [];
  70. to_block.forEach(function(m){
  71. masks.push(new RegExp(
  72. m.replace(/([\\\/\[\].*+?(){}$])/g, '\\$1')
  73. .replace(/\^(?!$)/g,'\\.?[^\\w%._-]')
  74. .replace(/\^$/,'\\.?([^\\w%._-]|$)')
  75. .replace(/^\|\|/,'^wss?:\\/+([^\/.]+\\.)*'),
  76. 'i'));
  77. });
  78. var realWS = win.WebSocket,
  79. closingFunctions = ['close', 'send'];
  80. function wsGetter(tgt, nm) {
  81. console.log('[WSI] Registered call to property "', nm, '"');
  82. try {
  83. if (typeof realWS.prototype[nm] === 'function') {
  84. if (closingFunctions.indexOf(nm) > -1) {
  85. tgt.readyState = realWS.CLOSED;
  86. }
  87. return function(){return;};
  88. }
  89. if (typeof realWS.prototype[nm] === 'number') {
  90. return realWS[nm];
  91. }
  92. } catch(ignore) {}
  93. return tgt[nm];
  94. }
  95. var _WebSocket = (new Proxy(realWS, {
  96. construct: function(target, args) {
  97. var url = args[0];
  98. console.log('[WSI] Opening socket on', url, '\u2026');
  99. var i = masks.length;
  100. while(i--) {
  101. if (masks[i].test(url)) {
  102. console.log("[WSI] Blocked.");
  103. return new Proxy({url: url, readyState: realWS.OPEN}, {
  104. get: wsGetter
  105. });
  106. }
  107. }
  108. return new target(args[0], args[1]);
  109. }
  110. }));
  111. win.WebSocket = _WebSocket.bind(win);
  112. }
  113.  
  114. function WorkerWrapper(){
  115. var wr = win.Worker;
  116. function Worker(resourceURI) {
  117. var _promise = new Promise(function(resolve,reject){
  118. var xhrLoadEnd = function() {
  119. resolve(new wr(URL.createObjectURL(
  120. new Blob(['(function(){var win = self;'+
  121. WebSocketWrapper.toString()+
  122. ' WebSocketWrapper();})();'+this.result])
  123. )));
  124. };
  125. var xhr = new XMLHttpRequest();
  126. xhr.open('GET', resourceURI, true);
  127. xhr.responseType = 'blob';
  128. xhr.onload = function(){
  129. if (this.status === 200) {
  130. var reader = new FileReader();
  131. reader.addEventListener("loadend", xhrLoadEnd);
  132. reader.readAsText(this.response);
  133. }
  134. };
  135. xhr.send();
  136. });
  137. var _worker = null,
  138. _terminate = false,
  139. _onerror = null,
  140. _onmessage = null,
  141. _messages = [],
  142. _events = [];
  143. var setWorker = function(val) {
  144. _worker = val;
  145. _worker.onerror = _onerror;
  146. _worker.onmessage = _onmessage;
  147. var _e;
  148. while(_events.length) {
  149. _e = _events.shift();
  150. _worker[_e[0]].apply(_worker, _e[1]);
  151. }
  152. while(_messages.length) {
  153. _worker.postMessage(_messages.shift());
  154. }
  155. if (_terminate) {
  156. _worker.terminate();
  157. }
  158. };
  159. _promise.then(setWorker);
  160. this.terminate = function(){
  161. _terminate = true;
  162. if (_worker) {
  163. _worker.terminate();
  164. }
  165. };
  166. Object.defineProperty(this, 'onmessage', {
  167. get:function(){
  168. return _onmessage;
  169. },
  170. set:function(val){
  171. _onmessage = val;
  172. if (_worker) {
  173. _worker.onmessage = val;
  174. }
  175. }
  176. });
  177. Object.defineProperty(this, 'onerror', {
  178. get:function(){
  179. return _onerror;
  180. },
  181. set:function(val){
  182. _onerror = val;
  183. if (_worker) {
  184. _worker.onmessage = val;
  185. }
  186. }
  187. });
  188. this.postMessage = function(message){
  189. if (_worker) {
  190. _worker.postMessage(message);
  191. } else {
  192. _messages.push(message);
  193. }
  194. };
  195. this.terminate = function() {
  196. _terminate = true;
  197. if (_worker) {
  198. _worker.terminate();
  199. }
  200. };
  201. this.addEventListener = function(){
  202. if (_worker) {
  203. _worker.addEventListener.apply(_worker, arguments);
  204. } else {
  205. _events.push(['addEventListener',arguments]);
  206. }
  207. };
  208. this.removeEventListener = function(){
  209. if (_worker) {
  210. _worker.removeEventListener.apply(_worker, arguments);
  211. } else {
  212. _events.push(['removeEventListener',arguments]);
  213. }
  214. };
  215. }
  216. win.Worker = Worker.bind(window);
  217. }
  218.  
  219. function CreateElementWrapper() {
  220. var _ce = document.createElement.bind(document),
  221. dataText = /^data:text/i,
  222. key = '"'+Math.random().toString(36).substr(2)+'";',
  223. eskey = escape(key);
  224. function frameRewrite(e) {
  225. var f = e.target;
  226. if(dataText.test(f.src) && f.src.indexOf(eskey) < 0) {
  227. f.src = f.src.replace(',',','+escape('<scr'+'ipt>'+key+scriptText+'</scr'+'ipt>'));
  228. }
  229. }
  230. function createElement(name) {
  231. if (name && name.toUpperCase &&
  232. name.toUpperCase() === 'IFRAME') {
  233. var ifr = _ce.apply(document, arguments);
  234. ifr.addEventListener('load', frameRewrite, false);
  235. return ifr;
  236. }
  237. return _ce.apply(document, arguments);
  238. }
  239. document.createElement = createElement.bind(document);
  240. }
  241.  
  242. function GenerateScriptText() {
  243. scriptText = '(function(){var win = self||window, scriptText = "";'+
  244. WebSocketWrapper.toString()+
  245. WorkerWrapper.toString()+
  246. CreateElementWrapper.toString()+
  247. GenerateScriptText.toString()+
  248. 'GenerateScriptText();'+
  249. 'WebSocketWrapper();'+
  250. 'WorkerWrapper();'+
  251. 'CreateElementWrapper();'+
  252. '})();'+
  253. 'var s = document.currentScript; if (s) {s.parentNode.removeChild(s);}';
  254. }
  255.  
  256. GenerateScriptText();
  257. scriptText = scriptText.replace(/\/\/[^\r\n]*/g,'').replace(/[\s\r\n]+/g,' ');
  258.  
  259. if (/firefox/i.test(navigator.userAgent)) {
  260. var script = document.createElement('script');
  261. script.appendChild(document.createTextNode(scriptText));
  262. document.head.insertBefore(script,document.head.firstChild);
  263. return; //we don't want to call functions on page from here in Fx, so exit
  264. }
  265.  
  266. WebSocketWrapper();
  267. WorkerWrapper();
  268. CreateElementWrapper();
  269. })();
  270.  
  271. if (!(/firefox/i.test(navigator.userAgent))) { // scripts for non-Firefox browsers
  272.  
  273. // https://greasyfork.org/scripts/14720-it-s-not-important
  274. (function(){
  275. var imptt = /((display|(margin|padding)(-top|-bottom)?)\s*:[^;!]*)!\s*important/ig;
  276.  
  277. function unimportanter(el, si) {
  278. if (!imptt.test(si) || el.style.display === 'none') {
  279. return 0; // get out if we have nothing to do here
  280. }
  281. if (el.nodeName === 'IFRAME' && el.src &&
  282. el.src.slice(0,17) === 'chrome-extension:') {
  283. return 0; // Web of Trust uses this method to add their frame
  284. }
  285. var so = si.replace(imptt, function(){return arguments[1];}), ret = 0;
  286. if (si !== so) {
  287. ret = 1;
  288. el.setAttribute('style', so);
  289. }
  290. return ret;
  291. }
  292.  
  293. function logger(c) {
  294. if (c) {
  295. console.log('Some page elements became a bit less important.');
  296. }
  297. }
  298.  
  299. function checkTarget(m, c) {
  300. var si = m.getAttribute ? m.getAttribute('style') : null;
  301. if (si && si.indexOf('!') > -1) {
  302. c += unimportanter(m, si);
  303. }
  304. return c;
  305. }
  306.  
  307. function checkNodes(m, c) {
  308. var i = m.length;
  309. while(i--) {
  310. c = checkTarget(m[i], c);
  311. }
  312. return c;
  313. }
  314.  
  315. var observer = new MutationObserver(function(mutations) {
  316. setTimeout(function(m) {
  317. var i = m.length, c = 0;
  318. while(i--) {
  319. if (m[i].target) {
  320. c = checkTarget(m[i].target, c);
  321. }
  322. if (m[i].addedNodes.length) {
  323. c = checkNodes(m[i].addedNodes, c);
  324. }
  325. }
  326. logger(c);
  327. },0,mutations);
  328. });
  329.  
  330. observer.observe(document, { childList : true, attributes : true, attributeFilter : ['style'], subtree : true });
  331.  
  332. win.addEventListener ("load", function(){
  333. var c = 0, imp = document.querySelectorAll('[style*="!"]'), i = imp.length;
  334. while(i--) {
  335. c+= checkTarget(imp[i], c);
  336. }
  337. logger(c);
  338. }, false);
  339. })();
  340.  
  341. }
  342.  
  343. if (/^https?:\/\/(news\.yandex\.|(www\.)?yandex\.[^\/]+\/(yand)?search[\/?])/i.test(win.location.href)) {
  344. // https://greasyfork.org/en/scripts/809-no-yandex-ads
  345. (function(){
  346. var adWords = ['Яндекс.Директ','Реклама','Ad'];
  347. function remove(node) {
  348. node.parentNode.removeChild(node);
  349. }
  350. // Generic ads removal and fixes
  351. function removeGenericAds() {
  352. var s, i;
  353. s = document.querySelector('.serp-header');
  354. if (s) {
  355. s.style.marginTop='0';
  356. }
  357. s = document.querySelectorAll('.serp-adv__head + .serp-item');
  358. i = s.length;
  359. while(i--) {
  360. s[i].parentNode.removeChild(s[i]);
  361. }
  362. s = document.querySelectorAll('#adbanner, .serp-adv, .b-spec-adv, div[class*="serp-adv__"]');
  363. i = s.length;
  364. while(i--) {
  365. remove(s[i]);
  366. }
  367. }
  368. // Search ads
  369. function removeSearchAds() {
  370. var s = document.querySelectorAll('.serp-block, .serp-item, .search-item');
  371. var i = s.length, item;
  372. while(i--) {
  373. item = s[i].querySelector('.label, .serp-item__label, .document__provider-name');
  374. if (item && adWords.indexOf(item.textContent) > -1) {
  375. remove(s[i]);
  376. console.log('Ads removed.');
  377. }
  378. }
  379. }
  380. // News ads
  381. function removeNewsAds() {
  382. var s = document.querySelectorAll('.page-content__left > *,.page-content__right > *:not(.page-content__col),.page-content__right > .page-content__col > *');
  383. var i = s.length;
  384. while(i--) {
  385. if (s[i].textContent.indexOf(adWords[0]) > -1) {
  386. remove(s[i]);
  387. console.log('Ads removed.');
  388. }
  389. }
  390. }
  391. // News fixes
  392. function removePageAdsClass() {
  393. if (document.body.classList.contains("b-page_ads_yes")){
  394. document.body.classList.remove("b-page_ads_yes");
  395. console.log('Page ads class removed.');
  396. }
  397. }
  398. // Function to attach an observer to monitor dynamic changes on the page
  399. function pageUpdateObserver(func, obj, params) {
  400. if (obj) {
  401. var o = new MutationObserver(func);
  402. o.observe(obj,(params || {childList:true, subtree:true}));
  403. }
  404. }
  405. // Cleaner
  406. document.addEventListener ("DOMContentLoaded", function() {
  407. removeGenericAds();
  408. if (win.location.hostname.search(/^news\./i) === 0) {
  409. pageUpdateObserver(removeNewsAds, document.querySelector('BODY'));
  410. pageUpdateObserver(removePageAdsClass, document.body, {attributes:true, attributesFilter:['class']});
  411. removeNewsAds();
  412. removePageAdsClass();
  413. } else {
  414. pageUpdateObserver(removeSearchAds, document.querySelector('.main__content'));
  415. removeSearchAds();
  416. }
  417. });
  418. })();
  419. return; //skip fixes for other sites
  420. }
  421.  
  422. // https://greasyfork.org/en/scripts/14470-4pda-unbrender
  423. if (/(^|\.)4pda\.ru$/i.test(window.location.hostname)) {
  424. (function(){
  425. var isForum = document.location.href.search('/forum/') !== -1,
  426. isSafari = (/Safari/i.test(navigator.userAgent)) && (/Apple\sComputer/i.test(navigator.vendor)),
  427. hStyle;
  428.  
  429. function remove(n) {
  430. if (n) {
  431. n.parentNode.removeChild(n);
  432. }
  433. }
  434.  
  435. function afterClean() {
  436. hStyle.disabled = true;
  437. remove(hStyle);
  438. }
  439.  
  440. function beforeClean() {
  441. // attach styles before document displayed
  442. hStyle = document.createElement('style');
  443. hStyle.id = 'ubrHider';
  444. hStyle.type = 'text/css';
  445. document.head.appendChild(hStyle);
  446.  
  447. hStyle.sheet.insertRule('html { overflow-y: scroll }', 0);
  448. hStyle.sheet.insertRule('article + aside * { display: none !important }', 0);
  449. hStyle.sheet.insertRule('#header + div:after {'+(
  450. 'content: "";'+
  451. 'position: fixed;'+
  452. 'top: 0;'+
  453. 'left: 0;'+
  454. 'width: 100%;'+
  455. 'height: 100%;'+
  456. 'background-color: #E6E7E9'
  457. )+'}', 0);
  458. // http://codepen.io/Beaugust/pen/DByiE
  459. hStyle.sheet.insertRule('@keyframes spin { 100% { transform: rotate(360deg) } }', 0);
  460. hStyle.sheet.insertRule('article + aside:after {'+(
  461. 'content: "";'+
  462. 'position: absolute;'+
  463. 'width: 150px;'+
  464. 'height: 150px;'+
  465. 'top: 150px;'+
  466. 'left: 50%;'+
  467. 'margin-top: -75px;'+
  468. 'margin-left: -75px;'+
  469. 'box-sizing: border-box;'+
  470. 'border-radius: 100%;'+
  471. 'border: 10px solid rgba(0, 0, 0, 0.2);'+
  472. 'border-top-color: rgba(0, 0, 0, 0.6);'+
  473. 'animation: spin 2s infinite linear'
  474. )+'}', 0);
  475.  
  476. // display content of a page if time to load a page is more than 2 seconds to avoid
  477. // blocking access to a page if it is loading for too long or stuck in a loading state
  478. setTimeout(2000, afterClean);
  479. }
  480.  
  481. GM_addStyle('#nav .use-ad {display: block !important;} ' +
  482. 'article:not(.post) + article:not(#id) { display: none !important }');
  483. if (!isForum && !isSafari) {
  484. beforeClean();
  485. }
  486.  
  487. // clean the page
  488. window.addEventListener('DOMContentLoaded', function(){
  489. var rem, si, lst, i;
  490. function width(){ return window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0; }
  491. function height(){ return window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0; }
  492.  
  493.  
  494. if (isForum) {
  495. si = document.querySelector('#logostrip');
  496. if (si) {
  497. remove(si.parentNode.nextSibling);
  498. }
  499. }
  500.  
  501. if (document.location.href.search('/forum/dl/') !== -1) {
  502. lst = document.querySelectorAll('body>div');
  503. i = lst.length;
  504. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+
  505. ';background-color:black!important');
  506. while (i--) {
  507. if (!lst[i].querySelector('.dw-fdwlink')) {
  508. remove(lst[i]);
  509. }
  510. }
  511. }
  512.  
  513. if (isForum) { // Do not continue if it's a forum
  514. return;
  515. }
  516.  
  517. si = document.querySelector('#header');
  518. if (si) {
  519. rem = si.previousSibling;
  520. while (rem) {
  521. si = rem.previousSibling;
  522. remove(rem);
  523. rem = si;
  524. }
  525. }
  526.  
  527. lst = document.querySelectorAll('#nav li[class]');
  528. i = lst.length;
  529. while (i--) {
  530. if (lst[i] && lst[i].querySelector('a[href^="/tag/"]')) {
  531. remove(lst[i]);
  532. }
  533. }
  534.  
  535. lst = document.querySelectorAll('DIV');
  536. i = lst.length;
  537. var style, result;
  538. while (i--) {
  539. if (lst[i].offsetWidth > 0.95 * width() && lst[i].offsetHeight > 0.9 * height()) {
  540. style = window.getComputedStyle(lst[i], null);
  541. result = [];
  542. if(style.backgroundImage !== 'none') {
  543. result.push('background-image:none!important');
  544. }
  545. if(style.backgroundColor !== 'transparent') {
  546. result.push('background-color:transparent!important');
  547. }
  548. if (result.length) {
  549. if (lst[i].getAttribute('style')) {
  550. result.unshift(lst[i].getAttribute('style'));
  551. }
  552. lst[i].setAttribute('style', result.join(';'));
  553. }
  554. }
  555. }
  556.  
  557. lst = document.querySelectorAll('ASIDE>DIV');
  558. i = lst.length;
  559. while (i--) {
  560. if ( ((lst[i].querySelector('script, iframe, a[href*="/ad/www/"]') ||
  561. lst[i].querySelector('img[src$=".gif"]:not([height="0"]), img[height="400"]')) &&
  562. !lst[i].classList.contains('post') ) || !lst[i].childNodes.length ) {
  563. remove(lst[i]);
  564. }
  565. }
  566.  
  567. document.body.setAttribute('style', (document.body.getAttribute('style')||'')+';background-color:#E6E7E9!important');
  568.  
  569. // display content of the page
  570. afterClean();
  571. });
  572. })();
  573. return;
  574. }
  575.  
  576. // moonwalk.cc/hdgo.cc/couber.be/kodik.cc skip/fix
  577. // based on // https://greasyfork.org/en/scripts/21937-moonwalk-hdgo-kodik-fix
  578. (function(){
  579. if (!inIFrame()) {
  580. return;
  581. }
  582. // MoonWalk.cc/Kodik.cc
  583. document.addEventListener ("DOMContentLoaded",function() {
  584. var player;
  585. if (win.banner_second !== undefined) {
  586. win.banner_second = 0;
  587. player = document.getElementById('play-player-hd');
  588. if (player) {
  589. player.onclick = function() {
  590. player = document.getElementById("ads-player-hd");
  591. player.parentNode.removeChild(player);
  592. win.setPlayer();
  593. };
  594. }
  595. }
  596. if (win.MXoverrollCallback !== undefined) {
  597. player = document.getElementsByClassName('play_button')[0];
  598. if (player) {
  599. player.onclick = win.MXoverrollCallback.bind(window);
  600. }
  601. }
  602. if (win.condition_detected !== undefined) {
  603. win.request_host_id = "19804";
  604. player = document.getElementById('player');
  605. if (player) {
  606. player.onclick = function(){
  607. win.showVideo();
  608. };
  609. }
  610. }
  611. },false);
  612. // HDgo.cc/Couber.be
  613. var hdgoDomains = ['couber.be','hdgo.cc','46.30.43.38'];
  614. if (hdgoDomains.indexOf(document.domain) > -1) {
  615. Object.defineProperty(win, 'canRunAds', {
  616. value: true,
  617. configurable: false,
  618. enumerable: false,
  619. writable: false
  620. });
  621. Object.defineProperty(win, 'swtf1', {
  622. value: function(){},
  623. configurable: false,
  624. enumerable: false,
  625. writable: false
  626. });
  627. }
  628. })();
  629.  
  630. document.addEventListener ("DOMContentLoaded", function() {
  631. // function to search and remove nodes by content
  632. // selector - standard CSS selector to define set of nodes to check
  633. // words - regular expression to check content of the suspicious nodes
  634. // params - object with multiple extra parameters:
  635. // .hide - set display to none instead of removing from the page
  636. // .parent - parent node to remove if content is found in the child node
  637. // .siblings - number of simling nodes to remove (excluding text nodes)
  638. function scRemove(e) {e.parentNode.removeChild(e);}
  639. function scHide(e) {e.style.display='none';}
  640. function scissors (selector, words, scope, params) {
  641. var remFunc = (params.hide ? scHide : scRemove),
  642. iterFunc = (params.siblings > 0 ?
  643. 'nextSibling' :
  644. 'previousSibling'),
  645. nodes = scope.querySelectorAll(selector),
  646. i = nodes.length,
  647. toRemove = [],
  648. siblings,
  649. node;
  650. while(i--) {
  651. node = nodes[i];
  652. if (words.test(node.innerHTML) || !node.childNodes.length) {
  653. // drill up to the specified parent node if required
  654. if (params.parent) {
  655. while(node !== scope && !(node.matches(params.parent))) {
  656. node = node.parentNode;
  657. }
  658. }
  659. if (node === scope) {
  660. break;
  661. }
  662. toRemove.push(node);
  663. // add multiple nodes if defined more than one sibling
  664. siblings = Math.abs(params.siblings) || 0;
  665. while (siblings) {
  666. node = node[iterFunc];
  667. toRemove.push(node);
  668. if (node.nodeType === 1) {
  669. siblings -= 1; //count only element nodes
  670. }
  671. }
  672. }
  673. }
  674. i = toRemove.length;
  675. while(i--) {
  676. remFunc(toRemove[i]);
  677. }
  678.  
  679. return toRemove.length;
  680. }
  681.  
  682. // function to perform multiple checks if ads inserted with a delay
  683. // by default does 30 checks withing a 3 seconds unless nonstop mode specified
  684. // also does 1 extra check when a page completely loads
  685. // selector and words - passed dow to scissors
  686. // params - object with multiple extra parameters:
  687. // .root - selector to narrow down scope to scan;
  688. // .observe - if true then check will be performed continuously;
  689. // Other parameters passed down to scissors.
  690. function gardener(selector, words, params) {
  691. params = params || {};
  692. var scope = document.body,
  693. nonstop = false;
  694. // narrow down scope to a specific element
  695. if (params.root) {
  696. scope = scope.querySelector(params.root);
  697. if (!scope) {// exit if the root element is not present on the page
  698. return 0;
  699. }
  700. }
  701. // add observe mode if required
  702. if (params.observe) {
  703. if (typeof MutationObserver === 'function') {
  704. var o = new MutationObserver(function(ms){
  705. ms.forEach(function(m){
  706. if (m.addedNodes.length) {
  707. scissors(selector, words, scope, params);
  708. }
  709. });
  710. });
  711. o.observe(scope, {childList:true, subtree: true});
  712. } else {
  713. nonstop = true;
  714. }
  715. }
  716. // wait for a full page load to do one extra cut
  717. win.addEventListener('load',function(){
  718. scissors(selector, words, scope, params);
  719. });
  720. // do multiple cuts until ads removed
  721. function cut(sci, s, w, sc, p, i) {
  722. if (i > 0) {
  723. i -= 1;
  724. }
  725. if (i && !sci(s, w, sc, p)) {
  726. setTimeout(cut, 100, sci, s, w, sc, p, i);
  727. }
  728. }
  729. cut(scissors, selector, words, scope, params, (nonstop ? -1 : 30));
  730. }
  731.  
  732. function preventBackgroundRedirect() {
  733. console.log("Background redirect prevention enabled.");
  734. var orgOpen = win.open;
  735. win.open = function(){
  736. var loc = arguments[0];
  737. if (loc.indexOf(win.location.host) > -1 ||
  738. loc.indexOf('://') === -1) {
  739. win.addEventListener('unload',function(){
  740. win.close();
  741. }, true);
  742. }
  743. orgOpen.apply(window, arguments);
  744. };
  745. }
  746.  
  747. var scripts = {};
  748. scripts['fs.to'] = function() {
  749. function skipClicker(i) {
  750. if (!i) {
  751. return;
  752. }
  753. var skip = document.querySelector('.b-aplayer-banners__close');
  754. if (skip) {
  755. skip.click();
  756. } else {
  757. setTimeout(skipClicker, 100, i-1);
  758. }
  759. }
  760. setTimeout(skipClicker, 100, 30);
  761.  
  762. (function(){
  763. var divs = document.getElementsByTagName('div'),
  764. re = /^b-[a-z]+\d+[a-z\d]*\s*$/,
  765. i = divs.length;
  766. while(i--) {
  767. if (re.test(divs[i].className)) {
  768. divs[i].style.display = 'none';
  769. }
  770. }
  771. })();
  772.  
  773. GM_addStyle('.b-aplayer-teasers > a, div[class^="b-adproxy"], div[id^="admixer_async_"],'+
  774. '.b-player-popup__content > div[class][style="position: relative;"]'+
  775. '{display:none!important}');
  776.  
  777. if (/\/(view_iframe|iframeplayer)\//i.test(document.location.pathname)) {
  778. var p = document.querySelector('#player:not([preload="auto"])'),
  779. m = document.querySelector('.main'),
  780. adStepper = function(p) {
  781. if (p.currentTime < p.duration) {
  782. p.currentTime += 1;
  783. }
  784. },
  785. adSkipper = function(f, p) {
  786. f.click();
  787. p.waitAfterSkip = false;
  788. p.longerSkipper = false;
  789. console.log('Пропустили.');
  790. },
  791. cl = function(p) {
  792. var faster = document.querySelector('.b-aplayer__html5-desktop-skip'),
  793. series = document.querySelector('.b-aplayer__actions-series');
  794.  
  795. function clickSelected() {
  796. var s = document.querySelector('.b-aplayer__popup-series-episodes .selected a');
  797. if (s) {
  798. s.click();
  799. }
  800. }
  801.  
  802. if ((!faster || faster.style.display !== 'block') && series && !p.seriesClicked) {
  803. series.click();
  804. p.seriesClicked = true;
  805. p.longerSkipper = true;
  806. setTimeout(clickSelected, 1000);
  807. p.pause();
  808. }
  809.  
  810. function skipListener() {
  811. if (p.waitAfterSkip) {
  812. console.log('В процессе пропуска…');
  813. return;
  814. }
  815. p.pause();
  816. if (!p.classList.contains('m-hidden')) {
  817. p.classList.add('m-hidden');
  818. }
  819. if (faster && p.currentTime &&
  820. win.getComputedStyle(faster).display === 'block' &&
  821. !faster.querySelector('.b-aplayer__html5-desktop-skip-timer')) {
  822. p.waitAfterSkip = true;
  823. setTimeout(adSkipper, (p.longerSkipper?3:1)*1000, faster, p);
  824. console.log('Доступен быстрый пропуск…');
  825. } else {
  826. setTimeout(adStepper, 1000, p);
  827. }
  828. }
  829.  
  830. p.addEventListener('timeupdate', skipListener, false);
  831. },
  832. o = new MutationObserver(function (mut) {
  833. mut.forEach(function (e) {
  834. var i = e.addedNodes.length;
  835. while(i--) {
  836. if (e.addedNodes[i].id === 'player' &&
  837. e.addedNodes[i].nodeName === 'VIDEO' &&
  838. e.addedNodes[i].getAttribute('preload') !== 'auto') {
  839. cl(e.addedNodes[i]);
  840. }
  841. }
  842. });
  843. });
  844. if (p.nodeName === 'VIDEO') {
  845. cl(p);
  846. } else {
  847. o.observe(m, {childList: true});
  848. }
  849. }
  850. };
  851. scripts['brb.to'] = scripts['fs.to'];
  852. scripts['cxz.to'] = scripts['fs.to'];
  853.  
  854. scripts['drive2.ru'] = function() {
  855. gardener('.c-block', />Реклама<\/|\.relap\..*display:\s?none/i);
  856. };
  857.  
  858. scripts['fishki.net'] = function() {
  859. gardener('.main-post', /543769|Реклама/);
  860. };
  861.  
  862. scripts['hdrezka.me'] = function() {
  863. gardener('div[id][onclick][onmouseup][onmousedown]', /onmouseout/i);
  864. };
  865.  
  866. scripts['naruto-base.su'] = function() {
  867. gardener('div[id^="entryID"],.block', /href="http.*?target="_blank"/i);
  868. };
  869.  
  870. scripts['pb.wtf'] = function() {
  871. GM_addStyle('#result,tbody.row1:not([id]) {display: none !important}');
  872. gardener('a[href$="=="]', /img/i, {root:'#page_container .containe', observe:true, parent:'div[class]'});
  873. gardener('a[href^="/"]', /<img\s.*<br>/i, {root:'#main_content', observe:true, parent:'div[class]'});
  874. gardener('.re_top1', /./, {root:'#main_content', parent:'table.border'});
  875. };
  876. scripts['piratbit.org'] = scripts['pb.wtf'];
  877. scripts['piratbit.ru'] = scripts['pb.wtf'];
  878.  
  879. scripts['pikabu.ru'] = function() {
  880. gardener('.story', /story__sponsor|story__gag|profile\/ads"/i, {root: '.inner_wrap', observe: true});
  881. };
  882.  
  883. scripts['rustorka.com'] = function() {
  884. var s = document.head.childNodes, i = s.length;
  885. if (i < 5) {
  886. while(i--) {
  887. if (s[i].httpEquiv && s[i].httpEquiv === 'refresh') {
  888. win.close();
  889. }
  890. }
  891. }
  892. gardener('span[class],ul[class],span[id],ul[id]', /\/\d{12,}\.php/i, {root:'#sidebar1', observe:true});
  893. gardener('div[id][style*="!important"]', /!important/i);
  894. };
  895. scripts['rumedia.ws'] = scripts['rustorka.com'];
  896.  
  897. scripts['sports.ru'] = function() {
  898. gardener('.aside-news-list__item', /aside-news-list__advert/i, {root:'.aside-news-block'});
  899. };
  900.  
  901. scripts['yap.ru'] = function() {
  902. var words = /member1438|Administration/;
  903. gardener('form > table[id^="p_row_"]', words);
  904. gardener('tr > .holder.newsbottom', words, {parent:'tr', siblings:-2});
  905. };
  906. scripts['yaplakal.com'] = scripts['yap.ru'];
  907.  
  908. scripts['reactor.cc'] = function() {
  909. preventBackgroundRedirect();
  910. gardener('a[href="/donate"],a[href^="/"][href*="%"]', /100/i, {parent:'#post_list>*,#content,#sidebar', root:'#pageinner', observe:true});
  911. };
  912. scripts['joyreactor.cc'] = scripts['reactor.cc'];
  913. scripts['pornreactor.cc'] = scripts['reactor.cc'];
  914.  
  915. scripts['auto.ru'] = function() {
  916. var words = /Реклама|Яндекс.Директ|yandex_ad_/;
  917. var userAdsListAds = [
  918. '.listing-list > .listing-item',
  919. '.listing-item_type_fixed.listing-item'
  920. ];
  921. var catalogAds = [
  922. 'div[class*="layout_catalog-inline"]',
  923. 'div[class$="layout_horizontal"]'
  924. ];
  925. var otherAds = [
  926. '.advt_auto',
  927. '.sidebar-block',
  928. '.pager-listing + div[class]',
  929. '.card > div[class][style]',
  930. '.sidebar > div[class]',
  931. '.main-page__section + div[class]',
  932. '.listing > tbody'];
  933. gardener(userAdsListAds.join(','), words, {root:'.listing-wrap', observe:true});
  934. gardener(catalogAds.join(','), words, {root:'.catalog__page,.content__wrapper', observe:true});
  935. gardener(otherAds.join(','), words);
  936. };
  937.  
  938. scripts['online.anidub.com'] = function() {
  939. var script = document.createElement('script');
  940. script.type = "text/javascript";
  941. script.innerHTML = "function ogonekstart1() {}";
  942. document.getElementsByTagName('head')[0].appendChild(script);
  943.  
  944. var style = document.createElement('style');
  945. style.type = 'text/css';
  946. style.appendChild(document.createTextNode('.background {background: none!important;}'));
  947. style.appendChild(document.createTextNode('.background > script + div, .background > script ~ div:not([id]):not([class]) + div[id][class] {display:none!important}'));
  948. document.head.appendChild(style);
  949. };
  950.  
  951. scripts['rsload.net'] = function() {
  952. win.addEventListener('load', function() {
  953. var dis = document.querySelector('.cb-disable');
  954. if (dis) {
  955. dis.click();
  956. }
  957. });
  958. document.addEventListener('click',function(e){
  959. var t = e.target;
  960. if (t && t.href && (/:\/\/\d+\.\d+\.\d+\.\d+\//.test(t.href))) {
  961. t.href = t.href.replace('://','://rsload.net:rsload.net@');
  962. }
  963. });
  964. };
  965.  
  966. scripts['imageban.ru'] = function() {
  967. preventBackgroundRedirect();
  968. win.addEventListener('unload', function() {
  969. if (!window.location.hash) {
  970. window.location.replace(window.location+'#');
  971. } else {
  972. window.location.hash = '';
  973. }
  974. }, true);
  975. };
  976.  
  977. var domain = document.domain;
  978. while (domain.indexOf('.') !== -1) {
  979. if (scripts.hasOwnProperty(domain)) {
  980. scripts[domain]();
  981. break;
  982. }
  983. domain = domain.slice(domain.indexOf('.') + 1);
  984. }
  985. });
  986. })();