B站稍后再看归位

它进收藏啦,被我搞出来啦,有什么好说哒

当前为 2021-09-30 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         B站稍后再看归位
// @namespace    https://greasyfork.org/zh-CN/users/412840-newell-gabe-l
// @version      1.2.6
// @description  它进收藏啦,被我搞出来啦,有什么好说哒
// @author       Pronax
// @match        *://*.bilibili.com/*
// @exclude      *://live.bilibili.com/*
// @require      https://code.jquery.com/jquery-1.12.4.min.js
// @noframes
// @grant        GM_addStyle
// ==/UserScript==

(function () {
    'use strict';
    // 视频页面稍后再看按钮css
    GM_addStyle("#van-popover-watch-later .ops-watch-later.van-watchlater{top:4px;right:25px}#van-popover-watch-later .rigth-btn{margin-right:20px;}");
    // 进度条css
    GM_addStyle("#van-popover-watch-later .wl-progress-bar{width:0;height:3px;background-color:#ff74a5;position:absolute;bottom:-2px}");
    // 时长css
    GM_addStyle("#van-popover-watch-later .duration-tag{left: 6px;position: absolute;background: rgba(0, 0, 0, 0.5);bottom: 4px;font-size: 12px;border-radius: 1px;padding: 0px 2px;color: #fff;}");
    // 删除图标css
    GM_addStyle("#van-popover-watch-later .watchlist-item-img-del{display:none;position:absolute;right:2px;bottom:4px;padding:2px;width:20px;height:20px;-webkit-box-sizing:border-box;box-sizing:border-box;background:rgba(0,0,0,.5);border-radius:2px;cursor:pointer}#van-popover-watch-later .watchlist-item-img-del:hover{background:#000}");
    // 视频信息css
    GM_addStyle("#van-popover-watch-later .line-2{min-height:42px;}");
    // bilibili自带css
    GM_addStyle("#van-popover-watch-later{width:370px;transform-origin:center top;z-index:2009;position:absolute;top:40px!important;left:-270%;display:none;box-shadow: rgb(0 0 0 / 20%) 0px 10px 6px 2px !important;}#van-popover-watch-later .vp-container{position:relative;display:flex;justify-content:space-between;width:100%;min-width:0;height:518px}#van-popover-watch-later .favorite-video-panel{padding-top:0;height:100%}#van-popover-watch-later .favorite-video-list{overflow-y:auto;width:370px;height:480px;overscroll-behavior:none}#van-popover-watch-later .header-video-card{display:flex;flex-shrink:0;padding:8px 5px 8px 20px;height:77px;cursor:pointer;transition:.3s ease}#van-popover-watch-later .header-video-card .multiple-preview{width:108px;height:61px}#van-popover-watch-later .header-video-card .video-preview{position:relative;text-align:center}#van-popover-watch-later .header-video-card .video-info{display:flex;flex-direction:column;flex-shrink:0;justify-content:space-between;margin-left:12px}#van-popover-watch-later .header-video-card .video-info .line-2{max-width:210px;height:37px;color:#212121;font-weight:500;font-size:14px;display:-webkit-box;overflow:hidden;-webkit-box-orient:vertical;text-overflow:-o-ellipsis-lastline;text-overflow:ellipsis;word-break:break-all;-webkit-line-clamp:2}#van-popover-watch-later .header-video-card .video-info .info{display:flex;color:#999;font-size:12px}#van-popover-watch-later .play-view-all{display:flex}#van-popover-watch-later .play-all.view{color:#212121}#van-popover-watch-later .play-all:hover{background-color:#f4f4f4}#van-popover-watch-later .play-all{bottom:0;display:block;display:flex;align-items:center;justify-content:center;width:100%;border-top:1px solid #e7e7e7;background-color:#fff;color:#00a1d6;line-height:45px;cursor:pointer;transition:.3s ease}#van-popover-watch-later .play-all .bilifont{margin-right:10px;color:#00a1d6!important;font-size:14px!important}");

    var watchLaterBtnTimeout;
    var lastUpdateTime;
    var watchLaterCountDown = 0;
    var watchLaterBtnCountDown = 0;

    var temp = '<div class="watch-later-video"><a href="" target="_blank" class="header-video-card"><div class="video-preview multiple-preview"><div class="video-card-img"><img src="" alt="" class="default-img"><div class="wl-progress-bar"></div><div class="duration-tag"></div><div class="watchlist-item-img-del"><span class="svgicon-r"><svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M5.4 11.652a.878.878 0 001.757 0V6.46a1 1 0 00-.879-.99c-.49.082-.856.495-.878.99v5.192zm3.514 0c0 .485.393.877.879.877a.826.826 0 00.878-.877V6.46a.983.983 0 00-.878-1c-.494.083-.86.501-.879 1v5.192zm5.324-7.139H13.21v8.946a1.43 1.43 0 01-1.317 1.535H4.354a1.458 1.458 0 01-1.59-1.544V4.513h-.975a.877.877 0 01-.782-.877.78.78 0 01.672-.876H5.4v-.948a.702.702 0 01.782-.807h3.61a.703.703 0 01.783.781v.974h3.61a.782.782 0 01.809.876.877.877 0 01-.756.877z" fill="#FFF" fill-rule="evenodd"></path></svg></span></div></div></div><div class="video-info"><div title="" class="line-2"></div><div class="info"><span class="up"></span></div></div></a></div>';

    window.addAddWatchLaterBtn = function () {
        let btn = $(".ops-watch-later.van-watchlater");
        if (btn.length == 0 && watchLaterBtnCountDown < 15) {
            watchLaterBtnCountDown++;
            setTimeout(() => addAddWatchLaterBtn(), 100);
            return;
        } else if (watchLaterBtnCountDown >= 30) {
        } else {
            $(".rigth-btn").append(btn.css({ "position": "relative", "bottom": "unset" }));
            $(".more-ops-list li")[1].remove();
        }
    }

    window.getCookie = function (objName) {//获取指定名称的cookie的值 
        var arrStr = document.cookie.split("; ");
        for (var i = 0; i < arrStr.length; i++) {
            var temp = arrStr[i].split("=");
            if (temp[0] == objName) {
                return decodeURI(temp[1]);
            }
        }
    }

    window.loadWatchLater = function () {
        let c = $(".user-con.signin").children();
        if (c.length == 0 && watchLaterCountDown < 30) {
            watchLaterCountDown++;
            setTimeout(() => loadWatchLater(), 100);
            return;
        } else if (watchLaterCountDown >= 30) {
            console.log("加载稍后再看失败,你可能没有登录,或者你太卡了花了3秒都没有加载出页面");
            console.log("当然了,如果这个页面本身不适合加入稍后再看按钮,而你又看见了这条信息,恭喜你找到了一个bug,欢迎反馈给我");
        } else {
            let t = c[3];
            $(t).after($('<div class="item"><span><div class="mini-toview" tabindex="0"><span><span class="name">稍后再看</span></span><div role="tooltip" id="van-popover-watch-later" aria-hidden="true" class="van-popover van-popper van-popper-favorite" tabindex="0"><div  class="vp-container"><div  class="favorite-video-panel"><div  class="favorite-video-list watch-later-list"></div><div data-v-a1b2c3d4 class="play-view-all"><a data-v-a1b2c3d4 href="//www.bilibili.com/watchlater/#/list" target="_blank" class="play-all view">查看全部</a><a data-v-a1b2c3d4 href="//www.bilibili.com/medialist/play/watchlater" target="_blank" class="play-all"><i data-v-a1b2c3d4 class="bilifont bili-icon_dingdao_bofang"></i>播放全部</a></div></div></div></div></div></span></div>'));
            $(".mini-toview").click(() => {
                window.open("https://www.bilibili.com/watchlater/#/list");
            }).mouseenter(function () {
                clearTimeout(watchLaterBtnTimeout);
                watchLaterBtnTimeout = setTimeout(() => {
                    $("#van-popover-watch-later").stop().fadeIn(200);
                    if ((!lastUpdateTime) || new Date().getTime() - lastUpdateTime >= 30000) {
                        lastUpdateTime = new Date().getTime();
                        $.ajax({
                            xhrFields: { withCredentials: true },
                            crossDomain: true,
                            url: "https://api.bilibili.com/x/v2/history/toview/web?jsonp=jsonp",
                            dataType: "json",
                            success: function (r) {
                                if (r.code == 0) {
                                    let list = r.data.list;
                                    for (let i = 0; i < list.length; i++) {
                                        let tar = $(temp);
                                        let a = tar.find(".header-video-card");
                                        a.attr("href", list[i].uri)
                                            .attr("data-bvid", list[i].bvid)
                                            .click(function (e) {
                                                if (e.ctrlKey) {
                                                    e.preventDefault();
                                                    window.open("https://www.bilibili.com/video/" + this.dataset.bvid);
                                                }
                                            });
                                        // https://www.bilibili.com/medialist/play/watchlater/
                                        // https://www.bilibili.com/video/
                                        tar.find(".default-img").attr("src", "https" + list[i].pic.substr(4) + "@112w_63h_1c_100q.webp");
                                        if (list[i].progress != 0) {
                                            tar.find(".wl-progress-bar").width(list[i].progress / list[i].duration * 100 + "%");
                                        }
                                        // todo 处理css
                                        if (list[i].videos != 1) {
                                            tar.find(".duration-tag").text(list[i].videos + "P");
                                        } else {
                                            let s = list[i].duration % 60;
                                            let m = Math.floor(list[i].duration / 60 % 60);
                                            let h = Math.floor(list[i].duration / 3600);
                                            tar.find(".duration-tag").text((h == 0 ? "" : h < 10 ? "0" + h + ":" : h + ":") + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s));
                                        }
                                        tar.find(".watchlist-item-img-del").data("bvid", list[i].bvid);
                                        tar.find(".line-2").text(list[i].title).attr("title", list[i].title);
                                        tar.find(".up").text(list[i].owner.name);
                                        $(".watch-later-list:first").append(tar);
                                    }
                                    $(".watch-later-video").click(function (e) {
                                        e.stopPropagation();
                                    }).mouseenter(function () {
                                        $(this).find(".line-2").css("color", "#00a1d6");
                                        $(this).find(".watchlist-item-img-del").show();
                                    }).mouseleave(function () {
                                        $(this).find(".line-2").css("color", "");
                                        $(this).find(".watchlist-item-img-del").hide();
                                    });
                                    $(".watchlist-item-img-del").click(function (e) {
                                        let targ = this;
                                        e.preventDefault();
                                        $.ajax({
                                            url: "https://api.bilibili.com/x/v2/history/toview/del",
                                            type: "POST",
                                            xhrFields: { withCredentials: true },
                                            crossDomain: true,
                                            data: { "jsonp": "jsonp", "bvids": $(targ).data("bvid"), "csrf": getCookie("bili_jct") },
                                            dataType: "json",
                                            success: function (r) {
                                                if (r.code == 0) {
                                                    $(targ).parents(".watch-later-video").fadeOut(300);
                                                } else {
                                                    console.log("删除失败:", r.message);
                                                }
                                            },
                                            error: function (r) {
                                                console.log("删除失败:", r.message);
                                            }
                                        });
                                    });
                                    $(".play-view-all").click(function (e) { e.stopPropagation(); });
                                } else {
                                    console.log("加载稍后再看失败:", r.msg);
                                }
                            },
                            error: function (r) {
                                console.log("加载稍后再看失败:", r.msg);
                            },
                        });
                    }
                }, 200);
            }).mouseleave(function () {
                clearTimeout(watchLaterBtnTimeout);
                watchLaterBtnTimeout = setTimeout(() => {
                    $("#van-popover-watch-later").stop().fadeOut(100);
                }, 200);
            });
        }
    }

    setTimeout(() => {
        loadWatchLater();
        if (location.pathname.startsWith("/video/")) {
            addAddWatchLaterBtn();
        }
    }, 200);

})();