Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name F*ck you, redirecters
- // @version 0.6
- // @author Pavel Lymarev <x hyphen user at bk dot ru>
- // @exlude /^.*:\/\/.*$/
- // @include /^https?:\/\/vk\.com(?:\/.*)?$/
- // @include /^https?:\/\/(?:[a-z]+\.)?google\.(?:com|ru)(?:\/.*)?$/
- // @include /^https?:\/\/(?:[a-z]+\.)?youtube\.com(?:\/.*)?$/
- // @run-at document-start
- // @grant none
- // ==/UserScript==
- const youtubeRe = /https?:\/\/(?:[a-z]+\.)?youtube\.com\/redirect\?(?:.+)$/i;
- const vkRe = /https?:\/\/vk\.com\/away\.php\?(?:.+)$/i;
- const googleRe = /https?:\/\/(?:[a-z]+\.)?google\.(?:com|ru)\/url\?(?:.+)$/i;
- function processNode(node) {
- if (node.href == null) {
- return;
- }
- if (youtubeRe.test(node.href)) {
- node.href = new URL(node.href).searchParams.get('q');
- } else if (vkRe.test(node.href)) {
- node.href = new URL(node.href).searchParams.get('to');
- } else if (googleRe.test(node.href)) {
- node.href = new URL(node.href).searchParams.get('url');
- }
- }
- new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (mutation.type === 'attributes') {
- var node = mutation.target;
- if (node.tagName === 'A' && mutation.attributeName === 'href') {
- processNode(node);
- }
- } else if (mutation.type === 'childList') {
- Array.prototype.forEach.call(mutation.addedNodes, function(node) {
- if (node.tagName === 'A') {
- processNode(node);
- }
- });
- }
- });
- }).observe(document, { attributes: true, childList: true, subtree: true });
Add Comment
Please, Sign In to add comment