自研 - 哔哩哔哩 - 隐藏已看完的播放记录

将已看完的播放记录移除掉。

// ==UserScript==
// @name               自研 - 哔哩哔哩 - 隐藏已看完的播放记录
// @name:en_US         Self-made - BiliBili - Hide watched playlists
// @description        将已看完的播放记录移除掉。
// @description:en_US  Remove the playback records of videos that have already been watched.
// @version            1.0.6
// @author             CPlayerCHN
// @license            MulanPSL-2.0
// @namespace          https://www.gitlink.org.cn/CPlayerCHN
// @match              https://www.bilibili.com/account/history
// @icon               https://static.hdslb.com/images/favicon.ico
// @grant              GM_addStyle
// @run-at             document-start
// @noframes
// ==/UserScript==

(function() {
    'use strict';

    // 修改页面最小高度,让更多播放记录正常加载。
    GM_addStyle("body { min-height: 125vh }");

    // 定义「初始化」函数。
    function init() {

        // 定义「历史清单」元素。
        const historyList = document.querySelector('#history_list');

        // 判断「历史清单」原素是否存在,如果存在就…
        if (historyList) {

            // 定义「侦测器」变量。
            var observer = new MutationObserver((elms) => {

                // 遍历「播放记录」信息。
                document.querySelectorAll('#history_list .history-record').forEach((elm) => {

                    // 如果带有「已看完」字样,就移除它。
                    if(/已看完/.test(elm.textContent)) {

                        elm.remove();
                    }

                });

            });

            // 配置「侦测器」侦测目标节点。
            observer.observe(historyList, {
                childList: true
            });

        } else {

            // 如果不存在,等待 .1 秒再次判断。
            setTimeout(init, 100);

        }

    };

    // 开始初始化。
    init();

})();