bilibili

过滤掉一些搜索结果!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         bilibili
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  过滤掉一些搜索结果!
// @author       You
// @match        https://search.bilibili.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    function c1(dom) {
        dom.style.opacity = 0.3
        dom.style.display = 'initial'
    }

    function c2(dom) {
        dom.style.display = 'none'
    }

    function restore(dom) {
        dom.style.opacity = 3
        dom.style.display = 'initial'
    }

    let doClear = c2

    const filter = new Proxy(
        {
            isWork: false,
            limitHour: 7,
            limitYear: 2020,
        },
        {
            set: function (target, propKey, value, receiver) {
                const result = Reflect.set(target, propKey, value, receiver)
                clear()
                return result
            },
        }
    )

    let html
    function clear() {
        const list = document.querySelectorAll('.video-list>div')
        list.forEach((dom) => {
            let hit
            test: if (filter.isWork) {
                let test

                // 时长
                test = dom.querySelector('.bili-video-card__stats__duration')
                if (test) {
                    const time = test.innerHTML
                    const hour = Number(/(?:(\d{2}):)?(\d{2}):(\d{2})/.exec(time)?.[1] || 0)
                    if (hour < (filter.limitHour || 0)) {
                        hit = dom
                        break test
                    }
                }


                // 日期
                test = dom.querySelector('.bili-video-card__info--date')
                if (test) {
                    test = test.innerHTML
                    test = /(?:(\d{4})-)?(\d{1,2})-(\d{1,2})/.exec(test)
                    test = test[1]
                    if (test && Number(test) < (filter.limitYear || 2020)) {
                        hit = dom
                        break test
                    }
                }
            }

            if (hit) {
                doClear(hit)
            } else {
                restore(dom)
            }
        })
    }
    setInterval(() => {
        const newHtml = document.querySelector('.video-list').innerText
        if (html != newHtml) {
            html = newHtml
            setTimeout(clear, 50)
        }
    }, 50)

    // 操作栏
    const bar = document.createElement('div')
    bar.style.position = 'fixed'
    bar.style.right = '10px'
    bar.style.bottom = '220px'
    bar.style.zIndex = 1000
    document.body.appendChild(bar)

    // 年份输入
    const inputYear = document.createElement('input')
    inputYear.style.width = '60px'
    inputYear.setAttribute('type', 'number')
    inputYear.setAttribute('value', filter.limitYear)
    inputYear.addEventListener('input', (e) => {
        filter.limitYear = e.target.valueAsNumber
    })
    bar.appendChild(inputYear)
    bar.appendChild(document.createElement('br'))

    // 时长输入
    const inputHour = document.createElement('input')
    inputHour.style.width = '60px'
    inputHour.setAttribute('type', 'number')
    inputHour.setAttribute('value', filter.limitHour)
    inputHour.addEventListener('input', (e) => {
        filter.limitHour = e.target.valueAsNumber
    })
    bar.appendChild(inputHour)
    bar.appendChild(document.createElement('br'))

    // 切换按钮
    const btn = document.createElement('button')
    btn.innerText = '切换'
    btn.style.backgroundColor = '#fff'
    btn.style.border = '1px solid rgb(118, 118, 118)'
    btn.addEventListener('click', () => {
        if (doClear == c1) {
            doClear = c2
        } else {
            doClear = c1
        }
        clear()
    })
    bar.appendChild(btn)

    // 开关按钮
    const stopSwitch = document.createElement('button')
    stopSwitch.innerText = '开关'
    stopSwitch.style.color = 'red'
    stopSwitch.style.backgroundColor = '#fff'
    stopSwitch.style.border = '1px solid rgb(118, 118, 118)'
    stopSwitch.addEventListener('click', () => {
        if (filter.isWork) {
            filter.isWork = false
            stopSwitch.style.color = 'red'
        } else {
            filter.isWork = true
            stopSwitch.style.color = 'green'
        }
    })
    bar.appendChild(stopSwitch)

})();