From edd10e6206c02be9aa2d84d803e79b9036183d76 Mon Sep 17 00:00:00 2001 From: TheEmeraldStarr <46467239+Epicloudygamer@users.noreply.github.com> Date: Mon, 2 Nov 2020 10:52:51 -0800 Subject: [PATCH] Updated Options Menu Schript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- Contribution from YÖCTDÖNALD'S --- public/assets/js/header.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/public/assets/js/header.js b/public/assets/js/header.js index 047f8f8c..5a245986 100644 --- a/public/assets/js/header.js +++ b/public/assets/js/header.js @@ -2,44 +2,41 @@ let titles = icons = []; addEventListener('DOMContentLoaded', p => { - p = $('csel'); - setPreferences(); + setPreferences(p = $('csel')); titles.forEach((e, i) => p.innerHTML += i ? `` : ''); - /*Title Submit*/ + /*Submit Title & Icon*/ (i => i.onsubmit = e => e.preventDefault() || setTitle(i.firstChild.value || '‏‎'))($('titleform')); - - /*Icon Submit*/ (i => i.onsubmit = e => e.preventDefault() || setIcon(i.firstChild.value || 'data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAA'))($('iconform')); - /*Settings Submit*/ + /*Submit Settings*/ p.onclick = (e, s) => (s = Array.from(p.children).indexOf(e.target)) + 1 && setTitle(titles[s], setIcon(icons[s])); - /*Settings Menu Event*/ + /*Settings Menu*/ (i => i.onclick = e => { onbeforeunload = e => { if (i.checked) return e.returnValue = 'Error Tab Cloak' } })($('csel')); - /*Fullscreen Feature Addition*/ + /*Unimplemented Fullscreen*/ //$('fullscreen').onclick=e=>e.preventDefault()||$('theframe').requestFullscreen() }, 0); -/*Title and Icon Cookies*/ -setPreferences = (e, i, a) => { e = 'HBTitle', i = 'HBIcon', a = [] + void[], readCookie(e) == a || pageTitle(readCookie(e)); - readCookie(i) == a || pageIcon(readCookie(i)) }; - -/*Set Secure Cookie*/ +/*Cookie Storage*/ (d => { d.setMonth(d.getMonth() + 12); - setCookie = (n, v) => { document.cookie = n + `=${encodeURIComponent(v)};expires=${d.toUTCString()};SameSite=None;Secure` } })(new Date()); + setCookie = (n, v) => { document.cookie = n + `=${([]+v).replace(/.|\n/g,p=>{try{return/[\w\d-.!~*'()]/.test(p)?'%'+p.charCodeAt().toString(16).toUpperCase():encodeURIComponent(p)}catch{return p}})};expires=${d.toUTCString()};SameSite=None;Secure` } })(new Date()); /*Read Cookie*/ -readCookie = n => { try { return decodeURIComponent(document.cookie.split('; ').filter(e => e.startsWith(n + '='))[0].slice(n.length + 1)) } catch { return [] } }; +readCookie = n => ([] + document.cookie.split('; ').filter(e => e.startsWith(n + '='))[0]).slice(([] + n).length + 1).replace(/(%[A-z\d]{2})+/g, decodeURIComponent); -/*Set Title & Icon from Input Value*/ +/*Set Title & Icon*/ +pageTitle = v => { document.title = v; try { parent.document.title = v } catch (e) { console.log(e) } }; +pageIcon = (v, l, e) => { document.head.appendChild(((l = document.querySelector(e = 'link[rel*=icon]') || document.createElement('link')).rel = 'icon', l.href = v, l)); try { parent.document.head.appendChild(((l = parent.document.querySelector(e) || document.createElement('link')).rel = 'icon', l.href = v, l)) } catch (e) { console.log(e) } }; + +/*Store Title & Icon*/ setTitle = v => pageTitle(v) || setCookie('HBTitle', v); setIcon = v => pageIcon(v) || setCookie('HBIcon', v); -/* Title & Icon Attach*/ -pageTitle = v => { document.title = v; try { parent.document.title = v } catch (e) { console.log(e) } }; -pageIcon = (v, l, e) => { e = 'link[rel*=icon]', document.head.appendChild(((l = document.querySelector(e) || document.createElement('link')).rel = 'icon', l.href = v, l)); try { parent.document.head.appendChild(((l = parent.document.querySelector(e) || document.createElement('link')).rel = 'icon', l.href = v, l)) } catch (e) { console.log(e) } }; +/*Set Stored Title & Icon*/ +setPreferences = (e, i, a) => { readCookie(e = 'HBTitle') == (a = [] + void[]) || pageTitle(readCookie(e)); + readCookie(i = 'HBIcon') == a || pageIcon(readCookie(i)) }; -/* Tab Cloak*/ +/*Sift Tabs*/ autoChange = (e, r) => { $('csel').checked ? pageTitle(titles[e = (r = (a, b) => Math.floor(Math.random() * (b - a + 1)) + a)(1, 5)], pageIcon(icons[e]), setTimeout(autoChange, r(1e4, 6e4))) : setPreferences() } \ No newline at end of file