Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Remove shitty AD
  3. // @namespace    https://gist.github.com/GlobalEliteBhopMaster/e12828ec23ad6f06626a8b311e1d0456
  4. // @version      0.3
  5. // @description  Removes the ad!
  6. // @author       You
  7. // @match        smotret-anime.ru/*
  8. // @match        smotretanime.ru/*
  9. // @grant        GM_xmlhttpRequest
  10. // @grant        GM_getValue
  11. // @grant        GM_setValue
  12. // @run-at       document-start
  13. // ==/UserScript==
  14.  
  15. function createCookie(name,value)
  16. {
  17.     document.cookie = name + "=" + value + "; path=/";
  18. }
  19.  
  20. function removeCookie(name)
  21. {
  22.     document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
  23. }
  24.  
  25. function getCookie(name)
  26. {
  27.   var nameEQ = name + "=";
  28.   var ca = document.cookie.split(';');
  29.   for(var i=0; i < ca.length; i++)
  30.   {
  31.     var c = ca[i];
  32.     while (c.charAt(0)==' ') c = c.substring(1, c.length);
  33.     if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  34.   }
  35.   return null;
  36. }
  37.  
  38. function DOMtoString(document_root) {
  39.     var html = '',
  40.         node = document_root.firstChild;
  41.     while (node) {
  42.         switch (node.nodeType) {
  43.         case Node.ELEMENT_NODE:
  44.             html += node.outerHTML;
  45.             break;
  46.         case Node.TEXT_NODE:
  47.             html += node.nodeValue;
  48.             break;
  49.         case Node.CDATA_SECTION_NODE:
  50.             html += '<![CDATA[' + node.nodeValue + ']]>';
  51.             break;
  52.         case Node.COMMENT_NODE:
  53.             html += '<!--' + node.nodeValue + '-->';
  54.             break;
  55.         case Node.DOCUMENT_TYPE_NODE:
  56.             // (X)HTML documents are identified by public identifiers
  57.             html += "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>\n';
  58.             break;
  59.         }
  60.         node = node.nextSibling;
  61.     }
  62.     return html;
  63. }
  64.  
  65. function ready(fn) {
  66.     //document.addEventListener('page:load', fn);
  67.  
  68.     if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
  69.         fn();
  70.     } else {
  71.         document.addEventListener('DOMContentLoaded', fn);
  72.     }
  73. }
  74.  
  75. function firstStart(ignoreCookie = false)
  76. {
  77.     window.localStorage.setItem('videojs-quality-2', '1080');
  78.  
  79.     var watchedPromoVideo = ignoreCookie ? null : getCookie('watchedPromoVideo');
  80.  
  81.     if (watchedPromoVideo === null)
  82.     {
  83.         createCookie('ads-blocked', '0');
  84.     }
  85. }
  86.  
  87. function setCookie(code)
  88. {
  89.     var req = GM_xmlhttpRequest({
  90.         method: "GET",
  91.         headers: { "Accept": "application/json" },
  92.         url: "https://smotret-anime.ru/translations/embedActivation?code=" + encodeURIComponent(code),
  93.         onload: function(response) {
  94.             var html = response.responseText;
  95.             //console.log('resp: ' + html);
  96.  
  97.             var json = JSON.parse(html);
  98.  
  99.             console.log('cookieValue: ' + json.cookieValue);
  100.  
  101.             createCookie('watchedPromoVideo', json.cookieValue);
  102.  
  103.             setTimeout(() => window.location.reload(false), 500);
  104.         }
  105.     });
  106. }
  107.  
  108. function checkAd()
  109. {
  110.     var serialized_html = DOMtoString(document);
  111.  
  112.     if (/<div class="seed-player-container videoseed-player-container">/.exec(serialized_html) !== null)
  113.     {
  114.         var pathname = window.location.pathname;
  115.         if (pathname.search("/translations/embed/") != -1)
  116.         {
  117.             var watchedPromoVideo = getCookie('watchedPromoVideo');
  118.  
  119.             if (watchedPromoVideo === null)
  120.             {
  121.                 var videoPlayer = document.querySelector('.video-js video, video.video-js');
  122.                 videoPlayer.click();
  123.  
  124.                 document.querySelector('.subtitles').style.display = "none";
  125.                 document.querySelector('.text').innerHTML = null;
  126.  
  127.                 var iframe = document.querySelector("iframe");
  128.                 if (iframe)
  129.                 {
  130.                     iframe.remove();
  131.                 }
  132.  
  133.                 var oActivate = unsafeWindow.playerGlobal.concatenate.activate;
  134.  
  135.                 unsafeWindow.playerGlobal.concatenate.activate = (code) => {
  136.                     console.log('code: ' + code);
  137.  
  138.                     GM_setValue("code", code);
  139.  
  140.                     oActivate(code);
  141.  
  142.                     var codeInterval = setInterval(() => {
  143.                         if (unsafeWindow.playerGlobal.support.cookieValue)
  144.                         {
  145.                             clearInterval(codeInterval);
  146.                             unsafeWindow.playerGlobal.support.skip();
  147.  
  148.                             var bind = Function.bind;
  149.                             var unbind = bind.bind(bind);
  150.  
  151.                             function instantiate(constructor, args) {
  152.                                 return new (unbind(constructor, null).apply(null, args));
  153.                             }
  154.  
  155.                             var oldDate = Date;
  156.                             var oldDatePrototype = Date.prototype;
  157.  
  158.                             unsafeWindow.Date = function (Date) {
  159.                                 MyDate.prototype = Date.prototype;
  160.  
  161.                                 function MyDate() {
  162.                                     var date = instantiate(Date, arguments);
  163.                                     date.setYear("2999");
  164.  
  165.                                     return date;
  166.                                 }
  167.  
  168.                                 return MyDate;
  169.                             }(Date);
  170.  
  171.                             var skipButton = document.querySelector('.skip-button');
  172.                             skipButton.click();
  173.  
  174.                             unsafeWindow.Date = oldDate;
  175.                             unsafeWindow.Date.prototype = oldDatePrototype;
  176.                         }
  177.                     }, 500);
  178.                 };
  179.             }
  180.         }
  181.     }
  182. }
  183.  
  184. function checkCode()
  185. {
  186.     var serialized_html = DOMtoString(document);
  187.  
  188.     if (/<div class="seed-player-container videoseed-player-container">/.exec(serialized_html) !== null)
  189.     {
  190.         var pathname = window.location.pathname;
  191.         if (pathname.search("/translations/embed/") != -1)
  192.         {
  193.             var code = GM_getValue("code", null);
  194.  
  195.             if (code !== null)
  196.             {
  197.                 var newBody = document.createElement("body");
  198.                 newBody.innerHTML = "<center><h1>Обходим говнорекламу...</h1></center><br><center><h2>Страница будет перезагружена несколько раз.</h2></center>";
  199.                 document.body.replaceWith(newBody);
  200.                 document.body.style.background = 'white';
  201.                 setCookie(code);
  202.             }
  203.         }
  204.     }
  205. }
  206.  
  207. firstStart();
  208. window.onload = checkAd;
  209. ready(checkCode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement