forked from ywzhaiqi/userscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserscripts.user.js
92 lines (80 loc) · 2.23 KB
/
userscripts.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
// ==UserScript==
// @id userscripts@[email protected]
// @name userscripts 只显示中文
// @version 1.2.1
// @author [email protected]
// @description 在userscripts.org Script页面只显示中文脚本,可与autopage 配合使用
// @include /https?://userscripts.org/scripts$/
// 注: UserScriptLoader.uc.js 可能不支持正则
// @include http*://userscripts.org/scripts?page=*
// @include http*://userscripts.org/scripts/search?q=*
// @run-at document-end
// ==/UserScript==
(function(){
var hided = false,
contentDiv = document.getElementById('content'),
contentHeight;
// 隐藏其它,只显示中文
function hideOthers(){
var scripts = document.querySelectorAll(".script-meat"),
script,
parent;
for (var i = scripts.length - 1; i >= 0; i--) {
script = scripts[i];
parent = script.parentElement;
if(parent.className.indexOf('mhide') > -1){
continue;
}
if(!/[\u4E00-\u9FA5]/.test(script.querySelector('a').textContent + script.querySelector('p.desc').textContent)){
parent.className += ' mhide';
}
}
hided = true;
}
function showAll () {
var trs = document.querySelectorAll(".mhide");
for (var i = trs.length - 1; i >= 0; i--) {
trs[i].className = trs[i].className.replace(/(\s+|)mhide(\s+|)/g, '');
}
hided = false;
}
function addButton(){
var button = document.createElement('button');
button.type = "button";
button.innerHTML = "只显示中文";
button.onclick = function(){
if(hided){
showAll();
button.innerHTML = "只显示中文";
contentHeight = contentDiv.scrollHeight;
}else{
hideOthers();
button.innerHTML = "显示全部";
contentHeight = contentDiv.scrollHeight;
}
};
var parent = document.querySelector("th.la");
parent.appendChild(button);
}
function fixAutoPage(){
var firstTime = true;
document.onscroll = function(){
if(firstTime){
contentHeight = contentDiv.scrollHeight;
firstTime = false;
}
// console.log(contentDiv.scrollHeight, contentHeight);
if(contentDiv.scrollHeight > contentHeight){
// console.log("add");
if(hided){
hideOthers();
}else{
showAll();
}
}
};
}
GM_addStyle(".mhide {display:none !important}");
addButton();
fixAutoPage();
})();