Greasy Fork is available in English.

bili - b站 - 记录看过的视频

在视频搜索页,标记已经看过的视频

// ==UserScript==
// @name         bili - b站 - 记录看过的视频
// @version      3.0.0
// @author       会飞的蛋蛋面
// @description  在视频搜索页,标记已经看过的视频
// @match        https://search.bilibili.com/*
// @match        https://www.bilibili.com/video/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant        GM.setValue
// @grant        GM.getValue
// @require      https://code.jquery.com/jquery-3.6.4.slim.min.js

// @namespace https://greasyfork.org/users/751952
// ==/UserScript==

(()=>{"use strict";function e(e,t){const i=new MutationObserver((async()=>{0!==$(e).length&&(i.disconnect(),await t())}));i.observe(document.body,{childList:!0,subtree:!0})}async function t(){let e=new Map;for(const t of $(".bili-video-card__image.__scale-player-wrap").parent()){const i=$(t).attr("href").match(/BV[0-9a-zA-Z]+/);if(!i)continue;const o=$(t).find(".bili-video-card__mask")[0];e.set(o,i[0])}let t=await GM.getValue("videoProgressMap",{});const i=new Map(Object.entries(t));for(const[t,o]of e){let e=i.get(o);if(null!=e){let i=(e.currentTime/e.totalTime).toFixed(2);if(i<.1)continue;$("<button>").attr("id",o).addClass("bili-watch-later").css({backgroundColor:"rgba(128, 128, 128, 0.4)",borderRadius:"8px",width:"45px",height:"25px"}).text(i>=.95?"看完":Math.round(100*i)+"%").appendTo(t)}}}function i(){const e=function(e,t){let i=null;return(...o)=>{i||(i=setTimeout((()=>i=null),t),e(...o))}}(o,3e3);$(".bpx-player-video-wrap video").on("timeupdate",e)}async function o(){const e=window.location.href.match(/BV[0-9a-zA-Z]+/)[0],t=$("video").get(0).currentTime,i=$("video").get(0).duration;let o=await GM.getValue("videoProgressMap",{});const n=new Map(Object.entries(o));n.set(e,{currentTime:t,totalTime:i}),await GM.setValue("videoProgressMap",Object.fromEntries(n))}!function(){const o=window.location.href;o.includes("search.bilibili.com")?e(".bili-video-card__image--wrap",(()=>{t(),function(){const e=function(e,t){let i=null;return(...o)=>{clearTimeout(i),i=setTimeout((()=>e(...o)),t)}}(t,500);$(".mt_sm video-list row").on("DOMSubtreeModified",e)}()})):o.includes("bilibili.com/video/BV")&&e(".bpx-player-video-wrap video",i)}()})();