Greasy Fork

Greasy Fork is available in English.

重写av页实验

测试中的脚本,基本不能使用,希望能作为大家的参考。重写的最简陋的b战av页播放器(没有任何布局!),弹幕列表消失的话可以试着往下滚就恢复了。

当前为 2019-12-27 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         重写av页实验
// @namespace    Motoori Kashin
// @version      0.1
// @description  测试中的脚本,基本不能使用,希望能作为大家的参考。重写的最简陋的b战av页播放器(没有任何布局!),弹幕列表消失的话可以试着往下滚就恢复了。
// @author       Motoori Kashin
// @match        *://*.bilibili.com/video/av*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.stop();
    // 新版av页2019年10月26 10:00起已经不适用定时器延时载入Element了,全都用promise!所以这里失效了ಥ_ಥ。
    /*var highestTimeoutId = setTimeout(";");
    for (var i = 0 ; i < highestTimeoutId ; i++) {
        clearTimeout(i);//清除所有定时器,防止后续Element载入
    }*/
    const xhr = new XMLHttpRequest();
    xhr.open('GET', window.location.href);// 返回新播放页,为重写提供可能需要的数据,仅作为测试的话用不到
    xhr.onload = () => {
        var html = xhr.responseText.replace(/<script\b[\s\S]*?<\/script>/g,"");// ---------------------清空所有<script>脚本
        var a = html.replace(/<style\b[\s\S]*?<\/style>/g,"");// --------------------------------------清空所有<style>布局
        a = a.replace(/<link\b[\s\S]*?>/g,"");// ------------------------------------------------------清空所有<link>引入的css布局
        html = a.replace(/<body\b[\s\S]*?<\/body>/g,"xxx"); // ----------------------------------------清空<body>并用"xxx"占位,方便重写<body>
        // 在<head>里引入2018年5月2日旧版av页<head>中可能有用的<script>和<link>的css
        // 前一行应该是判断浏览器UA,看起来似乎可以不引入;第二行是css,可能是旧版av页全局的css,除了评论区(因为就这两个外链css);还有两个后端写了av号数据包括aid的脚本因为依赖与av号,这里直接删除了
        var wrh = '<script type="text/javascript">(function(){var ua=window.navigator.userAgent,agents=["Android","iPhone","SymbianOS","Windows Phone","iPod"],isPC=true;for(var i=0,len=agents.length;i<len;i++){if(ua.indexOf(agents[i])>0){isPC=false;break}}if(!isPC){var href=window.location.origin.replace("www","m")+"/video/"+window.location.href.match(/av([0-9]+)/g)[0]+".html"+window.location.search;window.location.href=href}})();</script><script type="text/javascript">window.spmReportData = {}window.reportConfig = { sample : 1, scrollTracker: true, msgObjects : ' + "'" + 'spmReportData' + "'" + ', errorTracker: true }</script><style><![CDATA[.player-fix{width:980px;min-height:556px;text-align:center;z-index:201;}.player-fix.abs{position:absolute;margin-left:-490px;top:414px;left:50%;}#bofqi .player{width:980px;height:556px;display:block}#bofqi.wide .player{height:608px}#bofqi.webfullscreen .player{width:100%;height:100%;margin-top:0}#bofqi #player_placeholder .placeholder{width:980px;height:556px}#bofqi embed{width:980px;height:530px}@media screen and (min-width:1400px){.player-fix{min-height:688px;width:1160px;}.player-fix.abs{margin-left:-580px;left:50%;}#bofqi .player,#bofqi embed{width:1160px;height:688px}#bofqi.wide .player{height:737px}#player_placeholder .placeholder{width:1160px;height:688px}}]]></style>' +
            '<link rel="stylesheet" href="https://s1.hdslb.com/bfs/static/jinkela/videoplay/css/video.1.b1b7706abd590dd295794f540f7669a5d8d978b3.css"></head>'
        html = html.replace(/<\/head>/g,wrh);
        // 开始重写<body>,这里未调用任何新版播放页返回的数据直接写最基本框架来测试(去除了所有依赖av号数据的内容)
        var wrb = '<div id="video-page-app"></div>' +
            // 两个最基本的js脚本,第二个应该就是旧版播放器
            '<script type="text/javascript" src="https://static.hdslb.com/js/jquery.min.js"></script>' +
            '<script type="text/javascript" src="https://static.hdslb.com/js/video.min.js"></script>' +
            '<div class="player-fix abs" id="bofqi">' +
                '<script type="text/javascript">' +
                    // 似乎是载入旧版播放器的关键代码,取自2018年5月2日旧版av页同样位置,这里的缩进表示原来的标签层次
                    // 这里警告是因为原代码中带有混用了单双引号',这里把单引号重新用双引号",包起来使其不与赋值时用到的单引号'冲突,警告是说建议不要用加号+连接两个用单引号'框起来的字符串(因为直接写在一起就行,这里由于单引号冲突'只能用加号+)
                    'window.getInternetExplorerVersion=function(){var rv=-1;if(navigator.appName=="Microsoft Internet Explorer"){var ua=navigator.userAgent;var re=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");if(re.exec(ua)!=null){rv=parseFloat(RegExp.$1)}}return rv};function getQueryString(name){var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");var r=window.location.search.substr(1).match(reg);if(r!=null){return unescape(r[2])}return null}var vd=window.__INITIAL_STATE__&&window.__INITIAL_STATE__.videoData;if(vd&&vd.aid&&getInternetExplorerVersion()!==9){$("#__bofqi").innerHTML=' + "'" + '<div class="bili-wrapper" id="bofqi"><div id="player_placeholder"></div></div>' + "'" + ';if(vd.embedPlayer){var p=getQueryString("p")?getQueryString("p")-1:0;var player={aid:vd.aid,cid:(vd.pages[p]&&vd.pages[p].cid)||vd.pages[0].cid};EmbedPlayer("player","https://static.hdslb.com/play.swf","cid="+player.cid+"&aid="+player.aid+"&pre_ad=")}if(vd.embed){$("#bofqi").html(vd.embed)}}else{$("#bofqi").remove()};' +
                '</script>' +
            '</div>' +
            // 2018年5月2日旧版av页的主体部分,网页显示全部内容都在这个id="app"的div里,其中很多内容(后端直接写在网页里的)需要依赖上面新av页数据返回来修改(或者用api重新获取),这里为了测试删除了下级所有标签(包括上面那个关键脚本可能依赖的标签)
            '<div id="app" data-server-rendered="true"></div>';
        // 用重写的<body>替换占位的"xxx"
        html = html.replace(/xxx/g,wrb);
        document.open();
        document.write(html);
        // 原想延迟6s等后续的Element载入完再重写网页,后来发现延迟载入的那些脚本好像并没有什么妨碍,最多引入了部分av信息和评论区
        //setTimeout(function(){document.write(html);},6000);
        // 播放器会被某个js或css自动缩小(没有定位到是哪个家伙干的ಥ_ಥ),所以延时把style清空
        setTimeout(function(){document.getElementById('bofqi').style = "";},2000);
        document.close();
    };
    xhr.send();
})();