Skip to content

Commit

Permalink
Merge pull request #21 from RandomPerson3465/main
Browse files Browse the repository at this point in the history
Fix abbreviations + Label colors now adjust
  • Loading branch information
mgcountss authored Dec 31, 2023
2 parents 6eba780 + d323080 commit 1c0e290
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
4 changes: 4 additions & 0 deletions top50/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
61 changes: 53 additions & 8 deletions top50/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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,
Expand All @@ -47,7 +79,6 @@ let data = {
'odometerUp': 'null',
'odometerDown': 'null',
'odometerSpeed': 2,

'theme': 'top50',
"sort": "num",
"order": "desc",
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -1579,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,
Expand Down Expand Up @@ -1681,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(';&#10;').join(';\n').split(';\n')
Expand Down Expand Up @@ -1738,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()
Expand Down

0 comments on commit 1c0e290

Please sign in to comment.