mark last read

Bookmark Kemono entries

< Feedback on mark last read

Review: OK - script works, but has bugs

Here, retard.

(function() {
    'use strict';
    const currPath = window.location.pathname;
    const borderColor = "DarkOrange";
    let markedButton = null;
    let markedElem = null;

    const markPost = (id, button, newTarget) => {
        if (markedButton) {
            markedButton.innerText = " ";
            markedElem.style.border = "";
        }

        newTarget.style.border = `3px solid ${borderColor}`;
        button.innerText = "x";
        markedButton = button;
        markedElem = newTarget;

        localStorage.setItem(currPath, id);
    };

    const createButton = (id, cV) => {
        const button = document.createElement('button');
        button.style.cssText = "position: absolute; top: 2px; right: 3px; z-index: 5; text-align: center; background-color: rgba(0, 0, 0, 0.2); color: Gold;";
        button.innerText = id === localStorage.getItem(currPath) ? "x" : " ";

        button.addEventListener("click", (event) => {
            event.preventDefault();
            markPost(id, button, cV.querySelector(`a`));
        });

        return button;
    };

    document.querySelectorAll("article.post-card").forEach((cV) => {
        cV.style.position = "relative";

        const button = createButton(cV.dataset.id, cV);
        const header = cV.querySelector('.post-card__header');
        header.style.paddingRight = '30px';
        header.appendChild(button);

        if (button.innerText === "x") {
            markedButton = button;
            markedElem = cV.querySelector(`a`);
        }
    });

    const markedPost = document.querySelector(`[data-id='${localStorage.getItem(currPath)}']>a`);
    if (markedPost) {
        markedPost.style.border = `3px solid ${borderColor}`;
    }
})();

Also use:

// @match        https://kemono.su/*/user/*

Since we need this to work for fanbox also, etc.

Post reply

Sign in to post a reply.