mirror of
https://github.com/Investigamer/cardconjurer.git
synced 2025-07-27 05:14:53 -05:00
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
let rootStyles = document.documentElement.style
|
|
|
|
function setCookie(cookieName, cookieValue, cookieTime = (5 * 365 * 24 * 60 * 60 * 1000)) { //years*days*hours*minutes*seconds*milliseconds
|
|
var tempDate = new Date()
|
|
tempDate.setTime(tempDate.getTime() + cookieTime)
|
|
document.cookie = cookieName + '=' + cookieValue + ';expires=' + tempDate.toUTCString() + ';path=/'
|
|
}
|
|
|
|
function getCookie(cookieName) {
|
|
var name = cookieName + '='
|
|
var cookieArray = document.cookie.split(';')
|
|
for(var i = 0; i < cookieArray.length; i++) {
|
|
var tempCookie = cookieArray[i]
|
|
while (tempCookie.charAt(0) == ' ') {
|
|
tempCookie = tempCookie.substring(1)
|
|
}
|
|
if (tempCookie.indexOf(name) == 0) {
|
|
return tempCookie.substring(name.length, tempCookie.length)
|
|
}
|
|
}
|
|
return ''
|
|
}
|
|
|
|
function checkCookies() {
|
|
var colorPaletteCookie = getCookie('colorPalette')
|
|
if (colorPaletteCookie != undefined && colorPaletteCookie != '') {
|
|
loadScript('/data/scripts/palettes/' + colorPaletteCookie + '.js')
|
|
setTimeout(function() {
|
|
document.getElementById('inputColorPalette').value = getCookie('colorPalette')
|
|
}, 1000)
|
|
} else {
|
|
loadScript('/data/scripts/palettes/lowpolyGreen.js')
|
|
}
|
|
}
|
|
checkCookies()
|
|
|
|
function loadScript(scriptPath){
|
|
var script = document.createElement('script')
|
|
script.setAttribute('type','text/javascript')
|
|
script.setAttribute('src', scriptPath)
|
|
if (typeof script != 'undefined') {
|
|
document.getElementsByTagName('head')[0].appendChild(script)
|
|
}
|
|
}
|