xuser

xD

Mar 24th, 2018 (edited)
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name F*ck you, redirecters
  3. // @version 0.6
  4. // @author Pavel Lymarev <x hyphen user at bk dot ru>
  5. // @exlude /^.*:\/\/.*$/
  6. // @include /^https?:\/\/vk\.com(?:\/.*)?$/
  7. // @include /^https?:\/\/(?:[a-z]+\.)?google\.(?:com|ru)(?:\/.*)?$/
  8. // @include /^https?:\/\/(?:[a-z]+\.)?youtube\.com(?:\/.*)?$/
  9. // @run-at document-start
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. const youtubeRe = /https?:\/\/(?:[a-z]+\.)?youtube\.com\/redirect\?(?:.+)$/i;
  14. const vkRe      = /https?:\/\/vk\.com\/away\.php\?(?:.+)$/i;
  15. const googleRe  = /https?:\/\/(?:[a-z]+\.)?google\.(?:com|ru)\/url\?(?:.+)$/i;
  16.  
  17. function processNode(node) {
  18.     if (node.href == null) {
  19.         return;
  20.     }
  21.  
  22.     if (youtubeRe.test(node.href)) {
  23.         node.href = new URL(node.href).searchParams.get('q');
  24.     } else if (vkRe.test(node.href)) {
  25.         node.href = new URL(node.href).searchParams.get('to');
  26.     } else if (googleRe.test(node.href)) {
  27.         node.href = new URL(node.href).searchParams.get('url');
  28.     }
  29. }
  30.  
  31. new MutationObserver(function(mutations) {
  32.     mutations.forEach(function(mutation) {
  33.         if (mutation.type === 'attributes') {
  34.             var node = mutation.target;
  35.             if (node.tagName === 'A' && mutation.attributeName === 'href') {
  36.                 processNode(node);
  37.             }
  38.         } else if (mutation.type === 'childList') {
  39.             Array.prototype.forEach.call(mutation.addedNodes, function(node) {
  40.                 if (node.tagName === 'A') {
  41.                     processNode(node);
  42.                 }
  43.             });
  44.         }
  45.     });
  46. }).observe(document, { attributes: true, childList: true, subtree: true });
Add Comment
Please, Sign In to add comment