【伟哥自用】salttiger电子书网盘提取码合成
// ==UserScript==
// @name 【伟哥自用】salttiger电子书网盘提取码合成
// @namespace http://tampermonkey.net/
// @version 0.11
// @description try to take over the world!
// @author You
// @match https://salttiger.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=salttiger.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
function AddpanButton(url,infoarea){
let btn = document.createElement("button");
btn.innerHTML = "直达网盘";
btn.onclick = function(){
window.open(url);
}
infoarea.append(btn);
}
function detectBaidupan(){
/** 针对https://salttiger.com/pandas-in-action/ 这里面超链接也有pan,所以匹配整个'pan.baidu.com'*/
let baidupan = document.querySelector("a[href*='pan.baidu.com']").href;
/** https://stackoverflow.com/questions/31773599/can-i-use-an-attribute-selector-for-contains-in-queryselector
* Pattern Represents
* E[foo*="bar"] An E element whose foo attribute value contains the substring bar.
*/
return baidupan;
}
function fucksharecode(){
let baidupan = detectBaidupan();
let infoarea = document.querySelector("a[href*='pan.baidu.com']").parentNode;
let textarr = infoarea.textContent.split("\n")
if(!(typeof infoarea === 'undefined') & textarr.length==4){
let sharecode = textarr[3].split(":")[1];/** eg.'提取码 :edxh'*/
let url = baidupan+"&pwd="+sharecode;/**带提取码的百度网盘链接 */
console.log(url)
AddpanButton(url,infoarea);
}/* sometimes, sharecode is not listed and there is no need to combine them*/
}
function isDetailPage(){
let isdetailpage = false;
try{
if(!(typeof detectBaidupan() === 'undefined')){
isdetailpage = true;
}
}catch(err){}
return isdetailpage;
}
if(isDetailPage()==true){/** book detail */
fucksharecode();
}
})();
/**
* ==================================================================================================
* A UserScript to combine pan.baidu.com and sharecode on salttiger.com
* ==================================================================================================
* 本脚本只针对salttiger.com图书详情页中的百度网盘链接处理
* 在salttiger.com这个电子书分享网站上,百度网盘的链接有时候不带提取码,例如这个页面:
* https://salttiger.com/principles-of-web-api-design/
* 本脚本的功能就是把salttiger网站里提取码弄进百度网盘链接,并且加个按钮直达,对于那些
* 网盘链接里本身自带提取码的,就没必要加,salttiger最近的分享基本都不需要
*/