B站稍后再看归位

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

目前為 2021-03-19 提交的版本,檢視 最新版本

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

(function() {
	'use strict';

	var watchLaterBtnTimeout;
	var lastUpdateTiem;
	var watchLaterCountDown = 0;
	var watchLaterBtnCountDown = 0;

	var temp = '<div data-v-64b63b5f=""><a data-v-37582e0a="" data-v-64b63b5f="" href="" target="_blank" class="header-video-card"><div data-v-37582e0a="" class="video-preview multiple-preview"><div data-v-c05424d6="" data-v-37582e0a="" class="video-card-img"><img data-v-c05424d6="" src="" alt="" class="default-img"><div data-v-c05424d6=""><div class="wl-progress-bar" style="width: 0%;height: 3px;background-color: #ff74a5;position: absolute;bottom: 0;"></div><div data-v-c05424d6="" class="duration-tag"></div></div></div></div><div data-v-37582e0a="" class="video-info"><div data-v-37582e0a="" title="" class="line-2"></div><div data-v-37582e0a="" class="info"><span data-v-37582e0a="" 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").css("margin-right","20px").append(($(".ops-watch-later.van-watchlater").css({"top":"4px","right":"25px"})));
			$(".more-ops-list li")[1].remove();
		}
	}

	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" style="width: 370px;transform-origin: center top;z-index: 2009;position: absolute;top: 40px !important;left: -270%;display: none;"><div data-v-64b63b5f="" class="vp-container"><div data-v-64b63b5f="" class="favorite-video-panel" style="padding-top: 0px;"><div data-v-64b63b5f="" class="favorite-video-list watch-later-list"></div><div data-v-64b63b5f="" class="play-view-all"><a data-v-64b63b5f="" href="//www.bilibili.com/watchlater/#/list" target="_blank" class="play-all view">查看全部</a><a data-v-64b63b5f="" href="//www.bilibili.com/medialist/play/watchlater" target="_blank" class="play-all"><i data-v-64b63b5f="" 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((!lastUpdateTiem)||new Date().getTime()-lastUpdateTiem>=30000){
						lastUpdateTiem = 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);
										tar.find(".header-video-card").attr("href",list[i].uri);
										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+"%");
										}
										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(".line-2").text(list[i].title).attr("title",list[i].title).height("40px");
										tar.find(".up").text(list[i].owner.name);
										$(".watch-later-list").append(tar);
									}
								}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);

})();