-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubdir.js
More file actions
117 lines (107 loc) · 4.75 KB
/
githubdir.js
File metadata and controls
117 lines (107 loc) · 4.75 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const gitDataFetcher = function(url,dir){
const myHeaders = new Headers();
if(api.token){
myHeaders.append("Authorization", "Bearer " + api.token);
}
myHeaders.append("Cookie", "_octo=GH1.1.1855976736.1707942526; logged_in=no");
const requestOptions = {
method: "GET",
headers: myHeaders,
redirect: "follow"
}
//?recursive=1
fetch(url, requestOptions)
.then((response) => response.json())
.then((result) => displayData(result,dir))
.catch((error) => console.error(error));
}
const displayData = function(obj,dir){
dir = dir ? dir + '/' : '/';
const list = document.getElementById('list');
const nav = document.getElementById('nav');
if(obj.hasOwnProperty('message')){
const msg = document.createTextNode(obj.message);
(nav || list).appendChild(msg);
return;
}
if(obj.hasOwnProperty('git_url')){
obj = [obj];
}
(obj.tree || obj).forEach(function(data){
if(data.hasOwnProperty('git_url') && data.name === config.repo){
gitDataFetcher(api.baseUrl + '/repos/' + config.acct + '/' + data.name + '/branches'); // {/branch}
}else if(data.hasOwnProperty('commit') && data.name === config.branch){
gitDataFetcher(api.baseUrl + '/repos/' + config.acct + '/' + config.repo + '/git/trees/' + data.commit.sha); // {/sha}
}else if(data.hasOwnProperty('type') && data.type === 'tree'){
if(nav && !data.path.includes('.idea') && !data.path.includes('_template')){
const a = document.createElement('a');
a.href = site.baseUrl + dir + data.path;
a.innerHTML = data.path;
a.classList.add("me-1");
a.classList.add("text-dark");
const delim = document.createTextNode(" ");
nav.appendChild(a);
nav.appendChild(delim);
const l = document.createElement('a');
l.href = 'https://' + data.path;
l.innerHTML = '↱';
l.classList.add("me-1");
l.classList.add("small");
l.classList.add("text-muted");
nav.appendChild(l);
nav.appendChild(delim);
}
if(window.location.pathname.includes(data.path)){
gitDataFetcher(data.url,dir + data.path);
response.count++;
}
}else if(data.hasOwnProperty('path') && !data.path.includes('git') && !data.path.includes('.cpt') && !data.path.includes('.md') && !data.path.includes('.htm') && !data.path.includes('.xml') && !data.path.includes('.iml') && !data.path.includes('.webmanifest')){
const l = document.createElement('a');
l.href = site.baseUrl + dir + data.path;
l.innerHTML = '⇝';
l.classList.add("me-1");
l.classList.add("text-muted");
const a = document.createElement('a');
a.href = site.baseUrl + dir + data.path;
a.innerHTML = site.baseUrl + dir + data.path;
a.classList.add("me-1");
a.classList.add("text-dark");
l.addEventListener('mouseover', function() {
document.getElementById('imgsrc').src = this.href;
document.getElementById('imgsrc-dk').src = this.href;
});
l.addEventListener('mouseout', function() {
document.getElementById('imgsrc').src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
document.getElementById('imgsrc-dk').src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
});
response.response.push(site.baseUrl + dir + data.path);
const li = document.createElement('li');
li.appendChild(a);
li.appendChild(l);
list.appendChild(li);
}
})
}
//site
const site = {};
site.baseUrl = 'https://imgsrc.cloud';
//api data
const api = {};
api.baseUrl = 'https://api.github.com';
api.zapUrl = 'https://zzzap.io/Utilities/formatting/zcd-read/text/zCd-88003555d757a02a3a3766a1da08c37f';
//target data
const config = {};
config.acct = 'Saran-pariyar'; //'quasicodo42'; //
config.repo = 'imgsrc'; //'HTMW'; //
config.branch = 'main';
//storage
const response = {config:config,response:[],count:0};
fetch(api.zapUrl)
.then((response) => response.json())
.then((result) => gitInit(result))
.catch((error) => console.error(error));
const gitInit = function(response){
api.token = response.response || null;
//gitDataFetcher(api.baseUrl + '/users/' + config.acct + '/repos');
gitDataFetcher(api.baseUrl + '/repos/' + config.acct + '/' + config.repo);
}