init
This commit is contained in:
40
app/static/scripts/downloadsTable.js
Normal file
40
app/static/scripts/downloadsTable.js
Normal file
@@ -0,0 +1,40 @@
|
||||
function addItem(url) {
|
||||
getFileSize(url, insertRow);
|
||||
}
|
||||
|
||||
async function getFileSize(url, myCallback) {
|
||||
// needs proper cors config
|
||||
var http = new XMLHttpRequest();
|
||||
http.open('HEAD', url, true); // true = Asynchronous
|
||||
http.onreadystatechange = function() {
|
||||
if (this.readyState == this.DONE) {
|
||||
if (this.status === 200) {
|
||||
myCallback(url,parseInt(this.getResponseHeader('content-length')));
|
||||
}
|
||||
}
|
||||
};
|
||||
http.send();
|
||||
}
|
||||
|
||||
function insertRow(url, size) {
|
||||
let table = document.getElementById("table");
|
||||
var newRow = table.insertRow(table.length);
|
||||
|
||||
let suffixes = ["B", "KB", "MB", "GB", "TB"];
|
||||
var sindex = 0;
|
||||
while(size > 1024) {
|
||||
sindex+=1;
|
||||
size/=1024;
|
||||
}
|
||||
|
||||
newRow.insertCell(0).innerHTML = "<a href="+url+" download>"+url.split("/").pop()+"</a>";
|
||||
newRow.insertCell(1).innerHTML = pRound(size) + " " + suffixes[sindex];
|
||||
}
|
||||
|
||||
function pRound(num) {
|
||||
// pretty round
|
||||
mult = Math.ceil(Math.pow(10,3-String(num).split(".",1)[0].length));
|
||||
return Math.round(num*mult)/mult;
|
||||
}
|
||||
|
||||
// thoughts and prayers for everyone working in javascript
|
||||
31
app/static/scripts/randImage.js
Normal file
31
app/static/scripts/randImage.js
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
function randImg() {
|
||||
var arrayImg = new Array();
|
||||
|
||||
arrayImg.push("1605617441753.png");
|
||||
arrayImg.push("1613916651677.png");
|
||||
arrayImg.push("1624171748298.png");
|
||||
arrayImg.push("1628050647008.webp");
|
||||
arrayImg.push("20220301_152225.jpg");
|
||||
arrayImg.push("20220308_211848.jpg");
|
||||
arrayImg.push("20220404_132144.jpg");
|
||||
arrayImg.push("20220404_132233.jpg");
|
||||
arrayImg.push("20220430_093257.jpg");
|
||||
arrayImg.push("20220502_103812.jpg");
|
||||
arrayImg.push("20220509_142239.jpg");
|
||||
arrayImg.push("EuyVfk9XYAEGA-x.jpg");
|
||||
arrayImg.push("FECoZcOWQAQmwd9.jpeg");
|
||||
arrayImg.push("FH5XkuZVkAI8VnL.jpg");
|
||||
arrayImg.push("FHIyMT7X0AowdpZ.png");
|
||||
arrayImg.push("FIQqCbOVcAIjZjY.jpg");
|
||||
arrayImg.push("FSkGFVKacAA8Opl.jpg");
|
||||
arrayImg.push("__kiryu_coco_and_bagpipe_hololive_and_1_more_drawn_by_chain_s__sample-a6b80c5333561d788a328239d51066dc.jpg");
|
||||
arrayImg.push("ahp3YdbjFcPQgwPDiqu4Cg.png");
|
||||
|
||||
var img = arrayImg[ Math.floor( Math.random() * arrayImg.length ) ];
|
||||
document.getElementById('randomImageGoesHere').src = "https://storage.googleapis.com/drath-public/rand/"+img;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
16
app/static/scripts/renault-calculator.js
Normal file
16
app/static/scripts/renault-calculator.js
Normal file
@@ -0,0 +1,16 @@
|
||||
document.getElementById("precode").addEventListener("keyup",code);
|
||||
|
||||
function code() {
|
||||
// lovingly stolen from https://github.com/kpym/autoradio-renault
|
||||
var precode = document.getElementById("precode").value.toUpperCase();
|
||||
|
||||
if (!/^[A-Z]\d{3}$/.test(precode) || precode.startsWith("A0")) { return ''; }
|
||||
|
||||
x = precode.charCodeAt(1) + precode.charCodeAt(0) * 10 - 698;
|
||||
y = precode.charCodeAt(3) + precode.charCodeAt(2) * 10 + x - 528;
|
||||
z = (y*7) % 100;
|
||||
code = Math.floor(z / 10) + (z % 10) * 10 + ((259 % x) % 100) * 100;
|
||||
|
||||
document.getElementById("code").value = code.toString().padStart(4,'0');
|
||||
// document.getElementById('code').innerHTML = code.toString().padStart(4,'0');
|
||||
}
|
||||
25
app/static/scripts/service-worker.js
Normal file
25
app/static/scripts/service-worker.js
Normal file
@@ -0,0 +1,25 @@
|
||||
// we're **progressive** now
|
||||
|
||||
const ASSETS = [
|
||||
"/resources/",
|
||||
"/index.htm",
|
||||
"/secrets/",
|
||||
"/"
|
||||
];
|
||||
|
||||
let cache_name = "SimiCart"; // The string used to identify our cache
|
||||
self.addEventListener("install", event => {
|
||||
console.log("installing...");
|
||||
event.waitUntil(
|
||||
caches
|
||||
.open(cache_name)
|
||||
.then(cache => {
|
||||
return cache.addAll(assets);
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", event => {
|
||||
console.log("You fetched " + event.url);
|
||||
});
|
||||
Reference in New Issue
Block a user