Greasy Fork

Greasy Fork is available in English.

manhuagui_readed_mark

标记一下哪些是看过的,哪些是不想看的。

当前为 2023-02-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         manhuagui_readed_mark
// @namespace    http://greasyfork.icu/zh-CN/scripts/388742-red-list
// @version      0.0.1
// @description  标记一下哪些是看过的,哪些是不想看的。
// @author       shawn
// @license MIT
// @match        *://*.manhuagui.com/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// ==/UserScript==

(function () {
    'use strict';

    let downloaded_listName = 'downloaded-list';
    let blocked_listName = 'blocked-list';



    let buttonName = 'redbutton';

    // delete all
    //GM_deleteValue('red-list');console.log('list:' + GM_getValue('red-list', 'empty'));return;

    let path = location.pathname
    if (path.startsWith('/list/')) {
        let downloaded_list = GM_getValue(downloaded_listName, "").split(';');
        let blocked_list = GM_getValue(blocked_listName, "").split(';');

        // 帖子详情页
        let ul = document.getElementById('contList');
        // 取出所有的li
        let lis = ul.getElementsByTagName('li');
        let len = lis.length;
        for (let i = 0; i < len; i++) {
            let href = lis[i].getElementsByClassName('bcover')[0].getAttribute('href');
            // // 取出 a 标签的 href 属性
            // if (redlist.indexOf(href) >= 0) {
            //     // console.log('in red list: ' + username.innerText);
            //     lis[i].style = "background-image:url(https://i.loli.net/2019/06/09/5cfbebdfd083a19907.png);background-size:contain;";
            // }
            // 取出 class 为 updateon 的 span 的内容
            let datestr = lis[i].getElementsByClassName('updateon')[0].innerHTML;
            // 正则匹配出 datestr 中格式为 2019-10-20 的日期


            let isDownloaded = downloaded_list.indexOf(href) >= 0
            let isBlocked = blocked_list.indexOf(href) >= 0

            if (isDownloaded) {
                lis[i].style = "background: greenyellow;"
            } else if (isBlocked) {
                lis[i].style = "background: orangered;"
            }

            let buttonName = "btn_down_" + i
            let button_container = lis[i].getElementsByClassName('updateon')[0];
            let btn_down = document.createElement('input');
            btn_down.setAttribute('type', 'button');
            btn_down.setAttribute('id', buttonName);
            btn_down.setAttribute('value', isDownloaded ? 'UnDown' : 'Downed');
            btn_down.setAttribute('class', 'super normal button');
            button_container.appendChild(btn_down);
            // onclick 传递 href
            document.getElementById(buttonName).onclick = function () {
                let strlist = GM_getValue(downloaded_listName, "")
                if (isDownloaded) {
                    GM_setValue(downloaded_listName, strlist.replace(';' + href, ''));
                    lis[i].style = ""
                } else {
                    GM_setValue(downloaded_listName, strlist + ';' + href);
                    lis[i].style = "background: greenyellow;"
                }
                document.getElementById(buttonName).value = GM_getValue(downloaded_listName, '').split(';').indexOf(href) >= 0 ? 'UnDown' : 'Downed';
            }


            let buttonBlockName = "btn_block_" + i
            let btn_block = document.createElement('input');
            btn_block.setAttribute('type', 'button');
            btn_block.setAttribute('id', buttonBlockName);
            btn_block.setAttribute('value', isBlocked ? 'UnBlock' : 'Block');
            btn_block.setAttribute('class', 'super normal button');
            button_container.appendChild(btn_block);
            // onclick 传递 href
            document.getElementById(buttonBlockName).onclick = function () {
                let strlist = GM_getValue(blocked_listName, "")
                if (isBlocked) {
                    GM_setValue(blocked_listName, strlist.replace(';' + href, ''));
                    lis[i].style = ""
                } else {
                    GM_setValue(blocked_listName, strlist + ';' + href);
                    lis[i].style = "background: orangered;"
                }
                document.getElementById(buttonBlockName).value = GM_getValue(blocked_listName, '').split(';').indexOf(href) >= 0 ? 'UnBlock' : 'Block';
            }
        }
    }
})();