Greasy Fork is available in English.

哔哩哔哩Mylist助手

使哔哩哔哩MyList功能再次可用,可创建MyList列表或编辑列表及列表中视频。

Fra 02.10.2017. Se den seneste versjonen.

// ==UserScript==
// @name         哔哩哔哩Mylist助手
// @namespace    undefined
// @version      0.1.0
// @description  使哔哩哔哩MyList功能再次可用,可创建MyList列表或编辑列表及列表中视频。
// @author       点灯 diandeng
// @match        *://member.bilibili.com/*
// @match        *://member.bilibili.com/mylist_manage.html*
// @match        *://www.bilibili.com/mylist*
// @match        *://www.bilibili.com/*
// @require      https://code.jquery.com/jquery-latest.js
// @run-at       document-start
// @icon 		 https://www.bilibili.com/favicon.ico
// @supportURL   http://space.bilibili.com/21219957
// ==/UserScript==
(function() {
	'use strict';
	//防止网页白底蓝字
	var url = window.location.host;
	if('https:' == document.location.protocol && 'member.bilibili.com' == window.location.host) {
		url = 'http://' + url;
		window.location.href = url;
	}
	//屏蔽消息框和遮盖
	document.head.innerHTML += "<style type='text/css'>.messagebox {display: none;}.wnd-mask {display: none;} </style>";
	var a = 0;
	var b = 0;
	var c = 0;
	var d = 0;
	var e = 0;
	var f = 0;
	//检测网页是否加载完成,并向一些元素添加事件
	var code = setInterval(function() {
		if($('#btn_create_mylist').length > 0 && a === 0) {
			$("#btn_create_mylist").click(function() {
				addMylist();
			});
			a = 1;
		}
		if($('#btn_avAddToList').length > 0 && b === 0) {
			$("#btn_avAddToList").click(function() {
				addVideo();
			});
			b = 1;
		}
		if($('#btn_updateList').length > 0 && c === 0) {
			$("#btn_updateList").click(function() {
				editVideo();
			});
			c = 1;
		}
		if($("#description").length > 0 && d === 0) {
			$("#description").append("<br><a id='add-watchlater' href='javascript:;'>一键加入到稍后再看</a>");
			$("#add-watchlater").click(function() {
				addWatchlater();
			});
			d = 1;
		}
		if($("#author").length > 0 && e === 0) {
			var mid = $("#author a").attr("href");
			var n = mid.indexOf("/", 10);
			var m = mid.length;
			mid = mid.substring(n + 1, m);
			$.ajax({
				url: "http://space.bilibili.com/ajax/member/GetInfo",
				type: "POST",
				dataType: "json",
				data: "mid=" + mid + "&csrf=" + getCookie("bili_jct"),
				success: function(data) {
					$("#author a").text(data.data.name);
				}
			});
			e = 1;
		}
		if($(".z_top .z_top_nav ul").length > 0 && f === 0) {
			$(".z_top .z_top_nav ul").append("<li class='old-home'><a class='i-link' target='_blank' href='http://member.bilibili.com/#main' title='旧版主页'>旧版主页</a></li>");
			f = 1;
		}
		//防止计时器一直处于激活状态,占用系统资源
		if((a === 1 && f === 1) || (b === 1 && c === 1 && f === 1) || (d === 1 && e === 1 && f === 1)) {
			clearInterval(code);
		}
	}, 500);
	//添加 Mylist 列表
	function addMylist() {
		var text = $('#mylist_create').serialize();
		$.ajax({
			url: "http://member.bilibili.com/mylist_manage.do?do=add&output=json",
			type: "POST",
			dataType: "json",
			data: text + "&csrf=" + getCookie("bili_jct"),
			success: function(data) {
				if(data === null) {
					alert("未知的错误");
					return;
				}
				if(data.code == -1 || data.code === 0) {
					alert(data.msg);
				} else {
					alert(data);
				}
			},
			error: function() {
				alert("网络错误,请稍后重试");
			}
		});
	}
	//添加视频到 Mylist 列表
	function addVideo() {
		var text = $("#frm_addtoList").serialize();
		$.ajax({
			url: "http://member.bilibili.com/mylist_manage.do?do=addstow&output=json",
			type: "POST",
			dataType: "json",
			data: text + "&csrf=" + getCookie("bili_jct"),
			success: function(data) {
				if(data === null) {
					alert("未知的错误");
					return;
				}
				if(data.code == -1 || data.code === 0) {
					alert(data.msg);
				} else {
					alert(data);
				}
			},
			error: function() {
				alert("网络错误,请稍后重试");
			}
		});
	}
	//编辑 Mylist 列表的视频优先级
	function editVideo() {
		var lid = $(".next-title span:first-of-type").text();
		var text = $("#frm_myList").serialize();
		lid = lid.substring(1, lid.length);
		$.ajax({
			url: "http://member.bilibili.com/mylist_manage.do?do=editstow&lid=" + lid + "&output=json",
			type: "POST",
			dataType: "json",
			data: text + "&csrf=" + getCookie("bili_jct"),
			success: function(data) {
				if(data === null) {
					alert("未知的错误");
					return;
				}
				if(data.code == -1 || data.code === 0) {
					alert(data.msg);
				} else {
					alert(data);
				}
			},
			error: function() {
				alert("网络错误,请稍后重试");
			}
		});
	}
	//将 Mylist 列表的视频添加到稍后再看
	function addWatchlater() {
		var n = playlist.length;
		for(var i = 0; i < n; i++) {
			$.ajax({
				url: "http://api.bilibili.com/x/v2/history/toview/add",
				type: "POST",
				dataType: "json",
				async: false,
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				/*n - i - 1是为了倒序添加稍后再看,使顺序与 Mylist 列表一致*/
				data: "aid=" + playlist[n - i - 1].aid + "&jsonp=jsonp&csrf=" + getCookie("bili_jct")
			});
		}
	}
	//获取Cookie
	function getCookie(e) {
		var o, t;
		var n = document,
			c = decodeURI;
		return n.cookie.length > 0 && (o = n.cookie.indexOf(e + "="), -1 != o) ? (o = o + e.length + 1, t = n.cookie.indexOf(";", o), -1 == t && (t = n.cookie.length), c(n.cookie.substring(o, t))) : "";
	}
})();