优化 规范代码

This commit is contained in:
xiu2
2021-03-30 10:25:49 +08:00
parent dc40d520d8
commit 209da34424
2 changed files with 26 additions and 28 deletions
+8 -8
View File
@@ -5,7 +5,7 @@
// @description 高速下载 Git Clone、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)
// @match *://github.com/*
// @match *://hub.fastgit.org/*
// @icon https://i.loli.net/2021/03/07/oUHPFSOTjKnkMzJ.png
// @icon https://i.loli.net/2021/03/30/ULV9XunaHesqGIR.png
// @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
/* globals $ */
// @grant GM_registerMenuCommand
@@ -127,7 +127,7 @@
$(this).next().after(html);
});
// 修改[文件大小]元素样式
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;');
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;'});
// Source Code
@@ -151,7 +151,7 @@
});
});
// 修改 Source code 样式,使其和加速按钮并列一排
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');
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'});
}
@@ -230,8 +230,8 @@
let elem = evt.currentTarget,
aElm_new = elem.querySelectorAll('.fileDownLink'),
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary');
aElm_new.forEach(el=>el.style.cssText = 'display: inline');
aElm_now.forEach(el=>el.style.cssText = 'display: none');
aElm_new.forEach(el=>{el.style.cssText = 'display: inline'});
aElm_now.forEach(el=>{el.style.cssText = 'display: none'});
};
// 鼠标离开则隐藏
@@ -239,8 +239,8 @@
let elem = evt.currentTarget,
aElm_new = elem.querySelectorAll('.fileDownLink'),
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.color-icon-tertiary');
aElm_new.forEach(el=>el.style.cssText = 'display: none');
aElm_now.forEach(el=>el.style.cssText = 'display: inline');
aElm_new.forEach(el=>{el.style.cssText = 'display: none'});
aElm_now.forEach(el=>{el.style.cssText = 'display: inline'});
};
// 循环添加
@@ -249,7 +249,7 @@
cntElm_a = trElm.querySelector('.css-truncate.css-truncate-target.d-block.width-fit a'),
cntElm_svg = trElm.querySelector('.mr-3.flex-shrink-0 svg.octicon.octicon-file.color-icon-tertiary'),
Name = cntElm_a.innerText,
href = cntElm_a.attributes['href'].nodeValue.replace('https://github.com','');
href = cntElm_a.attributes.href.nodeValue.replace('https://github.com','');
let href2 = href.replace('/blob/','/'), url, url_name, url_tip = '';
console.log(cntElm_a, cntElm_svg, Name, href)
switch(menu_raw_fast)
+18 -20
View File
@@ -221,7 +221,7 @@ function topTime_search()
// 完整显示时间
if(menu_allTime)
{
if($(this).find(".ContentItem-time").text().indexOf("发布于")==-1 && $(this).find(".ContentItem-time").text().indexOf("编辑于") > -1) //只有"编辑于"时,增加具体发布时间data-tooltip
if($(this).find(".ContentItem-time").text().indexOf("发布于")==-1 && $(this).find(".ContentItem-time").text().indexOf("编辑于") > -1) //只有"编辑于"时,增加具体发布时间data-tooltip
{
let data_tooltip = $(this).find(".ContentItem-time").find("span").attr("data-tooltip");
var oldtext =$(this).find(".ContentItem-time").find("span").text();
@@ -298,19 +298,18 @@ function directLink () {
if ($(this).find("span").length > 0) {
new_href = $(this).text();
$(this).attr("href", new_href);
}
else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
} else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
external_href = $(this).attr("href");
new_href = external_href.substring(external_href = $(this).attr("href").indexOf("link.zhihu.com/?target=") + "link.zhihu.com/?target=".length);
//console.log(`${new_href}`)
$(this).attr("href", decodeURIComponent(new_href));
}
else {
} else {
external_href = $(this).attr("href");
if (external_href.lastIndexOf("https%3A"))
if (external_href.lastIndexOf("https%3A")) {
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("https%3A"));
else if (external_href.lastIndexOf("http%3A%2F%2F"))
} else if (external_href.lastIndexOf("http%3A%2F%2F")) {
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("http%3A"));
}
$(this).attr("href", decodeURIComponent(new_href));
}
});
@@ -320,18 +319,17 @@ function directLink () {
if ($(this).find("LinkCard-title").length > 0 && $(this).find("LinkCard-title").indexOf("http") > -1) {
new_href = $(this).find("LinkCard-title").text();
$(this).attr("href", new_href);
}
else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
} else if ($(this).attr("href").indexOf("link.zhihu.com/?target=") > -1) {
external_href = $(this).attr("href");
new_href = external_href.substring(external_href = $(this).attr("href").indexOf("link.zhihu.com/?target=") + "link.zhihu.com/?target=".length);
$(this).attr("href", decodeURIComponent(new_href));
}
else {
} else {
external_href = $(this).attr("href");
if (external_href.lastIndexOf("https%3A"))
if (external_href.lastIndexOf("https%3A")) {
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("https%3A"));
else if (external_href.lastIndexOf("http%3A%2F%2F"))
} else if (external_href.lastIndexOf("http%3A%2F%2F")) {
new_href = $(this).attr("href").substring($(this).attr("href").lastIndexOf("http%3A"));
}
$(this).attr("href", decodeURIComponent(new_href));
}
});
@@ -356,10 +354,10 @@ function directLink () {
// 默认高清原图,来自:https://greasyfork.org/scripts/402808
function originalPic(){
$("img").each(function(){
if($(this).attr("data-original")!=undefined && !$(this).hasClass("comment_sticker"))
{
if($(this).attr("src") != $(this).attr("data-original"))
if ($(this).attr("data-original")!=undefined && !$(this).hasClass("comment_sticker")) {
if ($(this).attr("src") != $(this).attr("data-original")) {
$(this).attr("src",$(this).attr("data-original"))
}
}
})
$(".Modal-inner").css({"overflow-y":"hidden"})
@@ -464,16 +462,16 @@ function addTypeTips() {
//console.log(`${postList.length} ${postNum.length}`)
if (postList.length > postNum.length){
for(let num = postNum.length;num<postList.length;num++){
if (!patt_tip.test(postList[num].innerHTML)){ // 判断是否已添加
if (patt_zhuanlan.test(postList[num].href)){ // 如果是文章
if (!patt_tip.test(postList[num].innerHTML)){ // 判断是否已添加
if (patt_zhuanlan.test(postList[num].href)){ // 如果是文章
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
}else if (patt_question.test(postList[num].href)){ // 如果是问题
}else if (patt_question.test(postList[num].href)){ // 如果是问题
if (patt_question_answer.test(postList[num].href)){ // 如果是指向回答的问题(而非指向纯问题的链接)
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
}else{
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
}
}else if (patt_video.test(postList[num].href)){ // 如果是视频
}else if (patt_video.test(postList[num].href)){ // 如果是视频
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
}
//postNum += 1;