function download(url) { console.log(url); fetch(url) .then(response => response.blob()) .then(blob => { const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = url.split('/').pop(); link.target = '_blank'; link.click(); }) .catch(console.error); } function formatTime(s) { return Math.floor(s / 60).toString().padStart(2, '0') + ':' + (s % 60).toString().padStart(2, '0'); } // this is literally a find replace in the css function setTheme(theme) { Array.from(document.styleSheets).map(e => { try { return Array.from(e.cssRules) } catch (e) { return [] } }).flat().map(e => { if (e.constructor != CSSMediaRule) return; if (e.originalConditionText) e.conditionText = e.originalConditionText; else e.originalConditionText = e.conditionText if (theme == "system") return let match = e.conditionText.match(/prefers-color-scheme:\s*(light|dark)/i) if (!match) return; e.conditionText = e.conditionText.replace(match[0], (match[1].toLowerCase() == theme ? 'min' : 'max') + '-width: 0') }); } function getWebsocketLocation() { return window.window.location.replace('https://', 'wss://').replace('http://', 'ws://'); } window.onload = () => { // dirty theme hacks :tm: const color = window.getComputedStyle(document.querySelector('body')).getPropertyValue('color'); const rgbRegex = /rgb\((\d+), ?(\d+), ?(\d+)\)/; const r = rgbRegex.exec(color); let brightness = (Number(r[1]) + Number(r[2]) + Number(r[3])) / (255 * 3); if (brightness > 0.5) { // light text, dark theme document.getElementById('theme-switch').checked = true } else { // dark text, light theme document.getElementById('theme-switch').checked = false } document.getElementById('theme-switch').addEventListener('click', () => { setTheme(document.getElementById('theme-switch').checked ? 'dark' : 'light'); }); const placeholders = [ 'xilent - we are dust', 'joyryde - brave', 'phaseone - the risen ep', 'blanke & godlands - hellraiser', 'camellia - blackmagik blazing', 't+pazolite - without permission', 'the brig - vindicate', 'bossfight - next wave' ]; const search = document.getElementById('album-search'); search.setAttribute('placeholder', placeholders[Math.floor(Math.random() * placeholders.length)]); async function change() { const value = document.getElementById('album-search').value; if (value === '') return document.getElementById('albums').innerHTML = ''; document.getElementById('progress-album').innerHTML = ''; document.getElementById('progress-bar-wrapper').innerHTML = ''; document.getElementById('albums').innerHTML = '