Greasy Fork is available in English.

抖音网页版优化

抖音网页版推荐、直播优化,网页全屏,全黑,自动按浏览器窗口调整大小

// ==UserScript==
// @name 抖音网页版优化
// @description 抖音网页版推荐、直播优化,网页全屏,全黑,自动按浏览器窗口调整大小
// @namespace https://space.bilibili.com/482343
// @author 古海沉舟
// @license 古海沉舟
// @version 1.14.5
// @match https://www.douyin.com/*
// @include https://*.douyin.com/*
// @require https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js
// @run-at document-end
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addValueChangeListener
// @noframes
// ==/UserScript==
setTimeout(()=>{
    var zz = new Array("","","","","","","","");
    var zzb = new Array("","","","","","","","");
    var lastindex=0,livecount=0,h="",h0="",sortdone=0,lct=0,wt=0;
    var toObj = function( arr ){ var obj = {}; for(var temp in arr){ obj[arr[temp]] = true; } return obj;};
    var toArr = function( obj ){ var arr = []; for(var temp in obj){ arr.push(temp); } return arr;};
    var together = function( a,b ){ for(var temp=0;temp<b.length;temp++)if(b[temp]!=null && b[temp]!="" && b[temp]!="null" && b[temp].length<40){ a.push(b[temp].toLowerCase()); }};
    var getUniq = function(arr){ return toArr( toObj(arr) );};
    var zzx = GM_getValue("zz",new Array());
    var zzy = GM_getValue("zzb",new Array());
    var ispayhide;
    zzx = zzx.filter((itemA) => !zzb.some((itemB) => itemA === itemB));
    zzy = zzy.filter((itemA) => !zz.some((itemB) => itemA === itemB));
    together(zzx,zz);
    zzx =getUniq(zzx);
    zz = new Array();
    together(zz,zzx);
    GM_setValue("zz", zz);
    together(zzy,zzb);
    zzy =getUniq(zzy);
    zzb = new Array();
    together(zzb,zzy);
    zzb = zzb.filter((itemA) => !zz.some((itemB) => itemA === itemB));
    GM_setValue("zzb", zzb);
    const colors = {
        reset: "\x1b[0m",
        red: "\x1b[31m",
        green: "\x1b[32m",
        yellow: "\x1b[33m",
        blue: "\x1b[34m",
        magenta: "\x1b[35m",
        cyan: "\x1b[36m",
        white: "\x1b[37m"
    };

    // 打印彩色文本的函数
    function cc(color, ...args) {
        let total = "";
        for (const arg of args) {
            total += arg;
        }
        console.log(colors[color] + total + colors.reset);
    }

    /*
function cc(color, message) {
  console.log(colors[color] + message + colors.reset);
}
*/
    function keydown(event) {
        //cc("white",event.keyCode);
        if(event.keyCode == 109 || event.keyCode == 189){ // 按-或者小键盘-
            pagefullscreen();
        }
        if(event.keyCode == 187 || event.keyCode == 106){ // 按=或者小键盘*
            payhide();
        }
    }
    document.addEventListener('keydown', keydown, false);

    var haspagefullscreen=0;
    if (location.href.indexOf("douyin.com/follow")>-1){
        haspagefullscreen=1;
        let livestyle = document.createElement('style');
        livestyle.classList.add("live");
        livestyle.innerHTML = `
        .semi-avatar-additionalBorder{border:none!important}
.QecmPpxX .RUVTDzAp,._dJyrFnU .gsOyYJvT{ border-radius: 0%;  }
.Jt6LO5RK .qOwBZHet .trexWhDY,.yP48EXrf .NvKO9tgN .jnhlhsXZ,.QecmPpxX .RUVTDzAp,._dJyrFnU .gsOyYJvT{ animation: none; }

.Jt6LO5RK .qOwBZHet .y5X4PaKT, .Jt6LO5RK .qOwBZHet .o4w20gFP, div.XcEg0PrM,div.Lo8QPz5R,div.QecmPpxX.TrKWAgc9>svg,div.QecmPpxX.TrKWAgc9 > div.X0v0tibw,div.QecmPpxX.TrKWAgc9 > div.XQ9v_nAP,ul > li > a > div > svg,ul > li > a > div > div.WDUuX4lo,ul > li > a > div > div.SDfWCx4A,#douyin-right-container > div.parent-route-container.route-scroll-container.h5AVrOfS > div.jRsgdw_0 > div > div.Cts4MhxF > div.eHY_F2xy.rc3osMc2{ display: none !important }
div[class="iLXEZpcn Wza3QO3S"],div.zhL4qBq2,.yP48EXrf .NvKO9tgN .Pj8z3gc4,div.WQmhtggS,div[data-e2e="recommend-guide-mask"],div.WDUuX4lo,div.SDfWCx4A,#douyin-right-container > div.jRsgdw_0 > div > div.Cts4MhxF > ul > li > div > div.frvzAIi8 > a > div > span > div > span:nth-child(2),#douyin-right-container > div.jRsgdw_0 > div > div.Cts4MhxF > ul > li > div > div.frvzAIi8 > a > div > span > div > span:nth-child(3){display: none!important}

`
    document.body.appendChild(livestyle);
        cc("blue","直播");
        var liveheight=setInterval(livesort,500);

    }
    function livesort(){
        $(`#douyin-right-container > div.parent-route-container.route-scroll-container.h5AVrOfS > div.jRsgdw_0 > div > div.Cts4MhxF > ul.hGOUffE7`).each(function(){
            if ($(this).text().indexOf(`个作品未看`)>-1){
                //cc("white",$(this)[0]);
                $(this).hide();
            }
        })
        $(`#douyin-right-container > div.parent-route-container.route-scroll-container.h5AVrOfS > div.jRsgdw_0 > div > div.Cts4MhxF > div.P9IJmXNW`).each(function(){
            if ($(this).text().indexOf(`精选关注人`)>-1){
                //cc("white",$(this)[0]);
                $(this).hide();
            }
        })
        $(`#douyin-right-container > div > div > div >ul:eq(1)`).each(function(){
            cc("blue","删除非直播");
            cc("blue",$(this)[0]);
            $(this).remove();
        })
        //直播个数
        var lul=`#douyin-right-container > div.jRsgdw_0 > div > div.Cts4MhxF > ul`;
        if ($(lul).length <1){
            lul=`#douyin-right-container > div.parent-route-container.route-scroll-container.h5AVrOfS > div.jRsgdw_0 > div > div.Cts4MhxF > ul.QTHs3MFv.zzJBL64E`;
        }
        if ($(lul).html()==h && sortdone==1){return;}
        livecount=$(lul+` > li`).length;
        if(livecount>0){
            cc("blue","当前直播个数:",livecount);
            cc("blue","排序次数:",sortdone);

            var h1="";
            var h2="";
            var h3="";
            var h4="";
            var ho="";
            $(lul+` > li`).each(function(){

                //cc("white","T ",$(this)[0]);
                let find=0;
                let fl = $(this).find("a").attr("href");
                let oh = $(this)[0].outerHTML;
                if (typeof fl !== "undefined"){
                }else{
                    fl = $(this).children("div.frvzAIi8").children("a").attr("href");
                    if (typeof fl !== "undefined"){
                    }else{
                        return
                    }
                }
                //cc("white","判断 ",fl)
                for (let x=0;x<zz.length;x++){
                    if(zz[x] != ""){
                        if (fl.indexOf(zz[x])>-1){
                            find=1;
                            break;
                        }
                    }
                }
                if (find){
                    h1=h1+oh;
                    //cc("white","加1 ",fl)
                    return
                }

                for (let x=0;x<zzb.length;x++){
                    if(zzb[x] != ""){
                        if (fl.indexOf(zzb[x])>-1){
                            find=1;
                            break;
                        }
                    }
                }
                if (find){
                    h2=h2+oh;
                    //cc("white","加2 ",fl)
                    return
                }
                if (oh.indexOf("福袋")>0){
                    h3=h3+oh;
                    //cc("white","加2 ",fl)
                    return
                }
                if (oh.indexOf("红包")>0){
                    h4=h4+oh;
                    //cc("white","加2 ",fl)
                    return
                }
                ho=ho+oh;
                //cc("white","加3 ",fl)
            })
            h=h1+h2+h3+h4+ho;
            if (h!=""){
                cc("blue","重新排序后");
                cc("blue",h);
                sortdone=1;
                $(lul).html(h);
            }
        }else{
            if (h0!=""){
                $(`#douyin-right-container`).html(h0);
                return
            }
        }
        livecount=$(lul+` > li`).length;
        if (livecount>0 && lastindex==0){
            h0=$(`#douyin-right-container`).html();
            cc("blue","直播个数",livecount);
            clearInterval(liveheight);
            lastindex=1;
            liveheight=setInterval(livesort,5000);
        }

    }

    function payhide(){
        ispayhide = 1-ispayhide;
        if (ispayhide){
            cc("red","隐藏支付");
            let wdstyle = document.createElement('style');
            wdstyle.classList.add("payhide");
            wdstyle.innerHTML = `
                div.aqK_4_5U{display:none !important}
                `
            document.body.appendChild(wdstyle);
        } else {
            cc("green","显示支付");
            $(`style.payhide`).remove();
        }
    }
    function pagefullscreen(){
        var is=0;
        //$(`#slidelist > div > div.swiper-wrapper > div.swiper-slide-active xg-icon.xgplayer-page-full-screen > div.xgplayer-icon`).click();
        $(`#sliderVideo xg-icon.xgplayer-page-full-screen > div.xgplayer-icon`).each(function(){
            haspagefullscreen=1;
            $(this).click();
            is=1;
            if (is){return}
            cc("blue","非推荐");
            $(`xg-controls xg-icon>div > div:nth-child(2)`).each(function(){
                if ($(this).parent().text().indexOf("网页全屏")<0)return;
                //cc("white","判断:",$(this).text(),"  ",$(this)[0]);
                haspagefullscreen=1;
                $(this).click();
            })
        })
        if (is){return}
        $(`div[data-e2e="living-container"] xg-icon>div>div`).each(function(){
            if ($(this).parent().text().indexOf("网页全屏")<0)return;
            //cc("white","判断:",$(this).text(),"  ",$(this)[0]);
            haspagefullscreen=1;
            $(this).click();
        })

    }
    var firstfullscreen=setInterval(function(){
        if (haspagefullscreen){
            clearInterval(firstfullscreen);
            return;
        }
        pagefullscreen();
    },1000);

    setInterval(function(){
        filtergift();
    },1000);

    function filtergift(){ //过滤直播礼物
        $(`div.webcast-chatroom___item.webcast-chatroom___enter-done,xg-danmu>div`).each(function(){
            var currentDate = new Date();
            var currentTime = currentDate.toLocaleString();
            if ($(this).text().indexOf("送出")>-1 || $(this).text().indexOf("送给")>-1 || $(this).text().indexOf("为主播加了")>-1){

                cc("white",$(this).text().replace(/\n/g, " ").replace(/\s\s/g, " ")+" "+currentTime);
                $(this).remove();
            }
            if ($(this).text().indexOf("想听")>-1 ||$(this).text().indexOf("刚刚升级至")>-1 ||   $(this).text().indexOf("成为在线观众TOP")>-1 || $(this).text().indexOf("推荐直播给")>-1 || $(this).text().indexOf("成功冠名了")>-1 || $(this).text().indexOf("恭喜主播成功点亮了")>-1){
                $(this).remove();
            }
        })
    }

    function addCSS(){
        let wdstyle = document.createElement('style');
        wdstyle.classList.add("optimize");
        wdstyle.innerHTML = `
div.gNyVUu_s, .OaNxZqFU img, .iRX47Q8q img,.Ng_nLvWy img,#sliderVideo > div.Mtz1OJlG.v0tRQvoe,div > div.eVtiBTlw > img,#slideMode > div.Mtz1OJlG.v0tRQvoe > img,.Mtz1OJlG img{ display: none!important }
.yP48EXrf .PzYA0Lei,._fmQtZIm .TWYv_EXn .I7uTRbqE{text-overflow: clip !important;}
.gKxBg4JL{box-shadow: none !important}
.qdcce5kG .VFMR0HAe,:root[update-header="2"] .qlkbkha_,div.search-horizontal-new-layout,#search-content-area div.GwBBBRKQ,#douyin-right-container,#chatroom > div.c6LJxjPr.unset-border > div.kz8VfOyK.Qsns7NdQ > div.Mv2estbj{ background: #0000 !important }
.vLt8mbfQ .y8iJbHin .mMOxHVzv, .vLt8mbfQ .y8iJbHin .rrKCA47Q, div.webcast-chatroom, .BasEuG5Q ._QjzkgP3, .OaNxZqFU,.basicPlayer.xgplayer,div.aqK_4_5U,.iSgCRqVf,.aEzDlumt .KhphjUgd.lG3F75Kf.anFLc8TW,.D9gH9oLs,html[dark] .lfsfx_uh .GE_yTyVX,.Pw3CDvJ,.aEzDlumt .xKQnHfmH.anFLc8TW,.Pw3CDvJg,#search-content-area > div,.MBk4_p5s .GbSnpgWT,.gvxFUQjb,.MBk4_p5s.qEhBiSX7, .MBk4_p5s.ikIdCJZa,.Z0XYsCxp .d8cD2XWD,.aEzDlumt .YN9VhGo7{background: #000 !important }
body,.Npz7CPXj, div.webcast-chatroom .webcast-chatroom___input-container .webcast-chatroom___textarea, .CgAB9miy, .JTIGfG2P, .NQ38Bc0h .XcEg0PrM, .N_HNXA04:not(.dUiu6B8O) .iViO9oMI, .UKFpY5tW, .SxCiQ8ip .EDvjMGPs,.SxCiQ8ip .A0ewbQCI,.fpRIB_wC,div.tgMCqIjJ, div.tgMCqIjJ.isDark,.sELpHy0M.metro .lgs6xhy7 .slot-item:hover,.sELpHy0M.metro .B9p3ney8:hover,.sELpHy0M.metro .UjStUCgW ._BSUxMOF:hover,.SxCiQ8ip.V6Va18Np,.qlkbkha_,.SxMeCeGo.UdVKTDud .gjQTl671,.h9wtZ0fY.metro .wtNw_CDe:hover,.h9wtZ0fY.metro .Pg8ernIx .slot-item:hover,.h9wtZ0fY.metro .fIHFYwJt .Y4MTL_BH:hover,.SxMeCeGo .DFH1PTN6,.gjQTl671,.EexPxRCK.cc1_mSqr.Bhtzbjo2,.aEzDlumt .jscIDlNp,.aEzDlumt .jscIDlNp.anFLc8TW,#slidelist,.X5syc51M.yWR42jR6,.EexPxRCK .Rr56zkD1,.gjQTl671 .c6LJxjPr,#island_e62be > div,.Qsns7NdQ{ background: #111 !important }
.N_HNXA04:not(.dUiu6B8O) .kQ2JnIMK .n9PPTk22, .N_HNXA04 .kQ2JnIMK, .iwzpXgQ3 .oJArD0aS, .xWPMYXKp .gOSlkVoB, .Exz5X5r1,.R5ITbXfy .k5cuEeRD,.sELpHy0M.metro .lgs6xhy7 .slot-item,.sELpHy0M.metro .B9p3ney8,.sELpHy0M.metro .UjStUCgW ._BSUxMOF,.N_HNXA04 .kQ2JnIMK .YrFhKzRI,.kuew7rkS .HaiBJL6n,.h9wtZ0fY.metro .wtNw_CDe,.h9wtZ0fY.metro .Pg8ernIx .slot-item,.h9wtZ0fY.metro .fIHFYwJt .Y4MTL_BH,._0QL2JpzH,#component-navigation,.J6zKCgYE{ background: #222 !important }
div.JwGiJkkI, div.xgplayer-dynamic-bg, div.umOY7cDY, div.ruqvqPsH,footer,:root[dark] .B6M32uoI,:root[dark] .KHZgK2KB,:root[dark] .YpFJLpHw{ display: none !important }
.L8o4Hyg1,.L8o4Hyg1 .LFbb1oon,.L8o4Hyg1 .R6NHkCAw .i4vdvOF5{ box-shadow: none !important; border-bottom: none !important; border-right: none !important; }
.N_HNXA04:not(.JVPLvXh3) .iViO9oMI,.N_HNXA04 .HQwsRJFy,.lXuWkeYW, .lXuWkeYW .oJArD0aS{height:60px !important}
.pgQgzInF.hqONwptG .Jf1GlewW.Ox89VrU5, .ckEyweZa.AmXnh1GR .QICHGW7r.RosH2lNv, .SxCiQ8ip.V6Va18Np .EDvjMGPs.FKQqfehj { height: 100% !important; }
:root[update-header="1"] .JTIGfG2P, :root[update-header="2"] .JTIGfG2P, :root[update-header="3"] .JTIGfG2P{padding: 0 0 0 0;}
.SxCiQ8ip .EDvjMGPs .nUwhpww3.E2QLXZIv,.SxMeCeGo .DFH1PTN6 ._uuQkdQj._J11W6D7{padding-top: 0px !important;}
div.immersive-player-switch-on-hide-interaction-area, #video-info-wrap, xg-inner-controls.xg-inner-controls { opacity: 0.6 !important }
.xgplayer-playswitch .xgplayer-playswitch-tab { opacity: 0 !important }
div.xgplayer-playswitch-tab:hover, div.immersive-player-switch-on-hide-interaction-area:hover, #video-info-wrap:hover, xg-inner-controls.xg-inner-controls:hover { opacity: 1 !important }
.mUQC4JAd .LU6dHmmD{color:#bbb}
`
    document.body.appendChild(wdstyle);
    }
    addCSS();
    ispayhide=0;
    payhide();

    //为直播页面时 尝试设置为最高清晰度
    var setdefinition=setInterval(function(){
        var curdefinition="",highestdefinition="",find=0;
        if (location.href.indexOf("https://live.douyin.com/")>-1){
            //直播页面
            $(`#_douyin_live_scroll_container_ xg-controls div[data-e2e="quality"]`).each(function(){
                curdefinition=$(this).text();
            })
            $(`#_douyin_live_scroll_container_ xg-controls div[data-e2e="quality-selector"] > div`).each(function(){
                highestdefinition=$(this).text();
                if ((highestdefinition.indexOf("登录即享")>-1 && highestdefinition.indexOf("高清")<0) || find>0){
                    return
                }
                if (highestdefinition!=""){
                    cc("white","当前清晰度 ",curdefinition," 可选最高",highestdefinition);
                    if(highestdefinition.indexOf(curdefinition)<0){
                        console.log("点击 ",$(this)[0]);
                        $(this).click();
                    }else{
                        clearInterval(setdefinition);
                    }
                    find = 1;
                }
            })
        }else{
            //视频页面
            $(`xg-controls xg-icon.xgplayer-playclarity-setting > div > div.btn`).each(function(){
                curdefinition=$(this).text();
            })
            $(`xg-controls xg-icon.xgplayer-playclarity-setting > div > div.virtual >div`).each(function(){
                highestdefinition=$(this).text();
                if ((highestdefinition.indexOf("登录即享")>-1 && highestdefinition.indexOf("清晰")<0) || find>0){
                    return
                }
                if (highestdefinition!=""){
                    cc("white","当前清晰度 ",curdefinition," 可选最高",highestdefinition);
                    if(highestdefinition.indexOf(curdefinition)<0){
                        console.log("点击 ",$(this)[0]);
                        $(this).click();
                    }else{
                        clearInterval(setdefinition);
                    }
                    find = 1;
                }
            })
        }
    },1000)

    var lingjiang;
    if (location.href.indexOf("live.douyin.com/")>-1){
        lingjiang=setInterval(function(){
            var lofind=0;
            var currentDate = new Date();
            var currentTime = currentDate.toLocaleString();
            var currentms = new Date().getTime();
            $(`#lottery_close_cotainer`).each(function(){
                if ($(this).text().indexOf("倒计时")>-1 || $(this).text().indexOf("加载中")>-1){
                    lofind=1;
                    $(this).find(`div[role="button"]`).each(function(){
                        if ($(this).text().indexOf("一键发评论参与福袋")>-1){
                            $(this).click();
                        }
                    })
                    return
                }
                if ($(this).text().indexOf("没抽中福袋")>-1){
                    cc("yellow","没抽中福袋 ",currentTime);
                    $(this).find(`div[role="button"]`).each(function(){
                        if ($(this).text().indexOf("知道了")>-1){
                            $(this).click();
                        }
                    })
                    return
                }
                lofind=1;
                cc("yellow",$(this).text()," ",currentTime);
                if (currentms-lct>5000){
                    $(this).find(`div > div > div.YnybGvCL`).click();
                    lct=currentms
                }
            })
            if (lofind==0){
                //未找到礼物窗口,寻找

                if (currentms-lct>5000){
                    //console.log(currentDate,lct);
                    $(`#living_room_player_container div.i7fQOuPe>pace-island>div.ZOCwtrnX`).each(function(){

                        if ($(this).text().indexOf(":")>-1 && !$(this).attr('id')){
                            console.log("点击",$(this)[0]);
                            $(this).click();
                            lct=currentms;
                            wt=$(this).text().split(":");
                            wt=wt[0]*60+wt[1]*1;
                            console.log("等待 ",wt," 秒");
                            lct=currentms+wt*1000-6000;
                            console.log("至",timestampToDatetime(lct));
                        }
                    })
                }

                $(`body > div > div > div > div.elw1KV8O > div.JL05k7eS.OG51D9OO`).each(function(){
                    if ($(this).text().indexOf("继续播放")>-1){
                        console.log("点击",$(this)[0]);
                        $(this).click();
                    }
                })

            }
        },1000)

    }

},1)


function timestampToDatetime(timestamp) {
    const dateObj = new Date(timestamp);

    const year = dateObj.getFullYear();
    const month = dateObj.getMonth() + 1;
    const day = dateObj.getDate();
    const hours = dateObj.getHours();
    const minutes = dateObj.getMinutes();
    const seconds = dateObj.getSeconds();

    return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
}