-
Notifications
You must be signed in to change notification settings - Fork 0
/
baidupan_password_auto_set.user.js
98 lines (97 loc) · 3.51 KB
/
baidupan_password_auto_set.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// ==UserScript==
// @name 度盘密码自动化
// @namespace http://tampermonkey.net/
// @version 0.4
// @description 自动拼接密码到网址,点击过的高亮显示
// @author etng
// @match *://fanxinzhui.com/rr/*
// @match *://www.fanxinzhui.com/rr/*
// @match *://www.ghxi.com/*
// @match *://subs.kamigami.org/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=fanxinzhui.com
// @grant GM_notification
// ==/UserScript==
(function () {
'use strict';
var $ = unsafeWindow.jQuery;
var getTextNodes = function (root, keyword) {
if (!root) {
root = document.querySelector('body')
}
var textNodes = []
root.childNodes.forEach(node => {
var nodeType = node.nodeType;
if (nodeType == 3) {
if (!keyword || node.textContent.indexOf(keyword) >= 0) {
textNodes.push(node)
}
} else if ([1, 9, 11].indexOf(nodeType) >= 0) {
textNodes = textNodes.concat(getTextNodes(node, keyword))
}
})
return textNodes
};
var cnt = 0;
$('a[href^="https://pan.baidu"]').each((k, v) => {
var a = $(v);
var url = a.attr('href');
if (url.indexOf('?pwd=') == -1) {
var pswd = a.closest('span').find('a.password')
var pswdTxt = ""
if (pswd.length) {
pswdTxt = pswd.text()
} else {
try {
var keywords = ["密码", "提取码"]
keywords.forEach((keyword) => {
getTextNodes(v.parentNode, keyword).forEach((linkNode) => {
var pattern = new RegExp('密码' + '[::]\\s*', 'g')
pswdTxt = linkNode.textContent.split(pattern)[1].trim()
throw new Error("Found")
})
})
} catch (e) {
if (e.message == "Found") {
}
}
}
if (pswdTxt) {
a.attr('href', url + '?pwd=' + pswdTxt)
pswd.hide()
a.css('font-size', '24px')
cnt += 1
}
}
})
$('a[href^="https://pan.baidu"]').click((e) => {
//e.preventDefault();
$(e.target).css('color', '#f00')
})
if (cnt > 0) {
GM_notification({ text: `${cnt}百度盘链接自动添加密码成功`, timeout: 800, onclick: function () { } });
} else {
var textNodes = getTextNodes('', 'pan.baidu.com');
textNodes.forEach((linkNode) => {
var link = linkNode.textContent.split(':')[1]
var current = linkNode
var i = 0;
while (current.textContent.indexOf('提取码') == -1 && i < 10) {
current = current.nextSibling
i++
}
if (current.textContent.indexOf('提取码') >= 0) {
link += '?pwd=' + current.textContent.split(':')[1]
var a = document.createElement('a')
a.href = link
a.textContent = link
a.target = "_blank"
current.remove()
linkNode.replaceWith(a)
cnt += 1;
}
});
if (cnt > 0) {
GM_notification({ text: `${cnt}百度盘文本链接转换成功`, timeout: 800, onclick: function () { } });
}
}
})();