Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
•
0bc96b1
1
Parent(s):
19081b7
✨ feat: add code to handle the parsing and storing of the new settings option (#424)
Browse files- public/static/settings.js +47 -7
public/static/settings.js
CHANGED
@@ -50,6 +50,9 @@ function setClientSettings() {
|
|
50 |
case 'colorschemes':
|
51 |
cookie_dictionary['colorscheme'] = select_tag.value
|
52 |
break
|
|
|
|
|
|
|
53 |
case 'safe_search_levels':
|
54 |
cookie_dictionary['safe_search_level'] = Number(select_tag.value)
|
55 |
break
|
@@ -103,13 +106,50 @@ function getClientSettings() {
|
|
103 |
.map((item) => item.split('='))
|
104 |
.reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {})
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
}
|
115 |
}
|
|
|
50 |
case 'colorschemes':
|
51 |
cookie_dictionary['colorscheme'] = select_tag.value
|
52 |
break
|
53 |
+
case 'animations':
|
54 |
+
cookie_dictionary['animation'] = select_tag.value || null
|
55 |
+
break
|
56 |
case 'safe_search_levels':
|
57 |
cookie_dictionary['safe_search_level'] = Number(select_tag.value)
|
58 |
break
|
|
|
106 |
.map((item) => item.split('='))
|
107 |
.reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {})
|
108 |
|
109 |
+
let links = Array.from(document.querySelectorAll('link'))
|
110 |
+
|
111 |
+
// A check to determine whether the animation link exists under the head tag or not.
|
112 |
+
// If it does not exists then create and add a new animation link under the head tag
|
113 |
+
// and update the other link tags href according to the settings provided by the user
|
114 |
+
// via the UI. On the other hand if it does exist then just update all the link tags
|
115 |
+
// href according to the settings provided by the user via the UI.
|
116 |
+
if (!links.some((item) => item.href.includes('static/animations'))) {
|
117 |
+
if (cookie_value['animation']) {
|
118 |
+
let animation_link = document.createElement('link')
|
119 |
+
animation_link.href = `static/animations/${cookie_value['animation']}.css`
|
120 |
+
animation_link.rel = 'stylesheet'
|
121 |
+
animation_link.type = 'text/css'
|
122 |
+
document.querySelector('head').appendChild(animation_link)
|
123 |
}
|
124 |
+
// Loop through all link tags and update their href values to match the user's preferences
|
125 |
+
links.forEach((item) => {
|
126 |
+
if (item.href.includes('static/themes')) {
|
127 |
+
item.href = `static/themes/${cookie_value['theme']}.css`
|
128 |
+
} else if (item.href.includes('static/colorschemes')) {
|
129 |
+
item.href = `static/colorschemes/${cookie_value['colorscheme']}.css`
|
130 |
+
}
|
131 |
+
})
|
132 |
+
} else {
|
133 |
+
// Loop through all link tags and update their href values to match the user's preferences
|
134 |
+
links.forEach((item) => {
|
135 |
+
if (item.href.includes('static/themes')) {
|
136 |
+
item.href = `static/themes/${cookie_value['theme']}.css`
|
137 |
+
} else if (item.href.includes('static/colorschemes')) {
|
138 |
+
item.href = `static/colorschemes/${cookie_value['colorscheme']}.css`
|
139 |
+
} else if (
|
140 |
+
item.href.includes('static/animations') &&
|
141 |
+
cookie_value['animation']
|
142 |
+
) {
|
143 |
+
item.href = `static/colorschemes/${cookie_value['animation']}.css`
|
144 |
+
}
|
145 |
+
})
|
146 |
+
if (!cookie_value['animation']) {
|
147 |
+
document
|
148 |
+
.querySelector('head')
|
149 |
+
.removeChild(
|
150 |
+
links.filter((item) => item.href.includes('static/animations')),
|
151 |
+
)
|
152 |
+
}
|
153 |
+
}
|
154 |
}
|
155 |
}
|