Last active
February 4, 2023 20:55
-
-
Save MagicWinnie/b2589698493f1ac40b245d995ed438a5 to your computer and use it in GitHub Desktop.
Этот скрипт перенаправляет на другую страницу при нажатии vk.com->Моя страница->Ещё->Мои желания
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 - Redirect on pressing "My wishes" | |
// @namespace https://github.com/MagicWinnie | |
// @version 1.0 | |
// @description Этот скрипт перенаправляет на другую страницу при нажатии vk.com->Моя страница->Ещё->Мои желания | |
// @author MagicWinnie | |
// @match https://vk.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=vk.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const LINK = "https://vk.com/"; // ИЗМЕНЯТЬ ЭТУ ССЫЛКУ | |
function click_handler(evt) { | |
window.open(LINK, "_self"); | |
} | |
const callback = (mutationList, observer) => { | |
const addedNodes = mutationList[0].addedNodes; | |
if (addedNodes.length == 0) { return; } | |
const child = addedNodes[0].children[0]; | |
if (!child) { return; } | |
var aTags = child.getElementsByTagName("a"); | |
for (const element of aTags) { | |
if (element.textContent.includes('Мои желания') && element.href != LINK) { | |
element.href = LINK; | |
element.addEventListener("click", click_handler, true); | |
break; | |
} | |
} | |
}; | |
const config = { attributes: false, childList: true, subtree: true }; | |
const observer = new MutationObserver(callback); | |
setInterval(function() { | |
const elem = document.getElementsByClassName('vkui__portal-root'); | |
var targetNode; | |
for (var i = elem.length - 1; i >= 0; i--) | |
{ | |
if (elem[i].nodeName == "DIV") | |
{ | |
targetNode = elem[i]; | |
break; | |
} | |
} | |
try { | |
observer.observe(targetNode, config); | |
} catch (error) | |
{ } | |
}, 500); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment