Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Hejto Profile Link (Hejto Script Tester)
- // @namespace Violentmonkey Scripts
- // @match https://www.hejto.pl/*
- // @grant none
- // @version 1.0
- // @author fewtoast
- // @description 25.02.2023, 02:45:25
- // ==/UserScript==
- function sleep(ms) {
- return new Promise(resolve => setTimeout(resolve, ms));
- }
- let oldHref = document.location.href;
- const bodyList = document.querySelector("body");
- const observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (oldHref !== document.location.href) {
- oldHref = document.location.href;
- // console.log("Hejto Script Tester - test 1");
- run();
- }
- });
- });
- const config = {
- childList: true,
- subtree: true
- };
- observer.observe(bodyList, config);
- run();
- async function run () {
- // console.log("Hejto Script Tester - test 1");
- await sleep(4000);
- const profileEl = document.querySelector("button.block");
- if (!profileEl) { return; }
- // function open (e) {
- // const url = `https://www.hejto.pl/uzytkownik/${profileEl.firstChild.getAttribute("alt")}`;
- // window.document.location = url;
- // e.preventDefault();
- // return false;
- // }
- // function openNew (e) {
- // if (e.button===1) {
- // const url = `https://www.hejto.pl/uzytkownik/${profileEl.firstChild.getAttribute("alt")}`;
- // window.open(url);
- // e.preventDefault();
- // return false;
- // }
- // }
- // console.log("profileEl",profileEl);
- const pEl = profileEl.parentElement;
- pEl.addEventListener("mouseenter", async ()=>{
- // console.log("me a");
- if (profileEl.getAttribute("aria-expanded")==="false") {
- // console.log("me b");
- profileEl.click();
- await sleep(100);
- addA();
- // console.log("me c");
- // profileEl.addEventListener("click", open);
- // // console.log("me d");
- // profileEl.addEventListener("mouseup", openNew);
- }
- });
- pEl.addEventListener("mouseleave", ()=>{
- if (profileEl.getAttribute("aria-expanded")==="true") {
- // profileEl.removeEventListener("click", open);
- // profileEl.removeEventListener("mouseup", openNew);
- removeA();
- profileEl.click();
- }
- });
- function addA () {
- const aEl = document.createElement("a");
- aEl.href = `https://www.hejto.pl/uzytkownik/${profileEl.firstChild.getAttribute("alt")}`;
- aEl.append(profileEl);
- pEl.append(aEl);
- }
- function removeA () {
- pEl.append(profileEl);
- pEl.querySelector("a").remove();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement