VoidVerified

Display a verified sign next to user's name in AniList.

30.09.2023 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         VoidVerified
// @namespace    http://tampermonkey.net/
// @version      0.3.2
// @description  Display a verified sign next to user's name in AniList.
// @author       voidnyan
// @match        https://anilist.co/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    const version = "0.3.2";
    const evaluationIntervalInSeconds = 1;

    const verified = {
        username: {
            enabled: true,
            enabledForReplies: true,
            enabledForProfileName: true,
            color: "white",
            sign: "✔",
        },
        highlight: {
            enabled: true,
            enabledForReplies: true,
            enabledForSmallCards: false,
            color: undefined,
            size: "5px",
        }
    };

    const shouldIntervalBeUsed = verified.username.enabledForProfileName || verified.highlight.enabled;

    const verifiedUsers = [
        {
            username: "voidnyan",
            color: "#f8aade",
            sign: "💻",
        }
    ].map(u => typeof u === "string" ? {username: u} : u);

    let usernameStyles = "";
    let highlightStyles = "";

    for (const user of verifiedUsers){
        if (verified.username.enabled) {
            createUsernameCSS(user);
        }

        if (verified.highlight.enabled) {
            createHighlightCSS(user, `div.wrap:has( div.header > a.name[href*="${user.username}"] )`);
            createHighlightCSS(user, `div.wrap:has( div.details > a.name[href*="${user.username}"] )`);
        }

        if (verified.highlight.enabledForReplies) {
            createHighlightCSS(user, `div.reply:has( a.name[href*="${user.username}"] )`);
        }
    }

    if (verified.highlight.enabled && !verified.highlight.enabledForSmallCards) {
        disableHighlightOnSmallCards();
    }

    function createUsernameCSS(user) {
        usernameStyles += `
        a.name[href*="${user.username}"]::after {
            content: "${user.sign ?? verified.username.sign}";
            color: ${user.color ?? verified.username.color ?? "rgb(var(--color-blue))"}
        }
        `;
    };

    function createHighlightCSS(user, selector){
        highlightStyles += `
        ${selector} {
            margin-right: -${verified.highlight.size};
            border-right: ${verified.highlight.size} solid ${user.color ?? verified.highlight.color ?? "rgb(var(--color-blue))"};
            border-radius: 5px;
        }
        `;
    }

    function disableHighlightOnSmallCards(){
        highlightStyles += `
        div.wrap:has(div.small) {
        margin-right: 0px !important;
        border-right: 0px solid black !important;
        }
        `;
    }

    const usernameLink = createStyleLink(usernameStyles, "username");
    const highlightLink = createStyleLink(highlightStyles, "highlight");
    const profileLink = createStyleLink("", "profile");

    async function refreshHomePage(){
        if (!verified.highlight.enabled) {
            return;
        }

        const randomnumber = await Math.random();
        highlightLink.href = 'data:text/css;charset=UTF-8,' + encodeURIComponent(highlightStyles + randomnumber);
    }

    function verifyProfile(){
        if (!verified.username.enabledForProfileName) {
            return;
        }

        const usernameHeader = document.querySelector("h1.name");
        const username = usernameHeader.innerHTML.trim();

        const user = verifiedUsers.find(u => u.username === username);
        if (!user){
            profileLink.href = 'data:text/css;charset=UTF-8,' + encodeURIComponent("");
            return;
        }

        const profileStyle = `
            h1.name::after {
            content: "${user.sign ?? verified.username.sign}"
            }
        `;
        profileLink.href = 'data:text/css;charset=UTF-8,' + encodeURIComponent(profileStyle);
    }

    function createStyleLink(styles, id){
        const link = document.createElement('link');
        link.setAttribute('id', `void-verified-${id}-styles`);
        link.setAttribute('rel', 'stylesheet');
        link.setAttribute('type', 'text/css');
        link.setAttribute('href', 'data:text/css;charset=UTF-8,' + encodeURIComponent(styles));
        document.head?.append(link);
        return link;
    }

    function handleIntervalScripts(){
        const path = window.location.pathname;
        if (path === "/home") {
            refreshHomePage();
        } else if (path.startsWith("/user/")){
            verifyProfile();
        }
    }

    if (shouldIntervalBeUsed) {
        setInterval(handleIntervalScripts, evaluationIntervalInSeconds * 1000);
    }

    console.log(`VoidVerified ${version} loaded.`);
})();