mark last read

Bookmark Kemono entries

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         mark last read
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Bookmark Kemono entries
// @author       SoloJessy
// @match        https://kemono.su/patreon/user/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=kemono.party
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    let currPath = window.location.pathname;
    let highlightColor = "Aqua";

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

        let button = document.createElement('button');
        button.innerText = "*";
        button.style.position = "absolute";
        button.style.top = "3px";
        button.style.right = "3px";
        button.style.zIndex = "5";

        let id = cV.dataset.id;
        button.addEventListener("click", () => {
            let mark = localStorage.getItem(currPath);

            let oldTarget = document.querySelector(`[data-id='${mark}']>a`);
            if (oldTarget) oldTarget.style.background = "";

            let newTarget = document.querySelector(`[data-id='${id}']>a`);
            if (newTarget) newTarget.style.background = highlightColor;

            localStorage.setItem(currPath, id);
        });

        cV.appendChild(button);
    });

    let elem = document.querySelector("[data-id='" + localStorage.getItem(currPath) + "']>a");
    if (elem) elem.style.background = highlightColor;
})();