Advertisement
AyrA

Anti Rickroll

Dec 6th, 2016
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserSacript==
  2. // @name         Anti Rickroll
  3. // @namespace    http://ayra.ch/
  4. // @version      0.1
  5. // @description  Warns you about being rickrolled
  6. // @author       /u/AyrA_ch
  7. // @include http://*/*
  8. // @include https://*/*
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.     'use strict';
  14.     //this matches youtube URLs for the video with ID dQw4w9WgXcQ
  15.     var filter=/(?:youtu\.be\/|youtube(-nocookie)?.com\/(?:v\/|e\/|.*u\/\w+\/|embed\/|.*v=))(dQw4w9WgXcQ)/;
  16.     var scanRickRoll=function(){
  17.         var a=document.querySelectorAll("a");
  18.         for(var i=0;i<a.length;i++)
  19.         {
  20.             if(a[i].href && a[i].href.match(filter))
  21.             {
  22.                 a[i].innerHTML="<b>Probably rickroll</b>";
  23.             }
  24.         }
  25.     };
  26.     var timer=false;
  27.     var scheduleUpdater=function(){
  28.         if(!timer)
  29.         {
  30.             timer=window.setTimeout(function(){scanRickRoll();timer=false;},500);
  31.         }
  32.     };
  33.     scanRickRoll();
  34.     document.body.addEventListener('DOMSubtreeModified', function (){
  35.         scheduleUpdater();
  36.     }, false);
  37. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement