|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Github 增强 - 高速下载 |
3 | | -// @version 1.3.4 |
| 3 | +// @version 1.3.5 |
4 | 4 | // @author X.I.U |
5 | | -// @description 高速下载 Clone、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁) |
| 5 | +// @description 高速下载 Git Clone、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁) |
6 | 6 | // @match *://github.com/* |
7 | 7 | // @icon https://github.com/favicon.ico |
8 | 8 | // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js |
|
33 | 33 | ['https://pd.zwc365.com/seturl','中国香港'] |
34 | 34 | ], |
35 | 35 | clone_url = [ |
36 | | - 'https://hub.fastgit.org', |
37 | | - 'https://gitclone.com', |
38 | | - 'https://ghp.lvmhsh.cn.cnpmjs.org' |
| 36 | + ['https://hub.fastgit.org','中国香港'], |
| 37 | + ['https://gitclone.com','中国浙江杭州'], |
| 38 | + ['https://ghp.lvmhsh.cn.cnpmjs.org','新加坡'] |
39 | 39 | ], |
40 | 40 | raw_url = [ |
41 | 41 | ['https://raw.githubusercontent.com','Github 原生',''], |
42 | 42 | ['https://raw.sevencdn.com','中国国内 01',''], |
43 | | - ['https://cdn.jsdelivr.net','中国国内 02','注意:该加速源存在缓存机制(24小时),所以文件可能不是最新。 注意:当前分支所有文件总文件大小超过 50MB 时,该加速源不可用。 注意:当前分支名为版本号格式时(如 v1.2.3),该高速下载链接因格式限制不可用。 '], |
44 | | - ['https://raw.fastgit.org','中国香港','注意:单个文件太大时可能会提示超时(实时获取中),请重试。 '], |
| 43 | + ['https://cdn.jsdelivr.net','中国国内 02','注意:该加速源存在缓存机制(24小时),所以文件可能不是最新。 注意:当前分支所有文件总文件大小超过 50MB 时,该加速源不可用。 注意:当前分支名为版本号格式时(如 v1.2.3),该高速下载链接因格式限制不可用。'], |
| 44 | + ['https://raw.fastgit.org','中国香港','注意:单个文件太大时可能会提示超时(实时获取中),请重试。'], |
45 | 45 | ['https://ghproxy.com','韩国首尔',''] |
46 | 46 | ], |
47 | 47 | svg = [ |
|
50 | 50 | '<svg class="octicon octicon-cloud-download" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M9 12h2l-3 3-3-3h2V7h2v5zm3-8c0-.44-.91-3-4.5-3C5.08 1 3 2.92 3 5 1.02 5 0 6.52 0 8c0 1.53 1 3 3 3h3V9.7H3C1.38 9.7 1.3 8.28 1.3 8c0-.17.05-1.7 1.7-1.7h1.3V5c0-1.39 1.56-2.7 3.2-2.7 2.55 0 3.13 1.55 3.2 1.8v1.2H12c.81 0 2.7.22 2.7 2.2 0 2.09-2.25 2.2-2.7 2.2h-2V11h2c2.08 0 4-1.16 4-3.5C16 5.06 14.08 4 12 4z"></path></svg>' |
51 | 51 | ], |
52 | 52 | style = ['padding:0 6px;margin-right: -1px;border-radius: 2px;background-color: '+backColor+';border-color: rgba(27, 31, 35, 0.1);font-size: 11px;color: '+fontColor+';'], |
53 | | - |
54 | 53 | menu_raw_fast = GM_getValue('xiu2_menu_raw_fast'), |
55 | 54 | menu_menu_raw_fast_ID, menu_feedBack_ID; |
56 | 55 | if (menu_raw_fast == null || menu_raw_fast == '中国国内'){menu_raw_fast = 1; GM_setValue('xiu2_menu_raw_fast', 1)}; // 调整上个版本的设置存储变量内容 |
|
103 | 102 | function addRelease(){ |
104 | 103 | $(".Box.Box--condensed").each(function () { |
105 | 104 | $(this).find(".d-flex.Box-body>a").each(function () { |
106 | | - var href = $(this).attr("href"), |
| 105 | + let href = $(this).attr("href"), |
107 | 106 | url = [ |
108 | 107 | download_url[0][0] + '/https://github.com' + href, |
109 | 108 | download_url[1][0] + '/https://github.com' + href, |
|
112 | 111 | download_url[4][0] + '/https://github.com' + href, |
113 | 112 | download_url[5][0] + '/https://github.com' + href |
114 | 113 | ], |
115 | | - html = `<div style="display: flex;justify-content: flex-end;"> |
116 | | -<div><a style="${style[0]}" class="btn" href="${url[0]}" rel="noreferrer noopener nofollow">${download_url[0][1]}</a></div> |
117 | | -<div><a style="${style[0]}" class="btn" href="${url[1]}" rel="noreferrer noopener nofollow">${download_url[1][1]}</a></div> |
118 | | -<div><a style="${style[0]}" class="btn" href="${url[2]}" rel="noreferrer noopener nofollow">${download_url[2][1]}</a></div> |
119 | | -<div><a style="${style[0]}" class="btn" href="${url[3]}" rel="noreferrer noopener nofollow">${download_url[3][1]}</a></div> |
120 | | -<div><a style="${style[0]}" class="btn" href="${url[4]}" rel="noreferrer noopener nofollow">${download_url[4][1]}</a></div> |
121 | | -<div><a style="${style[0]}" class="btn" href="${url[5]}" rel="noreferrer noopener nofollow">${download_url[5][1]}</a></div> |
122 | | -</div>`; |
| 114 | + html = `<div style="display: flex;justify-content: flex-end;">`; |
| 115 | + for (let i=0;i<url.length;i++) |
| 116 | + { |
| 117 | + html = html + `<div><a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a></div>` |
| 118 | + } |
| 119 | + html = html + `</div>` |
123 | 120 | $(this).next().after(html); |
124 | 121 | }); |
125 | 122 | // 修改[文件大小]元素样式 |
|
128 | 125 |
|
129 | 126 | // Source Code |
130 | 127 | $(this).find(".d-block.Box-body>a").each(function () { |
131 | | - var href = $(this).attr("href"), |
| 128 | + let href = $(this).attr("href"), |
132 | 129 | url = [ |
133 | 130 | download_url[0][0] + '/https://github.com' + href, |
134 | 131 | download_url[1][0] + '/https://github.com' + href, |
|
137 | 134 | download_url[4][0] + '/https://github.com' + href, |
138 | 135 | download_url[5][0] + '/https://github.com' + href |
139 | 136 | ], |
140 | | - html = `<div style="display: flex;justify-content: flex-end;flex-grow: 1;"> |
141 | | -<div><a style="${style[0]}" class="btn" href="${url[0]}" rel="noreferrer noopener nofollow">${download_url[0][1]}</a></div> |
142 | | -<div><a style="${style[0]}" class="btn" href="${url[1]}" rel="noreferrer noopener nofollow">${download_url[1][1]}</a></div> |
143 | | -<div><a style="${style[0]}" class="btn" href="${url[2]}" rel="noreferrer noopener nofollow">${download_url[2][1]}</a></div> |
144 | | -<div><a style="${style[0]}" class="btn" href="${url[3]}" rel="noreferrer noopener nofollow">${download_url[3][1]}</a></div> |
145 | | -<div><a style="${style[0]}" class="btn" href="${url[4]}" rel="noreferrer noopener nofollow">${download_url[4][1]}</a></div> |
146 | | -<div><a style="${style[0]}" class="btn" href="${url[5]}" rel="noreferrer noopener nofollow">${download_url[5][1]}</a></div> |
147 | | -</div>`; |
| 137 | + html = `<div style="display: flex;justify-content: flex-end;flex-grow: 1;">`; |
| 138 | + for (let i=0;i<url.length;i++) |
| 139 | + { |
| 140 | + html = html + `<div><a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a></div>` |
| 141 | + } |
| 142 | + html = html + `</div>` |
148 | 143 | $(this).after(html); |
149 | 144 | }); |
150 | 145 | }); |
|
156 | 151 | // Download ZIP |
157 | 152 | function addDownloadZIP(){ |
158 | 153 | $(".dropdown-menu.dropdown-menu-sw.p-0 ul li:last-child").each(function () { |
159 | | - var href = $(this).children("a").attr("href"), |
| 154 | + let href = $(this).children("a").attr("href"), |
160 | 155 | url = [ |
161 | 156 | download_url[0][0] + "/https://github.com" + href, |
162 | 157 | download_url[1][0] + "/https://github.com" + href, |
|
165 | 160 | download_url[4][0] + "/https://github.com" + href, |
166 | 161 | download_url[5][0] + '/https://github.com' + href |
167 | 162 | ], |
168 | | - html = ` |
169 | | -<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[0]}">${svg[0]}Download ZIP ${download_url[0][1]}</a></li> |
170 | | -<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[1]}">${svg[0]}Download ZIP ${download_url[1][1]}</a></li> |
171 | | -<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[2]}">${svg[0]}Download ZIP ${download_url[2][1]}</a></li> |
172 | | -<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[3]}">${svg[0]}Download ZIP ${download_url[3][1]}</a></li> |
173 | | -<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[4]}">${svg[0]}Download ZIP ${download_url[4][1]}</a></li> |
174 | | -<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[5]}">${svg[0]}Download ZIP ${download_url[5][1]}</a></li> |
175 | | -`; |
| 163 | + html = ``; |
| 164 | + for (let i=0;i<url.length;i++) |
| 165 | + { |
| 166 | + html = html + `<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[i]}">${svg[0]}Download ZIP ${download_url[i][1]}</a></li>` |
| 167 | + } |
176 | 168 | $(this).after(html); |
177 | 169 | }); |
178 | 170 | } |
|
181 | 173 | // Git Clone |
182 | 174 | function addGitClone(){ |
183 | 175 | $("[role='tabpanel'] div.input-group").first().each(function () { |
184 | | - var href_split = location.href.split("/"), |
| 176 | + let href_split = location.href.split("/"), |
185 | 177 | url = [ |
186 | | - clone_url[0] + "/" + href_split[3] + "/" + href_split[4] + ".git", |
187 | | - clone_url[1] + "/github.com/" + href_split[3] + "/" + href_split[4] + ".git", |
188 | | - clone_url[2] + "/" + href_split[3] + "/" + href_split[4] + ".git" |
| 178 | + clone_url[0][0] + "/" + href_split[3] + "/" + href_split[4] + ".git", |
| 179 | + clone_url[1][0] + "/github.com/" + href_split[3] + "/" + href_split[4] + ".git", |
| 180 | + clone_url[2][0] + "/" + href_split[3] + "/" + href_split[4] + ".git" |
189 | 181 | ], |
190 | | - html = ` |
191 | | -<div class="input-group" style="margin-top: 4px;"><input value="${url[0]}" aria-label="${url[0]}" type="text" class="form-control input-monospace input-sm bg-gray-light" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${url[0]}" aria-label="Copy to clipboard" class="btn btn-sm" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div> |
192 | | -<div class="input-group" style="margin-top: 4px;"><input value="${url[1]}" aria-label="${url[1]}" type="text" class="form-control input-monospace input-sm bg-gray-light" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${url[1]}" aria-label="Copy to clipboard" class="btn btn-sm" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div> |
193 | | -<div class="input-group" style="margin-top: 4px;"><input value="${url[2]}" aria-label="${url[2]}" type="text" class="form-control input-monospace input-sm bg-gray-light" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${url[2]}" aria-label="Copy to clipboard" class="btn btn-sm" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div> |
194 | | -`; |
| 182 | + html = ``; |
| 183 | + for (let i=0;i<url.length;i++) |
| 184 | + { |
| 185 | + html = 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>` |
| 186 | + } |
195 | 187 | $(this).after(html); |
196 | 188 | }); |
197 | 189 | } |
|
200 | 192 | // Raw |
201 | 193 | function addRawFile(){ |
202 | 194 | $("#raw-url").each(function () { |
203 | | - var href = location.href.replace('https://github.com',''), |
| 195 | + let href = location.href.replace('https://github.com',''), |
204 | 196 | href2 = href.replace('/blob/','/'), |
205 | 197 | url = [ |
206 | 198 | raw_url[1][0] + href2, |
207 | 199 | raw_url[2][0] + "/gh" + href.replace('/blob/','@'), |
208 | 200 | raw_url[3][0] + href2, |
209 | 201 | raw_url[4][0] + "/" + raw_url[0][0] + href2 |
210 | 202 | ], |
211 | | - html = ` |
212 | | -<a href="${url[0]}" title="${raw_url[1][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[1][1]}</a> |
213 | | -<a href="${url[1]}" title="${raw_url[2][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[2][1]}</a> |
214 | | -<a href="${url[2]}" title="${raw_url[3][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[3][1]}</a> |
215 | | -<a href="${url[3]}" title="${raw_url[4][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[4][1]}</a> |
216 | | -`; |
| 203 | + html = ``; |
| 204 | + for (let i=0;i<url.length;i++) |
| 205 | + { |
| 206 | + html = 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>` |
| 207 | + } |
217 | 208 | $(this).after(html); |
218 | 209 | }); |
219 | 210 | } |
|
222 | 213 | // 添加 Raw 下载链接(☁) |
223 | 214 | function addRawDownLink(){ |
224 | 215 | // 如果不是项目文件页面,就返回 |
225 | | - var files = $('div.Box-row svg.octicon.octicon-file'); |
| 216 | + let files = $('div.Box-row svg.octicon.octicon-file'); |
226 | 217 | if(files.length === 0) return; |
227 | | - var files1 = $('a.fileDownLink'); |
| 218 | + let files1 = $('a.fileDownLink'); |
228 | 219 | if(files1.length > 0) return; |
229 | 220 |
|
230 | 221 | // 鼠标指向则显示 |
231 | 222 | var mouseOverHandler = function(evt){ |
232 | | - var elem = evt.currentTarget, |
| 223 | + let elem = evt.currentTarget, |
233 | 224 | aElm_new = elem.querySelectorAll('.fileDownLink'), |
234 | 225 | aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.text-gray-light'); |
235 | 226 | aElm_new.forEach(el=>el.style.cssText = 'display: inline'); |
|
238 | 229 |
|
239 | 230 | // 鼠标离开则隐藏 |
240 | 231 | var mouseOutHandler = function(evt){ |
241 | | - var elem = evt.currentTarget, |
| 232 | + let elem = evt.currentTarget, |
242 | 233 | aElm_new = elem.querySelectorAll('.fileDownLink'), |
243 | 234 | aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.text-gray-light'); |
244 | 235 | aElm_new.forEach(el=>el.style.cssText = 'display: none'); |
|
247 | 238 |
|
248 | 239 | // 循环添加 |
249 | 240 | files.each(function(i,fileElm){ |
250 | | - var trElm = fileElm.parentNode.parentNode, |
| 241 | + let trElm = fileElm.parentNode.parentNode, |
251 | 242 | cntElm_a = trElm.querySelector('.css-truncate.css-truncate-target.d-block.width-fit a'), |
252 | 243 | cntElm_svg = trElm.querySelector('.mr-3.flex-shrink-0 svg.octicon.octicon-file.text-gray-light'), |
253 | 244 | Name = cntElm_a.innerText, |
254 | 245 | href = cntElm_a.attributes['href'].nodeValue.replace('https://github.com',''); |
255 | | - var href2 = href.replace('/blob/','/'), url, url_name, url_tip = ''; |
| 246 | + let href2 = href.replace('/blob/','/'), url, url_name, url_tip = ''; |
256 | 247 | switch(menu_raw_fast) |
257 | 248 | { |
258 | 249 | case 2: |
|
271 | 262 | url_tip = raw_url[menu_raw_fast][2]; |
272 | 263 | break; |
273 | 264 | } |
274 | | - var html = ` <a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」 [Alt + 左键] 或 [右键 - 另存为...] 下载文件。 注意:鼠标点击 [☁] 图标,而不是左侧的文件名! ${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) 即可切换。">${svg[2]}</a>`; |
| 265 | + let html = ` <a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」 [Alt + 左键] 或 [右键 - 另存为...] 下载文件。 注意:鼠标点击 [☁] 图标,而不是左侧的文件名! ${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) 即可切换。">${svg[2]}</a>`; |
275 | 266 | $(cntElm_svg).after(html); |
276 | 267 | // 绑定鼠标事件 |
277 | 268 | trElm.onmouseover=mouseOverHandler; |
|
282 | 273 |
|
283 | 274 | // 删除 Raw 快捷下载(☁) |
284 | 275 | function delRawDownLink(){ |
285 | | - var aElm = document.querySelectorAll('.fileDownLink'); |
| 276 | + let aElm = document.querySelectorAll('.fileDownLink'); |
286 | 277 | if(aElm.length === 0) return; |
287 | | - for(var num = 0;num<aElm.length;num++){ |
| 278 | + for(let num = 0;num<aElm.length;num++){ |
288 | 279 | aElm[num].remove(); |
289 | 280 | }; |
290 | 281 | } |
|
0 commit comments