initial commit
This commit is contained in:
commit
3f60e03c98
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.env
|
||||
index.html
|
||||
script.js
|
9
Makefile
Normal file
9
Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
include .env
|
||||
|
||||
gensite:
|
||||
sed -e "s#GITEA_SITE#${GITEA_SITE}#" script.template.js > script.js
|
||||
sed -e "s#GITEA_SITE_NAME#${GITEA_SITE_NAME}#" index.template.html > index.html
|
||||
sed -i -e "s#GITEA_SITE_NAME#${GITEA_SITE_NAME}#" index.html
|
||||
|
||||
clean:
|
||||
rm -rf index.html script.js
|
33
index.template.html
Normal file
33
index.template.html
Normal file
@ -0,0 +1,33 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
@import url("https://styles.alv.cx/colors/gruvbox.css");
|
||||
@import url("https://styles.alv.cx/base.css");
|
||||
@import url("https://styles.alv.cx/modules/darkmode.css");
|
||||
@import url("https://styles.alv.cx/modules/search.css");
|
||||
|
||||
:root {
|
||||
--light: var(--colorscheme-light);
|
||||
}
|
||||
</style>
|
||||
<title>reposearch</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>reposearch</h1>
|
||||
<p>private and fast search as you type for <a href="GITEA_SITE">GITEA_SITE_NAME</a>.</p>
|
||||
<p>
|
||||
<a href="GITEA_SITE/alvierahman90/reposearch">source</a>
|
||||
<span id="access_token_inputs">
|
||||
<button id="set_access_token">set access token</button>
|
||||
</span>
|
||||
</p>
|
||||
<div id="searchWrapper"> <input id="search" placeholder="Search"> </div>
|
||||
<p class="searchSmallText" style="margin-top: 0; text-align: center">
|
||||
Press (<kbd>Shift</kbd>+)<kbd>Enter</kbd> to open first result (in new tab)
|
||||
</p>
|
||||
<div id="results"></div>
|
||||
<script src="/fuse.js"></script>
|
||||
<script src="/script.js"></script>
|
||||
</body>
|
11
readme.txt
Normal file
11
readme.txt
Normal file
@ -0,0 +1,11 @@
|
||||
reposearch
|
||||
----------
|
||||
|
||||
create a .env file:
|
||||
|
||||
GITEA_SITE=https://example.com
|
||||
GITEA_SITE_NAME=Human Friendly Name
|
||||
|
||||
|
||||
run
|
||||
make
|
132
script.template.js
Normal file
132
script.template.js
Normal file
@ -0,0 +1,132 @@
|
||||
var searchBar = document.getElementById('search');
|
||||
var resultsDiv = document.getElementById('results');
|
||||
var accessTokenInputsDiv = document.getElementById('access_token_inputs');
|
||||
var setAccessTokenA = document.getElementById('set_access_token');
|
||||
|
||||
var options = {
|
||||
findAllMatches: true,
|
||||
keys: [
|
||||
'name',
|
||||
'description',
|
||||
]
|
||||
}
|
||||
|
||||
var results = [];
|
||||
var REPOS = [];
|
||||
var fuse = new Fuse(REPOS, options)
|
||||
|
||||
function setCookie(name, value, seconds) {
|
||||
var expires = "";
|
||||
if (seconds) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (seconds*1000));
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
||||
}
|
||||
|
||||
function getCookie(name) {
|
||||
var nameEQ = name + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for(var i=0;i < ca.length;i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0)==' ') c = c.substring(1,c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function eraseCookie(name) {
|
||||
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
||||
}
|
||||
|
||||
function get(url, cb, errcb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var u = new URL(url);
|
||||
u.searchParams.set('access_token', getCookie('access_token'))
|
||||
xhr.responseType = 'json';
|
||||
xhr.open('GET', u);
|
||||
xhr.send()
|
||||
xhr.onload = cb;
|
||||
xhr.onerror = errcb
|
||||
}
|
||||
|
||||
function loadRepos() {
|
||||
get('GITEA_SITE/api/v1/user/repos?limit=50000',
|
||||
function(x) {
|
||||
console.log('loadRepos');
|
||||
console.log(x);
|
||||
REPOS = x.target.response;
|
||||
console.log(REPOS);
|
||||
fuse = new Fuse(REPOS, options);
|
||||
applySearch();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function applySearch() {
|
||||
results = fuse.search(searchBar.value);
|
||||
console.log(results)
|
||||
resultsDiv.innerHTML = "";
|
||||
results.forEach(function(r) {
|
||||
p = document.createElement('div');
|
||||
p.classList.add('searchResult');
|
||||
fullNameDiv = document.createElement('div');
|
||||
fullNameDiv.innerHTML = r.item.full_name;
|
||||
aDiv = document.createElement('a');
|
||||
aDiv.href = r.item.html_url;
|
||||
aDiv.appendChild(fullNameDiv);
|
||||
descriptionDiv = document.createElement('div');
|
||||
descriptionDiv.classList.add('searchSmallText');
|
||||
descriptionDiv.innerHTML = 'description: ' + r.item.description;
|
||||
propertiesDiv = document.createElement('div');
|
||||
propertiesDiv.classList.add('searchSmallText');
|
||||
propertiesDiv.innerHTML += r.item.private ? "private" : "";
|
||||
propertiesDiv.innerHTML += r.item.archived ? " archived" : "";
|
||||
p.appendChild(aDiv);
|
||||
p.appendChild(descriptionDiv);
|
||||
p.appendChild(propertiesDiv);
|
||||
resultsDiv.appendChild(p);
|
||||
});
|
||||
}
|
||||
|
||||
function openAccessTokenInput() {
|
||||
var accessTokenInput = document.createElement('input');
|
||||
accessTokenInput.placeholder = 'access token';
|
||||
accessTokenInput.type = 'password';
|
||||
|
||||
function setAccessToken(ev) {
|
||||
if (ev.key != "Enter") return;
|
||||
|
||||
setCookie('access_token', accessTokenInput.value);
|
||||
|
||||
setAccessTokenA = document.createElement('a');
|
||||
setAccessTokenA.innerHTML = 'set access token';
|
||||
setAccessTokenA.addEventListener('click', openAccessTokenInput);
|
||||
|
||||
accessTokenInputsDiv.innerHTML = '';
|
||||
accessTokenInputsDiv.appendChild(setAccessTokenA);
|
||||
}
|
||||
|
||||
accessTokenInput.addEventListener('keyup', setAccessToken);
|
||||
|
||||
accessTokenInputsDiv.innerHTML = '';
|
||||
accessTokenInputsDiv.appendChild(accessTokenInput);
|
||||
}
|
||||
|
||||
setAccessTokenA.addEventListener('click', openAccessTokenInput);
|
||||
|
||||
searchBar.focus();
|
||||
|
||||
searchBar.addEventListener('change', applySearch);
|
||||
searchBar.addEventListener('keyup', applySearch);
|
||||
searchBar.addEventListener('keypress', function(ev) {
|
||||
if (ev.key != "Enter") return
|
||||
|
||||
if (ev.shiftKey) window.open(results[0].item.html_url, '_blank');
|
||||
else window.location.href = results[0].item.html_url;
|
||||
});
|
||||
|
||||
|
||||
// attempt to load repos if user is authenticated
|
||||
if (getCookie('access_token')) loadRepos();
|
Loading…
Reference in New Issue
Block a user