// ==UserScript== // @name Bilibili 旧播放页 // @namespace https://greasyfork.org/zh-CN/scripts/394296 // @version 2.4.2 // @description 切换旧版播放页面,布局、播放器全部切换回2019年12月09日之前的样子。载入异常请尝试`Shift+F5`或`Ctrl+Shift+R` // @author Motoori Kashin // @match *://*.bilibili.com/* // @license MIT // @run-at document-start // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; const OR_HTML = document.getElementsByTagName("head")[0].innerHTML; const TITLE = document.getElementsByTagName("title")[0].innerText; const path = document.location.href.split('/'); function xhrHM(url){ // 同步链接获取网页数据 const xhr = new XMLHttpRequest(); xhr.open('GET', url, false); xhr.send(null); if (xhr.status === 200) {return xhr.responseText;} } /*function xhrYM(url){ // 异步链接获取网页数据 const xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.onload = () => {return xhr.responseText;} xhr.send(); } function adscr(src){ // 添加同步script let script = document.createElement("script"); script.setAttribute("type","text/javascript"); script.setAttribute("src",src); document.body.appendChild(script); } function anscr(src){ // 添加异步script let script = document.createElement("script"); script.setAttribute("src",src); script.setAttribute("crossorigin",""); script.setAttribute("defer","defer"); document.body.appendChild(script); } function repEle(ele,dcm){ // 替换页面元素 let rp = document.getElementsByClassName(ele)[0]; let rpw = document.createElement(ele); rpw.innerHTML = dcm; rp.replaceWith(rpw); } function onPlay(){ // 动态添加av页播放器初始化代码 let bofqi = document.getElementById("bofqi"); let str = ''; var range = document.createRange() range.setStart(bofqi, 0) bofqi.appendChild( range.createContextualFragment(str) ) }*/ /* 以上程序存档备用 */ function mkIS(ini,){ // 主动构造ss番剧页播放数据,ss页无法主动获取epId,未登录情况下默认取第一个分集的epId let is = JSON.parse(ini).result; // 以数组形式获取原__INITIAL_STATE__数据,包含番剧原生信息,但需重构 let ep = 0; // 布尔值,判断是否登录,这里用数值0代替(是否能正常获取epId) let pug = JSON.parse(xhrHM(location.href).match(/(?<=PGC_USERSTATE__=).+?(?=<\/script>)/)[0]); // 以数组形式获取新版__PGC_USERSTATE__信息,播放记录被拆分到了这里 /* 下面开始构造__INITIAL_STATE__数据,第一行直接复制自旧版页面 */ let dat = {"ver":{},"loginInfo":{},"canReview":false,"userShortReview":{},"userLongReview":{},"userScore":0,"userCoined":false,"isPlayerTrigger":false,"special":false,"area":0,"app":false,"recomList":[],"playerRecomList":[],"paster":{},"payPack":{},"payMent":{},"activity":{},"spending":0,"sponsorTotal":{"code":0,"result":{"ep_bp":0,"users":0,"mine":{},"list":[]}},"sponsorWeek":{"code":0,"result":{"ep_bp":0,"users":0,"mine":{},"list":[]}},"sponsorTotalCount":0,"miniOn":true,"seasonFollowed":false,"epStat":{},"ssStat":{}}; dat.epId = "";if(pug.hasOwnProperty("progress")){dat.epId = pug.progress.last_ep_id;ep = 1;}; // 当前ep集数 dat.ssId = is.season_id; // 番剧ssID dat.mdId = is.link.match(/[0-9][0-9]*/)[0]; // 番剧信息页ID,这里通过link获取 dat.mediaInfo = {};dat.mediaInfo.actors = is.actors;dat.mediaInfo.alias = is.alias;dat.mediaInfo.areas = is.areas;dat.mediaInfo.cover = is.cover;dat.mediaInfo.evaluate = is.evaluate; dat.mediaInfo.is_paster_ads = is.is_paster_ads;dat.mediaInfo.jp_title = is.jp_title;dat.mediaInfo.link = is.link;dat.mediaInfo.media_id = is.media_id;dat.mediaInfo.mode = is.mode; dat.mediaInfo.season_id = is.season_id;dat.mediaInfo.season_status = is.season_status;dat.mediaInfo.season_title = is.season_title;dat.mediaInfo.season_type = is.season_type; dat.mediaInfo.series_title = is.series_title;dat.mediaInfo.square_cover = is.square_cover;dat.mediaInfo.staff = is.staff;dat.mediaInfo.style = is.style;dat.mediaInfo.title = is.title; dat.mediaInfo.total_ep = is.total_ep; // 番剧基本信息 dat.mediaRating = is.rating; // 评分及长短评 dat.epList = is.episodes;if (ep==0){dat.epId=dat.epList[0].ep_id;}for (let i = 0;i)/)[0]); let dat = {"ver":{},"loginInfo":{},"canReview":false,"userShortReview":{},"userLongReview":{},"userScore":0,"userCoined":false,"isPlayerTrigger":false,"special":false,"area":0,"app":false,"recomList":[],"playerRecomList":[],"paster":{},"payPack":{},"payMent":{},"activity":{},"spending":0,"sponsorTotal":{"code":0,"result":{"ep_bp":0,"users":0,"mine":{},"list":[]}},"sponsorWeek":{"code":0,"result":{"ep_bp":0,"users":0,"mine":{},"list":[]}},"sponsorTotalCount":0,"miniOn":true,"seasonFollowed":false,"epStat":{},"ssStat":{}}; dat.epId = epId;if(pug.hasOwnProperty("progress")){dat.epId = pug.progress.last_ep_id;}; // 未登录时使用默认epId,登录时直接获取历史epId dat.ssId = is.season_id; dat.mdId = is.link.match(/[0-9][0-9]*/)[0]; dat.mediaInfo = {};dat.mediaInfo.actors = is.actors;dat.mediaInfo.alias = is.alias;dat.mediaInfo.areas = is.areas;dat.mediaInfo.cover = is.cover;dat.mediaInfo.evaluate = is.evaluate; dat.mediaInfo.is_paster_ads = is.is_paster_ads;dat.mediaInfo.jp_title = is.jp_title;dat.mediaInfo.link = is.link;dat.mediaInfo.media_id = is.media_id;dat.mediaInfo.mode = is.mode; dat.mediaInfo.season_id = is.season_id;dat.mediaInfo.season_status = is.season_status;dat.mediaInfo.season_title = is.season_title;dat.mediaInfo.season_type = is.season_type; dat.mediaInfo.series_title = is.series_title;dat.mediaInfo.square_cover = is.square_cover;dat.mediaInfo.staff = is.staff;dat.mediaInfo.style = is.style;dat.mediaInfo.title = is.title; dat.mediaInfo.total_ep = is.total_ep; dat.mediaRating = is.rating; dat.epList = is.episodes;for (let i = 0;iwindow.__INITIAL_STATE__.+?<\/script>/)[0]; let html = '' + TITLE + '' + ini + '
'; document.open(); document.write(html); document.close(); } function wrWL(){ // 处理稍后再看 let html = '' + TITLE + '
'; document.open(); document.write(html); document.close(); } function wrBGM(){ // 处理BGM页 if (window.__INITIAL_STATE__){console.log("__INITIAL_STATE__");Reflect.deleteProperty(window, "__INITIAL_STATE__");} // 去掉可能导致番剧页载入失败的新版页面残留的__INITIAL_STATE__ if(path[5].startsWith('ss')){let ssid = location.href.match(/(?<=ss)[0-9]*/); // 分离出ss页面准备构造番剧信息 if (ssid[0]){let url = "https://bangumi.bilibili.com/view/web_api/season?season_id=" + ssid[0];let ini = xhrHM(url);new mkIS(ini);}} if(path[5].startsWith('ep')){let epid = location.href.match(/(?<=ep)[0-9]*/); // 分离出ep页面准备构造番剧信息 if (epid[0]){let url = "https://bangumi.bilibili.com/view/web_api/season?ep_id=" + epid[0];let ini = xhrHM(url);new mkIE(ini,epid[0]);}} let html = '' + TITLE + '
'; document.open(); document.write(html); document.close(); } function wrBB(aid,tvs,wid,hei){ // 处理blackboard let xhr = new XMLHttpRequest(); let url = '//api.bilibili.com/x/player/pagelist?aid=' + aid + '&jsonp=jsonp'; xhr.open('GET', url,true); // 获取异步链接返回值会失败,所以直接写在了异步任务里 xhr.onload = () => { let cid = JSON.parse(xhr.responseText).data[0].cid; let ifr = document.createElement("iframe"); ifr.setAttribute("src",'https://www.bilibili.com/blackboard/html5player.html?aid=' + aid + '&cid=' + cid); ifr.setAttribute("style",'width: '+ wid +'px;height: ' + hei + 'px;'); tvs.replaceWith(ifr); }; xhr.send(); } function wrZY(){ // 处理主页 let html = '哔哩哔哩 (゜-゜)つロ 干杯~-bilibili
'; document.open(); document.write(html); document.close(); } function setDM(){ // 选择弹幕列表 let cDM = setInterval(()=>{ let DMList = document.getElementsByClassName("bilibili-player-filter-btn")[1]; if (DMList){ DMList.click(); clearInterval(cDM); } }, 10); } function wrMH(ele){ // 替换迷你版头 let reh = document.createElement("div"); reh.setAttribute("class","z-top-container"); ele.replaceWith(reh); let script = document.createElement("script"); script.setAttribute("type","text/javascript"); script.setAttribute("src","//s1.hdslb.com/bfs/seed/jinkela/header/header.js"); document.body.appendChild(script); } function wrAH(ele){ // 替换完整版头 let reh = document.createElement("div"); reh.setAttribute("class","z-top-container has-menu"); ele.replaceWith(reh); let script = document.createElement("script"); script.setAttribute("type","text/javascript"); script.setAttribute("src","//s1.hdslb.com/bfs/seed/jinkela/header/header.js"); document.body.appendChild(script); } function wrFT(ele){ // 替换版底 let ret = document.createElement("div"); ret.setAttribute("class","footer bili-footer report-wrap-module"); ret.setAttribute("id","home_footer"); ele.replaceWith(ret); let script = document.createElement("script"); script.setAttribute("type","text/javascript"); script.setAttribute("src","//static.hdslb.com/common/js/footer.js"); document.body.appendChild(script); } function otFX(){ // 其他全局处理 setTimeout(()=>{let blur = document.getElementsByClassName("blur-bg");if (blur[0]){blur[0].removeAttribute("style");}},1000); } function reAV(){ // av页入口 if (OR_HTML.match(/biliconfig/) == null && OR_HTML.match(/去哪/) == null){ // 排除自动重定向的av页 new wrAV(); new setDM(); let reh = setInterval(()=>{ // av页后续处理 let reHead = document.getElementsByClassName("bili-header-m"); if (reHead[1]){ reHead[1].remove(); // 移除旧版av页已失效版头 document.getElementById("bofqi").removeAttribute("style"); // 取消播放器隐藏 document.getElementById("entryNew").setAttribute("style","visibility: hidden;"); // 隐藏新版入口 clearInterval(reh); } }, 10); } } function reWL(){ // 稍后再看入口 new wrWL(); new setDM(); } function reBGM(){ // BGM页入口 if (OR_HTML.match(/出错/) == null){ // 排除无效BGM页 new wrBGM(); new setDM(); let reh = setInterval(()=>{ // BGM页后续处理 let entryNew = document.getElementsByClassName("new-entry")[0]; if (entryNew){ entryNew.setAttribute("style","visibility: hidden;"); clearInterval(reh); } }, 10); } } function reBB(){ // blackboard入口 document.addEventListener("DOMContentLoaded",() => { let ply = document.getElementsByTagName("iframe"); if (ply){ for (let i = 0;i < ply.length;i++){ let src = ply[i].src; if (src && src.match(/newplayer/)[0]){ let aid = src.match(/[0-9][0-9]*/)[0]; let tvs = ply[i]; let wid = ply[i].offsetWidth; let hei = ply[i].offsetHeight; new wrBB(aid,tvs,wid,hei); } } } }); } function reBT(){ // 版头版底处理 document.addEventListener("DOMContentLoaded",() => { let inh = document.getElementById("internationalHeader"); let inf = document.getElementsByClassName("international-footer"); if (inh){ let ppt = document.getElementById("primaryPageTab"); if (ppt){new wrAH(inh);} else{new wrMH(inh);} } if (inf[0]){new wrFT(inf[0]);} }); } function reZY(){ // 主页入口 new wrZY(); } /* 分离页面 */ if (path[3]){ if (path[3] == 'video'&& (path[4].startsWith('av'))){new reAV();} if (path[3] == 'watchlater'){new reWL();} if ((path[3] == 'bangumi') && (path[4] == 'play')){new reBGM();} if (path[3] == 'blackboard'){new reBB();} } if (path[3]){new reBT();} //if (location.href == "https://www.bilibili.com/"){new reZY()}/* 主页目前还未下架,且目前实现的丢失了首页推荐和推广位 */ /* 其他全局处理入口 */ window.onload = otFX(); })();