AniBrain: replace JavaScript links

Replaces JS links using proper links that allow 'Right-click > Open in new tab' and other stuff

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         AniBrain: replace JavaScript links
// @version      2023-12-31
// @description  Replaces JS links using proper links that allow 'Right-click > Open in new tab' and other stuff
// @author       thepbone
// @match        https://anibrain.ai/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=anibrain.ai
// @grant        none
// @license      GPLv3
// @run-at       document-idle
// @namespace https://greasyfork.org/users/174601
// ==/UserScript==

(function() {
    'use strict';


    function fixLinks() {
        console.log("Fixing links");

        var mangaDivs = document.getElementsByTagName("div");


        for (var i = mangaDivs.length -1 ; i >=0; i--) {
            var div = mangaDivs[i];
            if(!div.id.startsWith("mrc-Manga-")) {
                console.log("skip " + div.id);
                continue;
            }

            console.log("DONE " + div.id);

            var p = document.createElement("a");
            p.setAttribute("href", div.id.match(/\d/g).join(''));
            var newDiv = div.cloneNode(true);
            newDiv.removeAttribute("id");
            p.appendChild(newDiv);
            div.parentNode.insertBefore(p, div);
            div.parentNode.removeChild(div);
        }
    }

    var count = 0;

    var currentInterval = 0;
    var x = new MutationObserver(function (e) {
        if(count >= 10) {
            x.disconnect();
        }

        if (e[0].addedNodes) {
            if(currentInterval != 0) {
                clearInterval(currentInterval);
            }

            currentInterval = setInterval(function(){
                currentInterval = 0;
                fixLinks();
            }, 1000);

            count++;
        }
    });

    x.observe(document.getElementsByTagName('main')[0], { childList: true, subTree: true });
})();