Skip to content

Instantly share code, notes, and snippets.

@gonzazoid
Created May 13, 2020 16:16
Show Gist options
  • Save gonzazoid/73da42c6d019e531bd49200676e75f20 to your computer and use it in GitHub Desktop.
Save gonzazoid/73da42c6d019e531bd49200676e75f20 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Replacer
// @namespace https://127.0.0.1/
// @version 0.1
// @date 2020-04-29
// @author XXX
// @description Replacer
// @include http://*
// @include https://*
// @run-at document-end
// @connect self
// ==/UserScript==
const debounce = function (func, timeout) {
let lock = false;
return function () {
if (lock) {
return;
}
const callback = () => {
lock = false;
func();
};
lock = true;
setTimeout(callback, timeout);
};
};
const replacer = function() {
const links = document.querySelectorAll("a");
const test = /https:\/\/app\.appwizard\.ru\/wizredirect\?info=[0-9a-z]+&soft=([^/]+)/;
for(var i=0; i<links.length; i++) {
if(test.test(links[i].href)){
const app = links[i].href.match(test)[1];
links[i].href = "http://appdater.ru/en/" + app;
}
}
};
const observerConfig = {
childList: true,
subtree: true,
};
const callback = debounce(replacer, 1e3);
const observer = new MutationObserver(callback);
observer.observe(window.document.body, observerConfig);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment