Last active
May 9, 2023 10:09
-
-
Save Efreak/37f63b423306f1f7b9fd71096d2293a3 to your computer and use it in GitHub Desktop.
Check Stable Horde kudos on a timer. Until @db0 adds X-Fields to access-control-allow-headers, you'll have to comment out line 163
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<title>API timer</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script>/* via https://github.com/center-key/pretty-print-json/blob/a7c1bda5fcd29a65894f3e68ac9ee870bb202481/src/pretty-print-json.ts */ const prettyPrintJson={toHtml(n,e){const l=Object.assign(Object.assign({},{indent:3,lineNumbers:!1,linkUrls:!0,linksNewTab:!0,quoteKeys:!1,trailingComma:!0}),e),s=(n,e)=>e?"<span class=json-"+n+">"+e+"</span>":"",t=(JSON.stringify(n,null,l.indent)||"undefined").replace(/[<>&]|\\"/g,(n=>"<"===n?"<":">"===n?">":"&"===n?"&":"\"")).replace(/^( *)("[^"]+": )?("[^"]*"|[\w.+-]*)?([{}[\],]*)?$/gm,((n,e,t,a,i)=>{var r;const o={indent:e,key:t,value:a,end:i},u=l.quoteKeys?/(.*)(): /:/"([\w$]+)": |(.*): /,c=o.indent||"",d=o.key&&o.key.replace(u,"$1$2"),k=o.key?s("key",d)+s("mark",": "):"",m=o.value?(n=>{const e=/^"/.test(n)&&"string",t=(["true","false"].includes(n)?"boolean":"null"===n&&"null")||e||"number",a=l.linksNewTab?" target=_blank":"",i=e&&l.linkUrls?n.replace(/https?:\/\/[^\s"]+/g,(n=>`<a class=json-link href="${n}"${a}>${n}</a>`)):n;return s(t,i)})(o.value):"",g=!o.end||["]","}"].includes(n.at(-1)),p=l.trailingComma&&" "===n.at(0)&&g;return c+k+m+s("mark",p?(null!==(r=o.end)&&void 0!==r?r:"")+",":o.end)})),a=n=>` <li>${n}</li>`;return l.lineNumbers?(n=>["<ol class=json-lines>",...n.split("\n").map(a),"</ol>"].join("\n"))(t):t}};</script> | |
<script type="module" src="https://unpkg.com/dark-mode-toggle"></script> | |
<link rel="stylesheet" href="https://googlechromelabs.github.io/dark-mode-toggle/demo/slider.css"> | |
<style>/* via https://github.com/center-key/pretty-print-json/blob/a7c1bda5fcd29a65894f3e68ac9ee870bb202481/src/pretty-print-json.prefers.css */ | |
/* pretty-print-json ~ MIT License */ | |
/* Layout */ | |
.json-container { font-family: menlo, consolas, monospace; font-style: normal; font-weight: bold; line-height: 1.4em; font-size: 0.9rem; transition: background-color 400ms; } | |
a.json-link { text-decoration: none; border-bottom: 1px solid; outline: none; } | |
a.json-link:hover { background-color: transparent; outline: none; } | |
ol.json-lines { white-space: normal; padding-inline-start: 3em; margin: 0px; } | |
ol.json-lines >li { white-space: pre; text-indent: 0.7em; line-height: 1.5em; padding: 0px; } | |
ol.json-lines >li::marker { font-family: system-ui, sans-serif; font-weight: normal; } | |
.json-key, .json-string, .json-number, .json-boolean, .json-null, .json-mark, a.json-link, ol.json-lines >li { transition: all 400ms; } | |
.json-container { background-color: white; } | |
.json-key { color: brown; } | |
.json-string { color: olive; } | |
.json-number { color: navy; } | |
.json-boolean { color: teal; } | |
.json-null { color: dimgray; } | |
.json-mark { color: black; } | |
a.json-link { color: purple; } | |
a.json-link:visited { color: slategray; } | |
a.json-link:hover { color: blueviolet; } | |
a.json-link:active { color: slategray; } | |
ol.json-lines >li::marker { color: dimgray; } | |
ol.json-lines >li:nth-child(odd) { background-color: gainsboro; } | |
ol.json-lines >li:nth-child(even) { background-color: whitesmoke; } | |
ol.json-lines >li:hover { background-color: lemonchiffon; } | |
.dark .json-container { background-color: black; } | |
.dark .json-key { color: indianred; } | |
.dark .json-string { color: khaki; } | |
.dark .json-number { color: deepskyblue; } | |
.dark .json-boolean { color: mediumseagreen; } | |
.dark .json-null { color: darkorange; } | |
.dark .json-mark { color: silver; } | |
.dark a.json-link { color: mediumorchid; } | |
.dark a.json-link:visited { color: slategray; } | |
.dark a.json-link:hover { color: violet; } | |
.dark a.json-link:active { color: slategray; } | |
.dark ol.json-lines >li::marker { color: silver; } | |
.dark ol.json-lines >li:nth-child(odd) { background-color: #222222; } | |
.dark ol.json-lines >li:nth-child(even) { background-color: #161616; } | |
.dark ol.json-lines >li:hover { background-color: dimgray; } | |
/* mine */ | |
body { | |
font-size: 20pt; | |
width:100%; | |
max-width:100%; | |
max-height:100%; | |
height:100%; | |
margin:0; | |
padding:0; | |
} | |
div, pre { | |
margin-top: 1.5em; | |
margin-bottom: 1.5em; | |
line-height:2em; | |
margin-left: auto; | |
margin-right: auto; | |
width: 35em; | |
display: block; | |
text-align: center; | |
} | |
input, label,#intval { | |
opacity:0.3; | |
font-size:20pt; | |
margin:0px; | |
padding: 0px; | |
border:0px; | |
display: inline-block; | |
} | |
input[type=password], label { | |
line-height:2em; | |
border:initial; | |
} | |
label { | |
width:5em; | |
} | |
input { | |
width:15em; | |
} | |
pre { | |
width:calc(35em * 1.4); | |
max-width: 100%; | |
height:calc(55em * 1.4); | |
text-align:left; | |
/*max-height:calc(100% - */ | |
overflow:auto; | |
text-align:left; | |
overflow:auto; | |
} | |
#response { | |
margin-top:0px!important; | |
} | |
.dark, .dark input { | |
background-color: black; | |
color:white; | |
} | |
.dark svg { | |
filter: invert(100%); | |
} | |
dark-mode-toggle { | |
position:fixed; | |
top:0; | |
right:0; | |
font-size:initial; | |
} | |
#kudosdiv { | |
display:none; | |
font-size:20pt; | |
} | |
#kudos { | |
font-size:25pt; | |
} | |
</style> | |
</head> | |
<body onload="resetInterval"> | |
<dark-mode-toggle appearance="toggle" mode="dark" permanent="" class="slider" remember="always"></dark-mode-toggle> | |
<div id="kudosdiv">You have <span id="kudos"></span> Kudos</div> | |
<div><label>Seconds: </label><input id="interval" type="range" min="30" max="600" step="5" value="90"><br><span id="intval">5 seconds</span></div> | |
<div><label>API key: </label><input id="apikey" type="password" autofocus></div> | |
<pre class="json-container" id="response"></pre> | |
<svg style="width:2em;height:auto;position:fixed;bottom:1em;right:1em;opacity:0.3" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 297 215"><path d="M108.4 6a101.6 101.6 0 1 0 40 194.9 101.6 101.6 0 1 0 0-186.8 101.2 101.2 0 0 0-40-8.2zm-2 31.8a70 70 0 0 1 41 13.3 70.3 70.3 0 1 1 0 114 70.3 70.3 0 1 1-41-127.3z"/><path d="M116.8 66.2H83.4c-22.5 46.7-3.7 78.5 11.2 85 15 6.7 39.3 10.8 52.9-13.6 11.1 21 36.4 22.1 53.2 14.4 16.8-7.7 33.1-43.1 11.7-85.8h-34c11.5 26.4 11.8 62.5 0 63.5-11.7 1.1-15-2.8-13.7-44.3l-33.3-.1c2.5 40.9-5.1 48-15.4 43.5-10.2-4.5-9.8-28.1.8-62.6z"/></svg> | |
<script> | |
// shortcuts cuz im lazy | |
var q = function(s){ | |
return document.querySelector(s); | |
}; | |
var l=window.localStorage; | |
l.time=l.time||90; | |
var intv; | |
// reset timer when it's changed | |
var resetInterval = function(){ | |
console.log('reset!'); | |
l.time = q("#interval").value; | |
if(q("#apikey")) { l.apikey = q("#apikey").value; } | |
q("#intval").textContent = l.time + " seconds"; | |
try { | |
clearInterval(intv); | |
} catch(e) { | |
console.log(e); | |
} | |
if (l.apikey.length > 21) { | |
intv = setInterval(update, l.time * 1000); | |
update(); | |
} | |
} | |
// grab the user's kudos, stick it in the page title. | |
// also put the full response in the page | |
var update = async function(){ | |
if (l.apikey.length > 21) { | |
const response = await fetch("https://stablehorde.net/api/v2/find_user",{headers:{ | |
apikey:l.apikey, | |
"Client-Agent":"Efreak:1:APITimer" | |
//,"X-Fields":(l.fields||"username,id,kudos,worker_count,usage") // I'm not documenting this or adding UI for it. Set localStorage.fields to something else if you want more | |
}}); | |
console.debug(response); | |
const jsonData = await response.json(); | |
console.debug(jsonData); | |
try { | |
document.title = jsonData.kudos; | |
q('#kudos').textContent=jsonData.kudos; | |
if(q('#apikey')) { q('#apikey').parentNode.parentNode.removeChild(q('#apikey').parentNode); q('#kudosdiv').style.display="block";} | |
} catch(e) { | |
window.title = jsonData.message; | |
} | |
q("#response").innerHTML=prettyPrintJson.toHtml(jsonData); | |
} | |
} | |
if(l.apikey) { | |
q("#apikey").value=l.apikey; | |
} | |
if(l.interval) { | |
q("#interval").value=l.interval; | |
} | |
// reinitialize when settings change | |
q("#apikey").addEventListener("change", resetInterval); | |
q("#interval").addEventListener("change", resetInterval); | |
// https://github.com/GoogleChromeLabs/dark-mode-toggle | |
window.addEventListener('colorschemechange', (e) => { | |
document.body.classList.toggle('dark', e.target.mode === 'dark'); | |
}); | |
resetInterval(); | |
q('svg').addEventListener('click',function(){ | |
q('pre').textContent=' DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE\n Version 2, December 2004\n\n Copyright (C) 2023 Efreak2004 <nope@nope>\n\n Everyone is permitted to copy and distribute verbatim or modified\n copies of this license document, and changing it is allowed as long\n as the name is changed.\n\n DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE\n TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n 0. You just DO WHAT THE FUCK YOU WANT TO.\n\n\n'; | |
q('pre').innerHTML+='<a href="https://gist.github.com/Efreak/37f63b423306f1f7b9fd71096d2293a3">https://gist.github.com/Efreak/37f63b423306f1f7b9fd71096d2293a3</a>'; | |
});</script> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2023 Efreak2004 <nope@nope> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment