Last active
December 10, 2021 18:31
-
-
Save ntnbrtnkv/48d8212f0ac917334e124d7f3ed00a5b to your computer and use it in GitHub Desktop.
Unwrap vk.com external away.php links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Vk remove away | |
// @namespace https://gist.github.com/ntnbrtnkv | |
// @version 1.1 | |
// @description Unwrap vk.com away links | |
// @author ntnbrtnkv | |
// @include *vk.com* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
"use strict"; | |
function parseSearch(search) { | |
var objURL = {}; | |
search.replace( | |
new RegExp("([^?=&]+)(?:=([^&]*))?", "g"), | |
function ($0, $1, $2) { | |
objURL[$1] = $2; | |
} | |
); | |
return objURL; | |
} | |
let updateLinks = (target) => { | |
if (target.querySelectorAll) { | |
target.querySelectorAll("a[href^='/away.php?']") | |
.forEach(a => { | |
a.href = decodeURIComponent(parseSearch(a.search).to); | |
}); | |
} | |
}; | |
const callback = function(mutationsList, observer) { | |
for (let mutation of mutationsList) { | |
if (mutation.type === 'childList') { | |
mutation.addedNodes.forEach(updateLinks); | |
} | |
} | |
}; | |
const observer = new MutationObserver(callback); | |
observer.observe(document.body, { | |
attributes: false, | |
childList: true, | |
subtree: true | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment