Skip to content

Commit 68c5c86

Browse files
committed
优化 代码细节
1 parent b93e656 commit 68c5c86

2 files changed

Lines changed: 31 additions & 54 deletions

File tree

52pojie-Enhanced.user.js

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,30 +131,24 @@
131131

132132
// URL 匹配正则表达式
133133
let patt_thread = /\/thread-\d+-\d+\-\d+.html/,
134-
patt_thread_2 = /mod\=viewthread/,
135134
patt_forum = /\/forum-\d+-\d+\.html/,
136-
patt_forum_2 = /mod\=forumdisplay/,
137-
patt_guide = /mod\=guide\&view\=(hot|digest|new|newthread|my|tech|help)/,
138-
patt_guide_newthread = /mod\=guide\&view\=newthread/,
139-
patt_collection = /mod\=collection/
135+
patt_guide = /mod\=guide\&view\=(hot|digest|new|newthread|my|tech|help)/
140136

141137
// URL 判断
142-
if (patt_thread.test(location.pathname) || patt_thread_2.test(location.search)) {
138+
if (patt_thread.test(location.pathname) || location.search.indexOf('mod=viewthread') > -1) {
143139
if (menu_value('menu_thread_pageLoading')) {
144140
curSite = DBSite.thread; // 帖子内
145141
hidePgbtn(); // 隐藏帖子内的 [下一页] 按钮
146142
}
147-
} else if (patt_forum.test(location.pathname) || patt_forum_2.test(location.search)) {
143+
} else if (patt_forum.test(location.pathname) || location.search.indexOf('mod=forumdisplay') > -1) {
148144
curSite = DBSite.forum; // 各板块帖子列表
149145
} else if (patt_guide.test(location.search)) {
150146
curSite = DBSite.guide; // 导读帖子列表
151147
delateReward(); // 屏蔽导读悬赏贴(最新发表)
152-
} else if (patt_collection.test(location.search)) {
148+
} else if (location.search.indexOf('mod=collection') > -1) {
153149
curSite = DBSite.collection; // 淘贴列表
154150
} else if (location.pathname === '/search.php') {
155151
curSite = DBSite.search; // 搜索结果列表
156-
/*}else if(location.href === "https://www.52pojie.cn/home.php?mod=task&do=draw&id=2"){
157-
window.opener=null;window.open('','_self');window.close(); // 签到完成页面,关闭该标签页*/
158152
}
159153
curSite.pageUrl = ""; // 下一页URL
160154

@@ -186,18 +180,6 @@
186180
}
187181

188182

