Bilibili-Evolved/min/watchlater.min.js
2020-10-06 10:54:43 +08:00

1 line
2.3 KiB
JavaScript

(()=>{return(t,e)=>{const i=t=>{const e=t.match(/(BV[\w]+)\/p([\d]+)/i)||t.match(/(av[\d]+)\/p([\d]+)/i);if(e){return`https://www.bilibili.com/video/${e[1]}/?p=${e[2]}`}else{return"javascript:;"}};const r=t=>{const e=t.map(t=>{const e=t.getAttribute("href");if(!e){return"javascript:;"}if(e.match(/.*watchlater.*|javascript:;/g)){return i(e)}if(e.match(/video\/av|video\/BV/i)){return e}return e});t.forEach((t,i)=>{t.setAttribute("href",e[i]);t.setAttribute("target","_blank")})};const a=(...t)=>{for(const e of t){SpinQuery.select(()=>document.querySelectorAll(e),t=>r([...t]))}};if(t.watchLaterRedirectPage){if(document.URL==="https://www.bilibili.com/watchlater/#/list"){(async()=>{const{getWatchlaterList:t}=await e.importAsync("watchlater-api");const i=await t(true);const r=await SpinQuery.select(".watch-later-list .list-box > span");if(!r){return}const a=(t,e)=>{const r=i[e];const a=r.aid;const c=r.cid;const s=r.pages;const l=c===0?1:s.find(t=>t.cid===c).page;const n=l>1?`https://www.bilibili.com/video/av${a}?p=${l}`:`https://www.bilibili.com/video/av${a}`;const o=t.querySelector(".av-pic");o.target="_blank";o.href=n;const h=t.querySelector(".av-about .t");h.target="_blank";h.href=n};const c=r.querySelectorAll(".av-item");c.forEach(a);Observer.attributesSubtree(r,t=>{t.forEach(t=>{if(t.target instanceof HTMLAnchorElement&&t.attributeName==="href"){const e=t.target;const i=dqa(r,".av-item");if(e.href.includes("/medialist/play/watchlater/")){const t=i.findIndex(t=>t.contains(e));if(t!==-1){a(i[t],t)}}}})})})()}}if(t.watchLaterRedirectNavbar){SpinQuery.select(".van-popper-favorite").then(async t=>{if(!t){return}const e=Observer.childListSubtree(t,()=>{const i=t.querySelector(".play-all");if(i){const t="//www.bilibili.com/watchlater/#/list";Observer.attributes(i,()=>{if(i.firstElementChild===null||i.lastChild===null){return}if(i.getAttribute("href")==="//www.bilibili.com/watchlater/"){i.setAttribute("href",t);i.firstElementChild.classList.remove("bili-icon_dingdao_bofang");i.firstElementChild.classList.add("bili-icon_xinxi_yuedushu");i.lastChild.nodeValue="查看全部"}else if(i.getAttribute("href")!==t){i.firstElementChild.classList.add("bili-icon_dingdao_bofang");i.firstElementChild.classList.remove("bili-icon_xinxi_yuedushu");i.lastChild.nodeValue="播放全部"}});e.forEach(t=>t.stop())}})})}}})();