MCPcopy Create free account
hub / github.com/XIU2/UserScript / addDownloadZIP

Function addDownloadZIP

GithubEnhanced-High-Speed-Download.user.js:258–289  ·  view source on GitHub ↗
(target)

Source from the content-addressed store, hash-verified

256
257 // Download ZIP
258 function addDownloadZIP(target) {
259 const html = target.querySelector('ul[class^=prc-ActionList-ActionList-]>li:last-child');if (!html) return
260 let href = html.querySelector('a[href^="/"][href$=".zip"]');if (!href || !href.getAttribute('href')) return
261 href = href.getAttribute('href');
262 //const href_script = document.querySelector('react-partial[partial-name=repos-overview]>script[data-target="react-partial.embeddedData"]');if (!href_script) return
263 //const href = JSON.parse(href_script.textContent).props.initialPayload.overview.codeButton.local.platformInfo.zipballUrl
264 /*let href_slice = href_script.textContent.slice(href_script.textContent.indexOf('"zipballUrl":"')+14),
265 href = href_slice.slice(0, href_slice.indexOf('"')),*/
266 let url = '', _html = '', new_download_url = get_New_download_url();
267
268 // 克隆原 Download ZIP 元素,并定位 <a> <span> 标签
269 let html_clone = html.cloneNode(true),
270 html_clone_a = html_clone.querySelector('a[href$=".zip"]'),
271 html_clone_span = html_clone.querySelector('span[id]');
272
273 for (let i=0;i<new_download_url.length;i++) {
274 if (new_download_url[i][3] === '') continue
275
276 if (new_download_url[i][3] !== undefined) {
277 url = new_download_url[i][3] + href
278 } else {
279 url = new_download_url[i][0] + href
280 }
281 html_clone_a.href = url
282 html_clone_a.setAttribute('title', new_download_url[i][2].replaceAll('&#10;','\n') + '\n\n提示:如果不想要点击链接在前台打开空白新标签页(一闪而过影响体验),\n可以 [鼠标中键] 或 [Ctrl+鼠标左键] 点击加速链接即可在后台打开新标签页!');
283 html_clone_a.setAttribute('target', '_blank');
284 html_clone_a.setAttribute('rel', 'noreferrer noopener nofollow');
285 html_clone_span.textContent = 'Download ZIP ' + new_download_url[i][1]
286 _html += html_clone.outerHTML
287 }
288 html.insertAdjacentHTML('afterend', _html);
289 }
290
291 // Git Clone 切换清理
292 function addGitCloneClear(css) {

Callers 1

callbackFunction · 0.85

Calls 1

get_New_download_urlFunction · 0.85

Tested by

no test coverage detected