Skip to content

Commit c72ee2e

Browse files
committed
移除 JQuery 依赖
1 parent 6429762 commit c72ee2e

2 files changed

Lines changed: 32 additions & 40 deletions

File tree

GithubEnhanced-High-Speed-Download.user.js

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,10 @@
106106

107107
// Release
108108
function addRelease(){
109-
let original = document.getElementsByClassName('Box Box--condensed')
110-
if (!original) return
111-
Array.from(original).forEach(function (current) {
112-
current.querySelectorAll('.d-flex.Box-body > a').forEach(function (current2) {
113-
let href = current2.href,
109+
let html = document.getElementsByClassName('Box Box--condensed');if (!html) return
110+
Array.from(html).forEach(function (current) {
111+
current.querySelectorAll('.d-flex.Box-body > a').forEach(function (_this) {
112+
let href = _this.href,
114113
url = [
115114
download_url[0][0] + '/https://github.com' + href,
116115
download_url[1][0] + '/https://github.com' + href,
@@ -119,21 +118,21 @@
119118
download_url[4][0] + '/https://github.com' + href,
120119
download_url[5][0] + '/https://github.com' + href
121120
],
122-
html = `<div style="display: flex;justify-content: flex-end;">`;
121+
_html = `<div style="display: flex;justify-content: flex-end;">`;
123122
for (let i=0;i<url.length;i++)
124123
{
125-
html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
124+
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
126125
}
127-
html += `</div>`
128-
current2.nextElementSibling.insertAdjacentHTML('afterend', html);
126+
_html += `</div>`
127+
_this.nextElementSibling.insertAdjacentHTML('afterend', _html);
129128
});
130129
// 修改[文件大小]元素样式
131130
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;'});
132131

133132

134133
// Source Code
135-
current.querySelectorAll('.d-block.Box-body > a').forEach(function (current2) {
136-
let href = current2.href,
134+
current.querySelectorAll('.d-block.Box-body > a').forEach(function (_this) {
135+
let href = _this.href,
137136
url = [
138137
download_url[0][0] + '/https://github.com' + href,
139138
download_url[1][0] + '/https://github.com' + href,
@@ -142,13 +141,13 @@
142141
download_url[4][0] + '/https://github.com' + href,
143142
download_url[5][0] + '/https://github.com' + href
144143
],
145-
html = `<div style="display: flex;justify-content: flex-end;flex-grow: 1;">`;
144+
_html = `<div style="display: flex;justify-content: flex-end;flex-grow: 1;">`;
146145
for (let i=0;i<url.length;i++)
147146
{
148-
html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
147+
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
149148
}
150-
html += `</div>`
151-
current2.insertAdjacentHTML('afterend', html);
149+
_html += `</div>`
150+
_this.insertAdjacentHTML('afterend', _html);
152151
});
153152
});
154153
// 修改 Source code 样式,使其和加速按钮并列一排
@@ -158,9 +157,8 @@
158157

159158
// Download ZIP
160159
function addDownloadZIP(){
161-
let original = document.querySelector('.dropdown-menu.dropdown-menu-sw.p-0 ul li:last-child');
162-
if (!original) return
163-
let href = original.getElementsByTagName('a')[0].href,
160+
let html = document.querySelector('.dropdown-menu.dropdown-menu-sw.p-0 ul li:last-child');if (!html) return
161+
let href = html.getElementsByTagName('a')[0].href,
164162
url = [
165163
download_url[0][0] + "/https://github.com" + href,
166164
download_url[1][0] + "/https://github.com" + href,
@@ -169,38 +167,36 @@
169167
download_url[4][0] + "/https://github.com" + href,
170168
download_url[5][0] + '/https://github.com' + href
171169
],
172-
html = ``;
170+
_html = ``;
173171
for (let i=0;i<url.length;i++)
174172
{
175-
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>`
173+
_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>`
176174
}
177-
original.insertAdjacentHTML('afterend', html);
175+
html.insertAdjacentHTML('afterend', _html);
178176
}
179177

180178

181179
// Git Clone
182180
function addGitClone(){
183-
let original = document.querySelector('[role="tabpanel"] div.input-group');
184-
if (!original) return
181+
let html = document.querySelector('[role="tabpanel"] div.input-group');if (!html) return
185182
let href_split = location.href.split("/"),
186183
url = [
187184
clone_url[0][0] + "/" + href_split[3] + "/" + href_split[4] + ".git",
188185
clone_url[1][0] + "/github.com/" + href_split[3] + "/" + href_split[4] + ".git",
189186
clone_url[2][0] + "/" + href_split[3] + "/" + href_split[4] + ".git"
190187
],
191-
html = ``;
188+
_html = ``;
192189
for (let i=0;i<url.length;i++)
193190
{
194-
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>`
191+
_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>`
195192
}
196-
original.insertAdjacentHTML('afterend', html);
193+
html.insertAdjacentHTML('afterend', _html);
197194
}
198195

199196

200197
// Raw
201198
function addRawFile(){
202-
let original = document.getElementById('raw-url')
203-
if (!original) return
199+
let html = document.getElementById('raw-url');if (!html) return
204200
let href = location.href.replace('https://github.com',''),
205201
href2 = href.replace('/blob/','/'),
206202
url = [
@@ -209,22 +205,20 @@
209205
raw_url[3][0] + href2,
210206
raw_url[4][0] + "/" + raw_url[0][0] + href2
211207
],
212-
html = ``;
208+
_html = ``;
213209
for (let i=0;i<url.length;i++)
214210
{
215-
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>`
211+
_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>`
216212
}
217-
original.insertAdjacentHTML('afterend', html);
213+
html.insertAdjacentHTML('afterend', _html);
218214
}
219215

220216

221217
// 添加 Raw 下载链接(☁)
222218
function addRawDownLink(){
223219
// 如果不是项目文件页面,就返回
224-
let files = document.querySelectorAll('div.Box-row svg.octicon.octicon-file');
225-
if(files.length === 0) return;
226-
let files1 = document.querySelectorAll('a.fileDownLink');
227-
if(files1.length > 0) return;
220+
let files = document.querySelectorAll('div.Box-row svg.octicon.octicon-file');if(files.length === 0) return;
221+
let files1 = document.querySelectorAll('a.fileDownLink');if(files1.length > 0) return;
228222

229223
// 鼠标指向则显示
230224
var mouseOverHandler = function(evt){
@@ -270,8 +264,8 @@
270264
url_tip = raw_url[menu_raw_fast][2];
271265
break;
272266
}
273-
let html = ` <a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」&#10;&#10;[Alt + 左键] 或 [右键 - 另存为...] 下载文件。&#10;注意:鼠标点击 [☁] 图标,而不是左侧的文件名!&#10;&#10;${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) 即可切换。">${svg[2]}</a>`;
274-
cntElm_svg.insertAdjacentHTML('afterend', html);
267+
let _html = ` <a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」&#10;&#10;[Alt + 左键] 或 [右键 - 另存为...] 下载文件。&#10;注意:鼠标点击 [☁] 图标,而不是左侧的文件名!&#10;&#10;${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) 即可切换。">${svg[2]}</a>`;
268+
cntElm_svg.insertAdjacentHTML('afterend', _html);
275269
// 绑定鼠标事件
276270
trElm.onmouseover = mouseOverHandler;
277271
trElm.onmouseout = mouseOutHandler;
@@ -281,8 +275,7 @@
281275

282276
// 删除 Raw 快捷下载(☁)
283277
function delRawDownLink(){
284-
let aElm = document.querySelectorAll('.fileDownLink');
285-
if(aElm.length === 0) return;
278+
let aElm = document.querySelectorAll('.fileDownLink');if(aElm.length === 0) return;
286279
aElm.forEach(function(fileElm){
287280
fileElm.remove()
288281
})

Zhihu-Enhanced.user.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// @match *://zhuanlan.zhihu.com/*
88
// @icon https://static.zhihu.com/heifetz/favicon.ico
99
// @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
10-
/* globals $ */
1110
// @grant GM_registerMenuCommand
1211
// @grant GM_unregisterMenuCommand
1312
// @grant GM_openInTab

0 commit comments

Comments
 (0)