From 2cf2d87a354ddcae21dd4bcdd119367d0cda9906 Mon Sep 17 00:00:00 2001 From: Lucas <50644934+RandomPerson3465@users.noreply.github.com> Date: Sat, 30 Dec 2023 19:19:10 -0800 Subject: [PATCH 1/2] Fix abbreviations + Label colors now adjust Abbreviations now work correctly. Before: 123,500 -> 124,000 Now: 123,500 -> 123,000 Label colors will now adjust automatically to allow for dark backgrounds. --- top50/index.css | 4 ++++ top50/index.js | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/top50/index.css b/top50/index.css index 6618e5a..6c36e89 100644 --- a/top50/index.css +++ b/top50/index.css @@ -14,6 +14,10 @@ label,h1,h2,h3,h4,h5,h6,p { color: #000; } +#disqus_thread { + background-color: #fff; +} + .main { width: 100%; transition: color 2s; diff --git a/top50/index.js b/top50/index.js index 0e3c1cb..42f6d01 100644 --- a/top50/index.js +++ b/top50/index.js @@ -7,7 +7,10 @@ let popups = []; let specificChannels = []; let pickingChannels = false; function abb(n) { - return Math.floor(parseFloat(n.toPrecision(3))) + let s = Math.sign(n); + n = Math.abs(n); + if (n < 1) return 0; + else return s*Math.floor(n/(10**(Math.floor(Math.log10(n))-2)))*(10**(Math.floor(Math.log10(n))-2)) } const uuidGen = function () { let a = function () { @@ -27,6 +30,35 @@ function avg(a, b) { function random(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } +function adjustColors() { + let c = document.body.style.backgroundColor; + if (!c) return; + let r,g,b; + if (c.startsWith('#')) { + c = c.replace('#',''); + const color = parseInt(c, 16); + r = (color >> 16); + g = (color >> 8) & 0xff; + b = color & 0xff; + } else { + c = c.replace('rgb(', ''); + const color = c.split(',').map(x => parseInt(x, 10)); + r = color[0]; + g = color[1]; + b = color[2]; + } + const brightness = (0.2126*r+0.7152*g+0.0722*b)/255; + const textLabels = document.querySelectorAll("label,h1,h2,h3,h4,h5,h6,p,strong,input[type=file]"); + if (brightness < 0.5) { + for (i = 0; i < textLabels.length; i++) { + textLabels[i].style.color = '#fff'; + } + } else { + for (i = 0; i < textLabels.length; i++) { + textLabels[i].style.color = '#000'; + } + } +} let uuid = uuidGen() let data = { "showImages": true, @@ -47,7 +79,6 @@ let data = { 'odometerUp': 'null', 'odometerDown': 'null', 'odometerSpeed': 2, - 'theme': 'top50', "sort": "num", "order": "desc", @@ -200,6 +231,7 @@ function initLoad(redo) { } document.body.style.backgroundColor = data.bgColor; document.body.style.color = data.textColor; + adjustColors(); fix(); updateOdo(); updateInterval = setInterval(update, data.updateInterval); @@ -699,6 +731,7 @@ function load() { } document.body.style.backgroundColor = data.bgColor; document.body.style.color = data.textColor; + adjustColors(); if (!data.uuid) { data.uuid = uuidGen(); } @@ -767,6 +800,7 @@ function downloadChannel() { document.getElementById('backPicker').addEventListener('change', function () { document.body.style.backgroundColor = this.value; data.bgColor = this.value; + adjustColors(); }); document.getElementById('textPicker').addEventListener('change', function () { From d32308060388c3ef302f6e8826c9f8f96c514009 Mon Sep 17 00:00:00 2001 From: Lucas <50644934+RandomPerson3465@users.noreply.github.com> Date: Sat, 30 Dec 2023 20:44:09 -0800 Subject: [PATCH 2/2] Update index.js Fix issue with headers (empty object as headers causes a cors error when using googleapis) and fix bug where the update interval gets x1000 every time it is loaded. --- top50/index.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/top50/index.js b/top50/index.js index 42f6d01..1f53d50 100644 --- a/top50/index.js +++ b/top50/index.js @@ -1613,13 +1613,22 @@ function apiUpdate(interval) { } function fetchNext(url) { if (data.apiUpdates.method == 'GET') { - fetch(url, { - method: data.apiUpdates.method, - headers: data.apiUpdates.headers - }).then(response => response.json()) + if (Object.keys(data.apiUpdates.headers).filter(x=>x).length) { + fetch(url, { + method: data.apiUpdates.method, + headers: data.apiUpdates.headers, + }).then(response => response.json()) .then(json => { doStuff(json) }) + } else { + fetch(url, { + method: data.apiUpdates.method + }).then(response => response.json()) + .then(json => { + doStuff(json) + }) + } } else { fetch(url, { method: data.apiUpdates.method, @@ -1715,7 +1724,9 @@ function saveAPIUpdates() { let newHeaders = {} for (let i = 0; i < headers.length; i++) { let header = headers[i].split(': ') - newHeaders[header[0]] = header[1] + if (header[1]) { + newHeaders[header[0]] = header[1] + } } data.apiUpdates.headers = newHeaders let body = document.getElementById('body').value.toString().split('; ').join(';\n').split(';\n') @@ -1772,7 +1783,7 @@ function loadAPIUpdates() { document.getElementById('pathImage').value = data.apiUpdates.response.image.path document.getElementById('updateID').checked = data.apiUpdates.response.id.enabled document.getElementById('pathID').value = data.apiUpdates.response.id.path - document.getElementById('apiUpdateInt').value = data.apiUpdates.interval + document.getElementById('apiUpdateInt').value = data.apiUpdates.interval / 1000; document.getElementById('enableApiUpdate').innerHTML = data.apiUpdates.enabled == true ? 'Disable API Updates' : 'Enable API Updates' } loadAPIUpdates()