-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub-tweak.user.js
49 lines (43 loc) · 1.4 KB
/
github-tweak.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// ==UserScript==
// @name github tweaks
// @namespace https://github.com/lilydjwg/userscripts
// @description use gzip, use ssh
// @match https://github.com/*
// @version 1.10
// @grant GM_addElement
// ==/UserScript==
(function() {
'use strict'
function prefer_gzip() {
console.log('tweak: prefer_gzip starts')
const dl = document.evaluate('//span[text()="Download ZIP"]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0)
console.log('tweak: dl', dl)
if(dl){
const re = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)(\/tree\/([^\/]+))?/
const m = re.exec(location.href)
const button_ref = document.querySelector('button#branch-picker-repos-header-ref-selector').textContent.trim()
const ref = m[4] || button_ref
dl.textContent = ''
GM_addElement(dl, 'a', {
href: `/${m[1]}/${m[2]}/archive/${ref}.tar.gz`,
textContent: 'Download tar.gz',
})
console.log('tweak: download link added')
}
}
console.log('tweak: start')
document.addEventListener('click', function() {
setTimeout(prefer_gzip, 100)
})
const repourl = document.querySelectorAll('.js-live-clone-url')
const re = /https:\/\/github\.com\/([^\/]+)\/(.*)/
let span, m
let i, len
for(i=0, len=repourl.length; i<len; i++){
span = repourl[i]
m = re.exec(span.textContent)
if(m){
span.textContent = '[email protected]:'+m[1]+'/'+m[2]
}
}
})()