Skip to content

Commit 209da34

Browse files
committed
优化 规范代码
1 parent dc40d52 commit 209da34

2 files changed

Lines changed: 26 additions & 28 deletions

File tree

GithubEnhanced-High-Speed-Download.user.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// @description 高速下载 Git Clone、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)
66
// @match *://github.com/*
77
// @match *://hub.fastgit.org/*
8-
// @icon https://i.loli.net/2021/03/07/oUHPFSOTjKnkMzJ.png
8+
// @icon https://i.loli.net/2021/03/30/ULV9XunaHesqGIR.png
99
// @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
1010
/* globals $ */
1111
// @grant GM_registerMenuCommand
@@ -127,7 +127,7 @@
127127
$(this).next().after(html);
128128
});
129129
// 修改[文件大小]元素样式
130-
document.querySelectorAll('small.pl-2.color-text-secondary.flex-shrink-0').forEach(el=>el.style.cssText='display: flex; justify-content: flex-end; flex-grow: 1; margin-right: 8px;');
130+
document.querySelectorAll('small.pl-2.color-text-secondary.flex-shrink-0').forEach(el=>{el.style.cssText='display: flex; justify-content: flex-end; flex-grow: 1; margin-right: 8px;'});
131131

132132

133133
// Source Code
@@ -151,7 +151,7 @@
151151
});
152152
});
153153
// 修改 Source code 样式,使其和加速按钮并列一排
154-
document.querySelectorAll('div.d-block.py-1.py-md-2.Box-body.px-2').forEach(el=>el.className='d-flex py-1 py-md-2 Box-body px-2');
154+
document.querySelectorAll('div.d-block.py-1.py-md-2.Box-body.px-2').forEach(el=>{el.className='d-flex py-1 py-md-2 Box-body px-2'});
155155
}
156156

157157

@@ -230,17 +230,17 @@
230230
let elem = evt.currentTarget,
231231
aElm_new = elem.querySelectorAll('.fileDownLink'),
232232
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary');
233-
aElm_new.forEach(el=>el.style.cssText = 'display: inline');
234-
aElm_now.forEach(el=>el.style.cssText = 'display: none');
233+
aElm_new.forEach(el=>{el.style.cssText = 'display: inline'});
234+
aElm_now.forEach(el=>{el.style.cssText = 'display: none'});
235235
};
236236

237237
// 鼠标离开则隐藏
238238
var mouseOutHandler = function(evt){
239239
let elem = evt.currentTarget,
240240
aElm_new = elem.querySelectorAll('.fileDownLink'),
241241
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary');
242-
aElm_new.forEach(el=>el.style.cssText = 'display: none');
243-
aElm_now.forEach(el=>el.style.cssText = 'display: inline');
242+
aElm_new.forEach(el=>{el.style.cssText = 'display: none'});
243+
aElm_now.forEach(el=>{el.style.cssText = 'display: inline'});
244244
};
245245

246246
// 循环添加
@@ -249,7 +249,7 @@
249249
cntElm_a = trElm.querySelector('.css-truncate.css-truncate-target.d-block.width-fit a'),
250250
cntElm_svg = trElm.querySelector('.mr-3.flex-shrink-0 svg.octicon.octicon-file.color-icon-tertiary'),
251251
Name = cntElm_a.innerText,
252-
href = cntElm_a.attributes['href'].nodeValue.replace('https://github.com','');
252+
href = cntElm_a.attributes.href.nodeValue.replace('https://github.com','');
253253
let href2 = href.replace('/blob/','/'), url, url_name, url_tip = '';
254254
console.log(cntElm_a, cntElm_svg, Name, href)
255255
switch(menu_raw_fast)

