`;
// 循环组合 URL 链接
for (let i=0;i -1) url[i] = url[i].replace('https://download.fastgit.org','https://archive.fastgit.org')
}
// 循环生成 HTML 标签
for (let i=0;i${download_url[i][1]}`
}
_html += `
`
_this.insertAdjacentHTML('afterend', _html);
});
});
}
// Download ZIP
function addDownloadZIP() {
if (document.querySelector('.XIU2-DZ')) return
let html = document.querySelector('.dropdown-menu.dropdown-menu-sw.p-0 ul li:last-child');if (!html) return
let href = html.getElementsByTagName('a')[0].href,
url = [],
_html = ``;
for (let i=0;i -1) url[i] = url[i].replace('https://download.fastgit.org','https://archive.fastgit.org')
}
for (let i=0;i${svg[0]}Download ZIP ${download_url[i][1]}`
}
html.insertAdjacentHTML('afterend', _html);
}
// Git Clone
function addGitClone() {
if (document.querySelector('.XIU2-GC')) return
let html = document.querySelector('[role="tabpanel"]:nth-child(2) div.input-group');if (!html) return
let href_split = html.getElementsByTagName('input')[0].getAttribute('value').split(location.host),
url = [],
_html = ``;
for (let i=0;i
${svg[1]}
`
}
html.insertAdjacentHTML('afterend', _html);
}
// Git Clone SSH
function addGitCloneSSH() {
if (document.querySelector('.XIU2-GCS')) return
let html = document.querySelector('[role="tabpanel"]:nth-child(3) div.input-group');if (!html) return
let href_split = html.getElementsByTagName('input')[0].getAttribute('value').split(':'),
url = [],
_html = ``;
if (href_split[0] != 'git@github.com') return
for (let i=0;i
${svg[1]}
`
}
html.insertAdjacentHTML('afterend', _html);
}
// Raw
function addRawFile() {
if (document.querySelector('.XIU2-RF')) return
let html = document.getElementById('raw-url');if (!html) return
let href = location.href.replace(`https://${location.host}`,''),
href2 = href.replace('/blob/','/'),
url = [
raw_url[1][0] + '/gh' + href.replace('/blob/','@'),
raw_url[2][0] + href2,
raw_url[3][0] + '/gh' + href.replace('/blob/','/')
],
_html = ``;
for (let i=0;i${raw_url[i+1][1]}`
}
html.insertAdjacentHTML('afterend', _html);
}
// 添加 Raw 下载链接(☁)
function addRawDownLink() {
// 如果不是项目文件页面,就返回,如果网页有 Raw 下载链接(☁)就返回
let files = document.querySelectorAll('div.Box-row svg.octicon.octicon-file');if(files.length === 0) return;if (location.pathname.indexOf('/tags') > -1) return
let files1 = document.querySelectorAll('a.fileDownLink');if(files1.length > 0) return;
// 鼠标指向则显示
var mouseOverHandler = function(evt) {
let elem = evt.currentTarget,
aElm_new = elem.querySelectorAll('.fileDownLink'),
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file');
aElm_new.forEach(el=>{el.style.cssText = 'display: inline'});
aElm_now.forEach(el=>{el.style.cssText = 'display: none'});
};
// 鼠标离开则隐藏
var mouseOutHandler = function(evt) {
let elem = evt.currentTarget,
aElm_new = elem.querySelectorAll('.fileDownLink'),
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file');
aElm_new.forEach(el=>{el.style.cssText = 'display: none'});
aElm_now.forEach(el=>{el.style.cssText = 'display: inline'});
};
// 循环添加
files.forEach(function(fileElm, i) {
let trElm = fileElm.parentNode.parentNode,
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'),
Name = cntElm_a.innerText,
href = cntElm_a.attributes.href.nodeValue.replace(`https://${location.host}`,'');
let href2 = href.replace('/blob/','/'), url, url_name, url_tip = '';
switch(menu_raw_fast) {
case 0:
case 2:
url = raw_url[menu_raw_fast][0] + href2; break;
case 1:
url = raw_url[menu_raw_fast][0] + '/gh' + href.replace('/blob/','@'); break;
case 3:
url = raw_url[menu_raw_fast][0] + '/gh' + href.replace('/blob/','/'); break;
default:
url = raw_url[menu_raw_fast][0] + '/' + raw_url[0][0] + href2;
}
url_name = raw_url[menu_raw_fast][1]; url_tip = raw_url[menu_raw_fast][2];
let _html = ` ${svg[2]}`;
cntElm_svg.insertAdjacentHTML('afterend', _html);
// 绑定鼠标事件
trElm.onmouseover = mouseOverHandler;
trElm.onmouseout = mouseOutHandler;
});
}
// 删除 Raw 快捷下载(☁)
function delRawDownLink() {
let aElm = document.querySelectorAll('.fileDownLink');if(aElm.length === 0) return;
aElm.forEach(function(fileElm) {
fileElm.remove()
})
}
// 在浏览器返回/前进时重新添加 Raw 下载链接(☁)鼠标事件
function addRawDownLink_() {
// 如果不是项目文件页面,就返回,如果网页没有 Raw 下载链接(☁)就返回
let files = document.querySelectorAll('div.Box-row svg.octicon.octicon-file');if(files.length === 0) return;
let files1 = document.querySelectorAll('a.fileDownLink');if(files1.length === 0) return;
// 鼠标指向则显示
var mouseOverHandler = function(evt) {
let elem = evt.currentTarget,
aElm_new = elem.querySelectorAll('.fileDownLink'),
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file');
aElm_new.forEach(el=>{el.style.cssText = 'display: inline'});
aElm_now.forEach(el=>{el.style.cssText = 'display: none'});
};
// 鼠标离开则隐藏
var mouseOutHandler = function(evt) {
let elem = evt.currentTarget,
aElm_new = elem.querySelectorAll('.fileDownLink'),
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file');
aElm_new.forEach(el=>{el.style.cssText = 'display: none'});
aElm_now.forEach(el=>{el.style.cssText = 'display: inline'});
};
// 循环添加
files.forEach(function(fileElm, i) {
let trElm = fileElm.parentNode.parentNode;
// 绑定鼠标事件
trElm.onmouseover = mouseOverHandler;
trElm.onmouseout = mouseOutHandler;
});
}
// 自定义 locationchange 事件(用来监听 URL 变化)
function addLocationchange() {
history.pushState = ( f => function pushState(){
var ret = f.apply(this, arguments);
window.dispatchEvent(new Event('pushstate'));
window.dispatchEvent(new Event('locationchange'));
return ret;
})(history.pushState);
history.replaceState = ( f => function replaceState(){
var ret = f.apply(this, arguments);
window.dispatchEvent(new Event('replacestate'));
window.dispatchEvent(new Event('locationchange'));
return ret;
})(history.replaceState);
window.addEventListener('popstate',()=>{
window.dispatchEvent(new Event('locationchange'))
});
}
console.log('ds_github loaded')
})();