189-
// 自动签到
190-
/*function qianDao() {
191-
if (!menu_value('menu_autoClockIn')) return
192-
let qiandao = document.querySelector('#um p:last-child a:first-child');
193-
if (qiandao && qiandao.href === "https://www.52pojie.cn/home.php?mod=task&do=apply&id=2"){
194-
window.GM_openInTab(qiandao.href, {active: false,insert: true,setParent: true}) // 后台打开签到地址
195-
qiandao.querySelector('.qq_bind').setAttribute('src','https://www.52pojie.cn/static/image/common/wbs.png') // 修改 [打卡签到] 图标为 [签到完毕]
196-
qiandao.href = "#" // 修改 URL 为 #
197-
}
198-
}*/
199-
200-
201183
// 自动签到(后台)
202184
function qianDao() {
203185
if (!menu_value('menu_autoClockIn')) return
@@ -225,7 +207,7 @@
225207
//屏蔽悬赏贴(导读-最新发表)
226208
function delateReward() {
227209
if (!menu_value('menu_delateReward')) return
228-
if (patt_guide_newthread.test(location.search)) {
210+
if (location.search.indexOf('mod=guide&view=newthread') > -1) {
229211
let tbody = document.querySelectorAll('#threadlist tbody[id^="normalthread"]');
230212
Array.from(tbody).forEach(function (_this) {
231213
if (_this.querySelector('img[alt="悬赏"]')) {

GithubEnhanced-High-Speed-Download.user.js

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
(function() {
2121
var backColor = '#ffffff';
2222
var fontColor = '#888888';
23-
if(document.getElementsByTagName('html')[0].getAttribute('data-color-mode') == 'dark'){ // 黑暗模式判断
24-
if(document.getElementsByTagName('html')[0].getAttribute('data-dark-theme') == 'dark_dimmed'){
23+
if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') == 'dark') { // 黑暗模式判断
24+
if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme') == 'dark_dimmed') {
2525
backColor = '#272e37';
2626
fontColor = '#768390';
27-
}else{
27+
} else {
2828
backColor = '#161a21';
2929
fontColor = '#b2b8bf';
3030
}
@@ -62,12 +62,12 @@
6262
registerMenuCommand();
6363
// 注册脚本菜单
6464
function registerMenuCommand() {
65-
if (menu_feedBack_ID){ // 如果反馈菜单ID不是 null,则删除所有脚本菜单
65+
if (menu_feedBack_ID) { // 如果反馈菜单ID不是 null,则删除所有脚本菜单
6666
GM_unregisterMenuCommand(menu_menu_raw_fast_ID);
6767
GM_unregisterMenuCommand(menu_feedBack_ID);
6868
menu_raw_fast = GM_getValue('xiu2_menu_raw_fast');
6969
}
70-
if(menu_raw_fast > raw_url.length - 1){ // 避免在减少 raw 数组后,用户储存的数据大于数组而报错
70+
if (menu_raw_fast > raw_url.length - 1) { // 避免在减少 raw 数组后,用户储存的数据大于数组而报错
7171
menu_raw_fast = 0
7272
}
7373
menu_menu_raw_fast_ID = GM_registerMenuCommand(`🔄 [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) - 点击切换`, menu_toggle_raw_fast);
@@ -76,9 +76,9 @@
7676

7777
// 切换加速源
7878
function menu_toggle_raw_fast() {
79-
if (menu_raw_fast >= raw_url.length - 1){ // 如果当前加速源位置大于等于加速源总数,则改为第一个加速源,反之递增下一个加速源
79+
if (menu_raw_fast >= raw_url.length - 1) { // 如果当前加速源位置大于等于加速源总数,则改为第一个加速源,反之递增下一个加速源
8080
menu_raw_fast = 0;
81-
}else{
81+
} else {
8282
menu_raw_fast += 1;
8383
}
8484
GM_setValue('xiu2_menu_raw_fast', menu_raw_fast);
@@ -113,7 +113,7 @@
113113

114114

115115
// Release
116-
function addRelease(){
116+
function addRelease() {
117117
let html = document.getElementsByClassName('Box Box--condensed');if (!html) return
118118
Array.from(html).forEach(function (current) {
119119
current.querySelectorAll('.d-flex.Box-body > a').forEach(function (_this) {
@@ -127,8 +127,7 @@
127127
download_url[5][0] + '/' + _this.href
128128
],
129129
_html = `<div style="display: flex;justify-content: flex-end;">`;
130-
for (let i=0;i<url.length;i++)
131-
{
130+
for (let i=0;i<url.length;i++) {
132131
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
133132
}
134133
_html += `</div>`
@@ -150,8 +149,7 @@
150149
download_url[5][0] + '/' + _this.href
151150
],
152151
_html = `<div style="display: flex;justify-content: flex-end;flex-grow: 1;">`;
153-
for (let i=0;i<url.length;i++)
154-
{
152+
for (let i=0;i<url.length;i++) {
155153
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
156154
}
157155
_html += `</div>`
@@ -164,7 +162,7 @@
164162

165163

166164
// Download ZIP
167-
function addDownloadZIP(){
165+
function addDownloadZIP() {
168166
let html = document.querySelector('.dropdown-menu.dropdown-menu-sw.p-0 ul li:last-child');if (!html) return
169167
let href = html.getElementsByTagName('a')[0].href,
170168
url = [
@@ -176,16 +174,15 @@
176174
download_url[5][0] + '/' + href
177175
],
178176
_html = ``;
179-
for (let i=0;i<url.length;i++)
180-
{
177+
for (let i=0;i<url.length;i++) {
181178
_html += `<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center color-text-primary text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[i]}">${svg[0]}Download ZIP ${download_url[i][1]}</a></li>`
182179
}
183180
html.insertAdjacentHTML('afterend', _html);
184181
}
185182

186183

187184
// Git Clone
188-
function addGitClone(){
185+
function addGitClone() {
189186
let html = document.querySelector('[role="tabpanel"] div.input-group');if (!html) return
190187
let href_split = html.querySelector('input').getAttribute('value').split('github.com'),
191188
url = [
@@ -194,16 +191,15 @@
194191
clone_url[2][0] + href_split[1]
195192
],
196193
_html = ``;
197-
for (let i=0;i<url.length;i++)
198-
{
194+
for (let i=0;i<url.length;i++) {
199195
_html += `<div class="input-group" style="margin-top: 4px;" title="加速源:${clone_url[i][1]} (点击可直接复制)"><input value="${url[i]}" aria-label="${url[i]}" type="text" class="form-control input-monospace input-sm bg-gray-light" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${url[i]}" aria-label="Copy to clipboard" class="btn btn-sm" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div>`
200196
}
201197
html.insertAdjacentHTML('afterend', _html);
202198
}
203199

204200

205201
// Raw
206-
function addRawFile(){
202+
function addRawFile() {
207203
let html = document.getElementById('raw-url');if (!html) return
208204
let href = location.href.replace('https://github.com',''),
209205
href2 = href.replace('/blob/','/'),
@@ -213,22 +209,21 @@
213209
raw_url[3][0] + "/" + raw_url[0][0] + href2
214210
],
215211
_html = ``;
216-
for (let i=0;i<url.length;i++)
217-
{
212+
for (let i=0;i<url.length;i++) {
218213
_html += `<a href="${url[i]}" title="${raw_url[i+1][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[i+1][1]}</a>`
219214
}
220215
html.insertAdjacentHTML('afterend', _html);
221216
}
222217

223218

224219
// 添加 Raw 下载链接(☁)
225-
function addRawDownLink(){
220+
function addRawDownLink() {
226221
// 如果不是项目文件页面,就返回,如果网页有 Raw 下载链接(☁)就返回
227222
let files = document.querySelectorAll('div.Box-row svg.octicon.octicon-file');if(files.length === 0) return;
228223
let files1 = document.querySelectorAll('a.fileDownLink');if(files1.length > 0) return;
229224

230225
// 鼠标指向则显示
231-
var mouseOverHandler = function(evt){
226+
var mouseOverHandler = function(evt) {
232227
let elem = evt.currentTarget,
233228
aElm_new = elem.querySelectorAll('.fileDownLink'),
234229
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary');
@@ -237,7 +232,7 @@
237232
};
238233

239234
// 鼠标离开则隐藏
240-
var mouseOutHandler = function(evt){
235+
var mouseOutHandler = function(evt) {
241236
let elem = evt.currentTarget,
242237
aElm_new = elem.querySelectorAll('.fileDownLink'),
243238
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary');
@@ -246,7 +241,7 @@
246241
};
247242

248243
// 循环添加
249-
files.forEach(function(fileElm, i){
244+
files.forEach(function(fileElm, i) {
250245
let trElm = fileElm.parentNode.parentNode,
251246
cntElm_a = trElm.querySelector('.css-truncate.css-truncate-target.d-block.width-fit a'),
252247
cntElm_svg = trElm.querySelector('.mr-3.flex-shrink-0 svg.octicon.octicon-file.color-icon-tertiary'),
@@ -280,22 +275,22 @@
280275

281276

282277
// 删除 Raw 快捷下载(☁)
283-
function delRawDownLink(){
278+
function delRawDownLink() {
284279
let aElm = document.querySelectorAll('.fileDownLink');if(aElm.length === 0) return;
285-
aElm.forEach(function(fileElm){
280+
aElm.forEach(function(fileElm) {
286281
fileElm.remove()
287282
})
288283
}
289284

290285

291286
// 在浏览器返回/前进时重新添加 Raw 下载链接(☁)鼠标事件
292-
function addRawDownLink_(){
287+
function addRawDownLink_() {
293288
// 如果不是项目文件页面,就返回,如果网页没有 Raw 下载链接(☁)就返回
294289
let files = document.querySelectorAll('div.Box-row svg.octicon.octicon-file');if(files.length === 0) return;
295290
let files1 = document.querySelectorAll('a.fileDownLink');if(files1.length === 0) return;
296291

297292
// 鼠标指向则显示
298-
var mouseOverHandler = function(evt){
293+
var mouseOverHandler = function(evt) {
299294
let elem = evt.currentTarget,
300295
aElm_new = elem.querySelectorAll('.fileDownLink'),
301296
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary');
@@ -304,7 +299,7 @@
304299
};
305300

306301
// 鼠标离开则隐藏
307-
var mouseOutHandler = function(evt){
302+
var mouseOutHandler = function(evt) {
308303
let elem = evt.currentTarget,
309304
aElm_new = elem.querySelectorAll('.fileDownLink'),
310305
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary');
@@ -313,7 +308,7 @@
313308
};
314309

315310
// 循环添加
316-
files.forEach(function(fileElm, i){
311+
files.forEach(function(fileElm, i) {
317312
let trElm = fileElm.parentNode.parentNode;
318313
// 绑定鼠标事件
319314
trElm.onmouseover = mouseOverHandler;

0 commit comments

Comments
 (0)