Zhihu-Enhanced.user.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function topTime_search()
221221
// 完整显示时间
222222
if(menu_allTime)
223223
{
224-
if($(this).find(".ContentItem-time").text().indexOf("发布于")==-1 && $(this).find(".ContentItem-time").text().indexOf("编辑于") > -1) //只有"编辑于"时,增加具体发布时间data-tooltip
224+
if($(this).find(".ContentItem-time").text().indexOf("发布于")==-1 && $(this).find(".ContentItem-time").text().indexOf("编辑于") > -1) //只有"编辑于"时,增加具体发布时间data-tooltip
225225
{
226226
let data_tooltip = $(this).find(".ContentItem-time").find("span").attr("data-tooltip");
227227
var oldtext =$(this).find(".ContentItem-time").find("span").text();
@@ -298,19 +298,18 @@ function directLink () {
298298
if ($(this).find("span").length > 0) {
299299
new_href = $(this).text();
300300
$(this).attr("href", new_href);
301-
}
302-
else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
301+
} else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
303302
external_href = $(this).attr("href");
304303
new_href = external_href.substring(external_href = $(this).attr("href").indexOf("link.zhihu.com/?target=") + "link.zhihu.com/?target=".length);
305304
//console.log(`${new_href}`)
306305
$(this).attr("href", decodeURIComponent(new_href));
307-
}
308-
else {
306+
} else {
309307
external_href = $(this).attr("href");
310-
if (external_href.lastIndexOf("https%3A"))
308+
if (external_href.lastIndexOf("https%3A")) {
311309
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("https%3A"));
312-
else if (external_href.lastIndexOf("http%3A%2F%2F"))
310+
} else if (external_href.lastIndexOf("http%3A%2F%2F")) {
313311
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("http%3A"));
312+
}
314313
$(this).attr("href", decodeURIComponent(new_href));
315314
}
316315
});
@@ -320,18 +319,17 @@ function directLink () {
320319
if ($(this).find("LinkCard-title").length > 0 && $(this).find("LinkCard-title").indexOf("http") > -1) {
321320
new_href = $(this).find("LinkCard-title").text();
322321
$(this).attr("href", new_href);
323-
}
324-
else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
322+
} else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
325323
external_href = $(this).attr("href");
326324
new_href = external_href.substring(external_href = $(this).attr("href").indexOf("link.zhihu.com/?target=") + "link.zhihu.com/?target=".length);
327325
$(this).attr("href", decodeURIComponent(new_href));
328-
}
329-
else {
326+
} else {
330327
external_href = $(this).attr("href");
331-
if (external_href.lastIndexOf("https%3A"))
328+
if (external_href.lastIndexOf("https%3A")) {
332329
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("https%3A"));
333-
else if (external_href.lastIndexOf("http%3A%2F%2F"))
330+
} else if (external_href.lastIndexOf("http%3A%2F%2F")) {
334331
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("http%3A"));
332+
}
335333
$(this).attr("href", decodeURIComponent(new_href));
336334
}
337335
});
@@ -356,10 +354,10 @@ function directLink () {
356354
// 默认高清原图,来自:https://greasyfork.org/scripts/402808
357355
function originalPic(){
358356
$("img").each(function(){
359-
if($(this).attr("data-original")!=undefined && !$(this).hasClass("comment_sticker"))
360-
{
361-
if($(this).attr("src") != $(this).attr("data-original"))
357+
if ($(this).attr("data-original")!=undefined && !$(this).hasClass("comment_sticker")) {
358+
if ($(this).attr("src") != $(this).attr("data-original")) {
362359
$(this).attr("src",$(this).attr("data-original"))
360+
}
363361
}
364362
})
365363
$(".Modal-inner").css({"overflow-y":"hidden"})
@@ -464,16 +462,16 @@ function addTypeTips() {
464462
//console.log(`${postList.length} ${postNum.length}`)
465463
if (postList.length > postNum.length){
466464
for(let num = postNum.length;num<postList.length;num++){
467-
if (!patt_tip.test(postList[num].innerHTML)){ // 判断是否已添加
468-
if (patt_zhuanlan.test(postList[num].href)){ // 如果是文章
465+
if (!patt_tip.test(postList[num].innerHTML)){ // 判断是否已添加
466+
if (patt_zhuanlan.test(postList[num].href)){ // 如果是文章
469467
postList[num].innerHTML = `<small class="zhihu_e_tips" style="color: #ffffff;font-weight: normal;font-size: 12px;padding: 0 3px;border-radius: 2px;background-color: #2196F3;display: inline-block;height: 18px;">文章</small> ` + postList[num].innerHTML
470-
}else if (patt_question.test(postList[num].href)){ // 如果是问题
468+
}else if (patt_question.test(postList[num].href)){ // 如果是问题
471469
if (patt_question_answer.test(postList[num].href)){ // 如果是指向回答的问题(而非指向纯问题的链接)
472470
postList[num].innerHTML = `<small class="zhihu_e_tips" style="color: #ffffff;font-weight: normal;font-size: 12px;padding: 0 3px;border-radius: 2px;background-color: #f68b83;display: inline-block;height: 18px;">问题</small> ` + postList[num].innerHTML
473471
}else{
474472
postList[num].innerHTML = `<small class="zhihu_e_tips" style="color: #ffffff;font-weight: normal;font-size: 12px;padding: 0 3px;border-radius: 2px;background-color: #ff5a4e;display: inline-block;height: 18px;">问题</small> ` + postList[num].innerHTML
475473
}
476-
}else if (patt_video.test(postList[num].href)){ // 如果是视频
474+
}else if (patt_video.test(postList[num].href)){ // 如果是视频
477475
postList[num].innerHTML = `<small class="zhihu_e_tips" style="color: #ffffff;font-weight: normal;font-size: 12px;padding: 0 3px;border-radius: 2px;background-color: #00BCD4;display: inline-block;height: 18px;">视频</small> ` + postList[num].innerHTML
478476
}
479477
//postNum += 1;

0 commit comments

Comments
 (0)