@@ -13,6 +13,7 @@ data["example.test.cpp"] = (function () {
13
13
} ) ( ) ;
14
14
15
15
const input = document . getElementById ( "input" ) ;
16
+ const inputBranch = document . getElementById ( "input-branch" ) ;
16
17
const output = document . getElementById ( "output" ) ;
17
18
const output2 = document . getElementById ( "output2" ) ;
18
19
const output3 = document . getElementById ( "output3" ) ;
@@ -27,22 +28,36 @@ const output11 = document.getElementById("output11");
27
28
const output12 = document . getElementById ( "output12" ) ;
28
29
const output13 = document . getElementById ( "output13" ) ;
29
30
30
- function update ( ) {
31
+ function retrieveDefaultBranch ( ) {
32
+ const found = input . value . match ( / \/ g i t h u b .c o m \/ ( [ ^ \/ ] + ) \/ ( [ ^ \/ ] + ) / ) ;
33
+ if ( ! found ) return ;
34
+ const url = "https://api.github.com/repos/" + found [ 1 ] + "/" + found [ 2 ] ;
35
+ const req = new XMLHttpRequest ( ) ;
36
+ req . open ( "GET" , url , false ) ;
37
+ req . send ( ) ;
38
+ const resp = JSON . parse ( req . responseText ) ;
39
+ if ( resp [ 'default_branch' ] ) {
40
+ inputBranch . value = resp [ 'default_branch' ] ;
41
+ }
42
+ }
43
+
44
+ function updateLinks ( ) {
31
45
const found = input . value . match ( / \/ g i t h u b .c o m \/ ( [ ^ \/ ] + ) \/ ( [ ^ \/ ] + ) / ) ;
32
46
if ( found ) {
33
47
const url = input . value . replace ( / \/ $ / , "" ) ;
34
48
const ghpages = "https://" + found [ 1 ] + ".github.io/" + found [ 2 ] + "/" ;
49
+ const branch = inputBranch . value ;
35
50
36
51
// adding verify.yml
37
52
const filename = ".github%2Fworkflows%2Fverify.yml"
38
53
const value = encodeURIComponent ( data [ "verify.yml" ] . replace ( "git+https://github.com/online-judge-tools/verification-helper.git@master" , "online-judge-verify-helper" ) ) ;
39
- output . href = url + "/new/master ?filename=" + filename + "&value=" + value ;
54
+ output . href = url + "/new/" + branch + " ?filename=" + filename + "&value=" + value ;
40
55
output . textContent = url + "&value=..." ;
41
56
42
57
// adding example.text.cpp
43
58
const filename2 = "example.test.cpp" ;
44
59
const value2 = encodeURIComponent ( data [ "example.test.cpp" ] ) ;
45
- output2 . href = url + "/new/master ?filename=" + filename2 + "&value=" + value2 ;
60
+ output2 . href = url + "/new/" + branch + " ?filename=" + filename2 + "&value=" + value2 ;
46
61
47
62
// links to GitHub Actions
48
63
output3 . href = input . value . replace ( / \/ $ / , "" ) + "/actions" ;
@@ -66,6 +81,14 @@ function update() {
66
81
output13 . href = url + "/commits/gh-pages" ;
67
82
}
68
83
}
84
+
85
+ function update ( ) {
86
+ retrieveDefaultBranch ( ) ;
87
+ updateLinks ( ) ;
88
+ }
89
+
69
90
input . addEventListener ( 'change' , update ) ;
70
91
input . addEventListener ( 'keyup' , update ) ;
71
- update ( ) ;
92
+ inputBranch . addEventListener ( 'change' , updateLinks ) ;
93
+ inputBranch . addEventListener ( 'keyup' , updateLinks ) ;
94
+ updateLinks ( ) ;
0 commit comments