From b772555d437a1aa4068587695332eeaf35334b97 Mon Sep 17 00:00:00 2001 From: Kyle <41976328+ImKyle4815@users.noreply.github.com> Date: Mon, 27 Jul 2020 15:23:39 -0700 Subject: [PATCH] fix color cycling --- data/scripts/palettes/dayRave.js | 29 +++++++++-------------------- data/scripts/palettes/nightRave.js | 29 +++++++++-------------------- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/data/scripts/palettes/dayRave.js b/data/scripts/palettes/dayRave.js index a87b52c4..72174fa2 100644 --- a/data/scripts/palettes/dayRave.js +++ b/data/scripts/palettes/dayRave.js @@ -8,28 +8,17 @@ rootStyles.setProperty('--font-color', '#000000') rootStyles.setProperty('--body-background', 'none') setCookie('colorPalette', 'dayRave') -//Stops the hue shift when another palette is loaded -if (document.getElementById('inputColorPalette') != null) { - document.getElementById('inputColorPalette').addEventListener('change', removeEventListener, false) -} else { - setTimeout(function() {document.getElementById('inputColorPalette').addEventListener('change', removeEventListener, false)}, 1000) -} - -function removeEventListener() { - if (document.getElementById('inputColorPalette').value != 'dayRave') { - clearInterval(colorCycle) - document.getElementById('inputColorPalette').removeEventListener('change', removeEventListener, false) - } -} - //Shifts the hue -var colorCycle = setInterval(shiftHue, 200) +var colorCycle var currentHueRotation = 0 +if (colorCycle == undefined) { + colorCycle = setInterval(shiftHue, 200) +} -function shiftHue() { - rootStyles.setProperty('--site-background-filter', 'grayscale(0) hue-rotate(' + currentHueRotation + 'deg)') - currentHueRotation += 1 - if (currentHueRotation == 360) { - currentHueRotation = 0 +function shiftHue(checkForClear = false) { + if (document.getElementById('inputColorPalette').value.includes('Rave')) { + rootStyles.setProperty('--site-background-filter', 'grayscale(0) hue-rotate(' + currentHueRotation + 'deg)') + currentHueRotation += 1 + if (currentHueRotation == 360) {currentHueRotation = 0} } } \ No newline at end of file diff --git a/data/scripts/palettes/nightRave.js b/data/scripts/palettes/nightRave.js index e00d15d4..9ff51f3f 100644 --- a/data/scripts/palettes/nightRave.js +++ b/data/scripts/palettes/nightRave.js @@ -8,28 +8,17 @@ rootStyles.setProperty('--font-color', '#efefef') rootStyles.setProperty('--body-background', 'none') setCookie('colorPalette', 'nightRave') -//Stops the hue shift when another palette is loaded -if (document.getElementById('inputColorPalette') != null) { - document.getElementById('inputColorPalette').addEventListener('change', removeEventListener, false) -} else { - setTimeout(function() {document.getElementById('inputColorPalette').addEventListener('change', removeEventListener, false)}, 1000) -} - -function removeEventListener() { - if (document.getElementById('inputColorPalette').value != 'nightRave') { - clearInterval(colorCycle) - document.getElementById('inputColorPalette').removeEventListener('change', removeEventListener, false) - } -} - //Shifts the hue -var colorCycle = setInterval(shiftHue, 200) +var colorCycle var currentHueRotation = 0 +if (colorCycle == undefined) { + colorCycle = setInterval(shiftHue, 200) +} -function shiftHue() { - rootStyles.setProperty('--site-background-filter', 'grayscale(0) hue-rotate(' + currentHueRotation + 'deg)') - currentHueRotation += 1 - if (currentHueRotation == 360) { - currentHueRotation = 0 +function shiftHue(checkForClear = false) { + if (document.getElementById('inputColorPalette').value.includes('Rave')) { + rootStyles.setProperty('--site-background-filter', 'grayscale(0) hue-rotate(' + currentHueRotation + 'deg)') + currentHueRotation += 1 + if (currentHueRotation == 360) {currentHueRotation = 0} } } \ No newline at end of file