Skip to content

Instantly share code, notes, and snippets.

@masterflitzer
Last active March 2, 2023 08:19
Show Gist options
  • Save masterflitzer/cb42fb318b911594dda05d7d66a43af6 to your computer and use it in GitHub Desktop.
Save masterflitzer/cb42fb318b911594dda05d7d66a43af6 to your computer and use it in GitHub Desktop.
Provadis Coach: Download all files of current dir (bookmarklet)
(() => {
"use strict";
if (document.readyState !== "complete") {
globalThis.addEventListener("load", () => main());
} else main();
async function main() {
const fileTuples = Array.from(
document.querySelector("#filelist").tBodies[0].children
).reduceRight((result, e) => {
const [id, type] = e.id.split("_");
const name = e.querySelector(".name");
const filename = `${name.textContent}.${name.nextElementSibling.textContent}`;
if (type === "file") result.push([id, filename]);
return result;
}, []);
const load = spinner();
document.body.append(load);
for (const [id, filename] of fileTuples) {
const res = await fetch(
`https://hochschule.provadis-coach.de/shared/filemanager/${id}`
);
const arrayBuffer = await res.arrayBuffer();
const blob = new Blob([arrayBuffer], {
type: "application/octet-stream",
});
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = filename;
a.click();
setTimeout(() => {
URL.revokeObjectURL(a.href);
}, 1000);
}
load.remove();
}
function spinner() {
const container = document.createElement("div");
container.style.width = "100%";
container.style.height = "100%";
container.style.top = "0";
container.style.position = "fixed";
container.style.display = "flex";
container.style.placeContent = "center";
container.style.placeItems = "center";
const shadow = container.attachShadow({ mode: "open" });
const style = document.createElement("style");
style.textContent = css();
shadow.append(style);
const div = document.createElement("div");
div.style.borderTopColor = "grey";
for (let i = 3; i >= 0; i--) {
div.append(div.cloneNode());
}
div.classList.add("loading-spinner");
shadow.append(div);
return container;
}
function css() {
return `
*,
::before,
::after {
box-sizing: border-box;
font-size: 16px;
}
.loading-spinner {
display: inline-block;
position: relative;
width: 10rem;
height: 10rem;
}
.loading-spinner div {
display: block;
position: absolute;
width: 8rem;
height: 8rem;
margin: 1rem;
border: 1rem solid;
border-radius: 50%;
animation: loading-spinner 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: transparent;
}
.loading-spinner div:nth-child(1) {
animation-delay: -0.45s;
}
.loading-spinner div:nth-child(2) {
animation-delay: -0.3s;
}
.loading-spinner div:nth-child(3) {
animation-delay: -0.15s;
}
@keyframes loading-spinner {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
`;
}
})();
(() => {"use strict";if (document.readyState !== "complete") {globalThis.addEventListener("load", () => main());} else main();async function main() {const fileTuples = Array.from(document.querySelector("#filelist").tBodies[0].children).reduceRight((result, e) => {const [id, type] = e.id.split("_");const name = e.querySelector(".name");const filename = `${name.textContent}.${name.nextElementSibling.textContent}`;if (type === "file") result.push([id, filename]);return result;}, []);const load = spinner();document.body.append(load);for (const [id, filename] of fileTuples) {const res = await fetch(`https://hochschule.provadis-coach.de/shared/filemanager/${id}`);const arrayBuffer = await res.arrayBuffer();const blob = new Blob([arrayBuffer], { type: "application/octet-stream" });const a = document.createElement("a");a.href = URL.createObjectURL(blob);a.download = filename;a.click();setTimeout(() => {URL.revokeObjectURL(a.href);}, 1000);}load.remove();}function spinner() {const container = document.createElement("div");container.style.width = "100%";container.style.height = "100%";container.style.top = "0";container.style.position = "fixed";container.style.display = "flex";container.style.placeContent = "center";container.style.placeItems = "center";const shadow = container.attachShadow({ mode: "open" });const style = document.createElement("style");style.textContent = css();shadow.append(style);const div = document.createElement("div");div.style.borderTopColor = "grey";for (let i = 3; i >= 0; i--) {div.append(div.cloneNode());}div.classList.add("loading-spinner");shadow.append(div);return container;}function css() {return `*,::before,::after {box-sizing: border-box;font-size: 16px;}.loading-spinner {display: inline-block;position: relative;width: 10rem;height: 10rem;}.loading-spinner div {display: block;position: absolute;width: 8rem;height: 8rem;margin: 1rem;border: 1rem solid;border-radius: 50%;animation: loading-spinner 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;border-color: transparent;}.loading-spinner div:nth-child(1) {animation-delay: -0.45s;}.loading-spinner div:nth-child(2) {animation-delay: -0.3s;}.loading-spinner div:nth-child(3) {animation-delay: -0.15s;}@keyframes loading-spinner {0% {transform: rotate(0deg);}100% {transform: rotate(360deg);}}`;}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment