// ==UserScript==
// @name [bilibili]稍后再看导出为.url
// @namespace wdssmq.com
// @version 0.1
// @description 将B站的稍后再看列表导出为.url文件
// @author 沉冰浮水
// @url
// @include https://www.bilibili.com/watchlater/*
// @include https://www.bilibili.com/video/av*
// @include https://www.bilibili.com/bangumi/play/ep*
// @include https://manga.bilibili.com/account-center*
// @icon https://www.bilibili.com/favicon.ico
// @run-at document-end
// @grant GM_setClipboard
// @downloadURL none
// ==/UserScript==
/* jshint esversion:6 */
(function() {
"use strict";
const $ = unsafeWindow.jQuery;
//const pic = unsafeWindow.__INITIAL_STATE__.videoData.pic;
//if (pic){
//console.log(pic);
//}
function $n(e) {
return document.querySelector(e);
}
function $na(e) {
return document.querySelectorAll(e);
}
function fnCopy(eTrig, vSoF,eList) {
if (!$n(eTrig)) {
return;
}
$n(eTrig).addEventListener("click", function(e) {
let content = typeof vSoF === "function" ? vSoF($na(eList)) : vSoF;
console.log(content);
GM_setClipboard(content);
this.style.color = "gray";
});
}
function fnMKShell($list) {
const today = new Date(); //获得当前日期
const year = today.getFullYear(); //获得年份
const month = today.getMonth() + 1; //此方法获得的月份是从0---11,所以要加1才是当前月份
const day = today.getDate(); //获得当前日期
const arrDate = [year, month, day];
let strRlt =
'if [ ! -d "bilibililater-foldername" ]; then\n' +
"mkdir bilibililater-foldername\n" +
"fi\n" +
"cd bilibililater-foldername\n";
strRlt = strRlt.replace(/foldername/g, arrDate.join("-"));
$list.forEach(function(e) {
// alert(1);
console.log(e);
let strTitle = e.textContent.replace(/\\|\/|:|\*|!|\?]|<|>/g, "");
let strUrl = e.href;
if (strUrl) {
strUrl = strUrl.replace(/watchlater\/#/g, "video");
strUrl = strUrl.replace(/\/p1/g, "");
} else {
console.log(strTitle);
return;
}
strRlt += 'echo [InternetShortcut] > "' + strTitle + '.url"\n';
strRlt += 'echo "URL=' + strUrl + '" >> "' + strTitle + '.url"\n';
});
strRlt += "exit\n\n";
strRlt = strRlt.replace(/\/\/\//g, "//www.bilibili.com/");
//console.log(strRlt);
return strRlt;
//$("body").innerHTML = strRlt.replace(/\n/g, "
");
}
(function() {
if (/#\/list|#\/video/g.test(location.href)) {
fnCopy("span.t", fnMKShell,".cube-list li a.title,.av-about .t");
return false;
}
})();
(function() {
if (location.hash === "#/my-favourite") {
let f = 0;
document.addEventListener(
"mouseover",
function(e) {
if (f) {
return false;
}
let $magList = $na("div.text-info-section a:first-child");
console.log($magList);
if ($magList.length) {
f = 1;
fnCopy("h1.page-title", fnMKShell,"div.text-info-section a:first-child");
}
},
false
);
return false;
}
})();
(function() {
// watchlater
if (location.href.indexOf("watchlater/#/av") > -1) {
location.href = location.href
.replace("watchlater/#", "video")
.replace("/p", "?p=");
return false;
}
})();
// 时间轴书签
function fnGenUrl(url) {
let more = 0;
if ($n(".watched.on")){
url = $n(".watched.on a").href;
more =1;
}
if ($n(".bilibili-player-video-time-now")) {
let strQurey = document.location.search;
let matchRlt = strQurey.match(/t=(\d+)/);
//console.log(matchRlt);
let oldTime = matchRlt && matchRlt[1] ? matchRlt[1] : 0;
if (more){
url = url + "&";
} else {
url = url.split("?")[0] + "?";
}
let arrTime = $n(".bilibili-player-video-time-now").innerText.split(":");
let t = parseInt(arrTime[0]) * 60 + parseInt(arrTime[1]) - 7;
// console.log(oldTime,t);
if (t - oldTime <= 73) {
return url;
}
let title = $n("h1.video-title").title;
let nURL = `${url}?t=${t}`;
$n("title").innerHTML = `${title}_${t}_bilibili`;
//$n("h1.video-title").innerHTML = `${title}_${t}`;
window.history.pushState(null, null, `${url}t=${t}`);
return url;
}
return url;
}
let url = document.location.href.replace("?tdsourcetag=s_pctim_aiomsg", "");
console.log(url);
document.addEventListener(
"mouseover",
function(e) {
//console.log(
//e.target,
//e.target.nodeName,
//e.target.className || "class为空"
//);
// 实际代码
if (e.target.nodeName === "VIDEO") {
url = fnGenUrl(url);
}
},
false
);
})();