Sebastiankay commited on
Commit
fa18eeb
1 Parent(s): e04cd4e

24. Sept. 2024, 19:19

Browse files
Files changed (1) hide show
  1. _res/_custom.js +94 -11
_res/_custom.js CHANGED
@@ -87,19 +87,47 @@ function gradioCustomJS() {
87
  body.style.setProperty("--primary-300", "color-mix(in srgb, var(--primary-600) 60%, white)")
88
  body.style.setProperty("--primary-400", "color-mix(in srgb, var(--primary-600) 70%, white)")
89
  body.style.setProperty("--primary-500", "color-mix(in srgb, var(--primary-600) 80%, white)")
90
- body.style.setProperty("--primary-700", "color-mix(in srgb, var(--primary-600) 60%, black)")
91
- body.style.setProperty("--primary-800", "color-mix(in srgb, var(--primary-600) 70%, black)")
92
- body.style.setProperty("--primary-900", "color-mix(in srgb, var(--primary-600) 80%, black)")
93
- body.style.setProperty("--primary-950", "color-mix(in srgb, var(--primary-600) 90%, black)")
94
-
95
- body.style.setProperty("--block-title-text-color", "var(--neutral-950)")
96
- body.style.setProperty("--block-label-text-color", "var(--neutral-950)")
97
- body.style.setProperty("--checkbox-label-text-color", "var(--neutral-950)")
98
 
 
 
 
99
  body.style.setProperty("--text-color-by-luminance", anpasseTextfarbe(usedColor))
100
- body.style.setProperty("--block-title-text-color", anpasseTextfarbe(usedColor))
101
- body.style.setProperty("--block-label-text-color", anpasseTextfarbe(usedColor))
102
- body.style.setProperty("--checkbox-label-text-color", anpasseTextfarbe(usedColor))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  const prompt_input = document.querySelector("#prompt_input")
105
  prompt_input.setAttribute("autocomplete", "off")
@@ -173,5 +201,60 @@ function gradioCustomJS() {
173
  // })
174
  // })
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  return "Custom Gradio JS"
177
  }
 
87
  body.style.setProperty("--primary-300", "color-mix(in srgb, var(--primary-600) 60%, white)")
88
  body.style.setProperty("--primary-400", "color-mix(in srgb, var(--primary-600) 70%, white)")
89
  body.style.setProperty("--primary-500", "color-mix(in srgb, var(--primary-600) 80%, white)")
90
+ body.style.setProperty("--primary-700", "color-mix(in srgb, var(--primary-600) 80%, black)")
91
+ body.style.setProperty("--primary-800", "color-mix(in srgb, var(--primary-600) 65%, black)")
92
+ body.style.setProperty("--primary-900", "color-mix(in srgb, var(--primary-600) 40%, black)")
93
+ body.style.setProperty("--primary-950", "color-mix(in srgb, var(--primary-600) 30%, black)")
 
 
 
 
94
 
95
+ body.style.setProperty("--button-primary-background-fill", "var(--primary-600)")
96
+ body.style.setProperty("--button-primary-background-fill-hover", "var(--primary-500)")
97
+ body.style.setProperty("--blur-value", "0px")
98
  body.style.setProperty("--text-color-by-luminance", anpasseTextfarbe(usedColor))
99
+
100
+ // MARK: Selectors & Elements
101
+ const gradioApp = document.querySelector("gradio-app")
102
+ const gradioContainer = document.querySelector("body > gradio-app > div.gradio-container")
103
+ const alertModalElem = document.createElement("div")
104
+ const alertModalElemP = document.createElement("p")
105
+ const alertModalElemI = document.createElement("i")
106
+ alertModalElemI.className = "fas fa-exclamation-circle"
107
+ const alertModalElemSpan = document.createElement("span")
108
+ alertModalElemSpan.id = "alertModalText"
109
+ const alertModalElemButton = document.createElement("button")
110
+ alertModalElemButton.className = "lg primary run-btn svelte-cmf5ev"
111
+ alertModalElemButton.id = "alertModalBtn"
112
+ alertModalElemButton.textContent = "Ok"
113
+ alertModalElemP.id = "alertModalP"
114
+ alertModalElemP.append(alertModalElemI, alertModalElemSpan)
115
+ alertModalElem.id = "alertModal"
116
+ alertModalElem.style.display = "none"
117
+ alertModalElem.append(alertModalElemP, alertModalElemButton)
118
+ //alertModalElem.innerHTML = '<p></p>'
119
+ gradioApp.appendChild(alertModalElem)
120
+
121
+ alertModalElemButton.addEventListener("click", () => {
122
+ oldText = alertModalElemSpan.textContent
123
+ alertModalElemButton.disabled = true
124
+ alertModalElemSpan.innerHTML = 'Der "Ok" Button ändert nur diesen Text. 🫢<br/>In 2.5 Sekunden wird wieder die ursprüngliche Meldung gezeigt. Cool oder?'
125
+ setTimeout(() => {
126
+ alertModalElemSpan.textContent = oldText
127
+ alertModalElemButton.disabled = false
128
+ alertModalElemButton.textContent = "Noch mal?"
129
+ }, 2500)
130
+ })
131
 
132
  const prompt_input = document.querySelector("#prompt_input")
133
  prompt_input.setAttribute("autocomplete", "off")
 
201
  // })
202
  // })
203
 
204
+ // MARK: Element-Ready function
205
+ function elementReady(selector) {
206
+ return new Promise((resolve, reject) => {
207
+ const el = document.querySelector(selector)
208
+ if (el) {
209
+ resolve(el)
210
+ }
211
+
212
+ new MutationObserver((mutationRecords, observer) => {
213
+ Array.from(document.querySelectorAll(selector)).forEach((element) => {
214
+ resolve(element)
215
+ observer.disconnect()
216
+ })
217
+ }).observe(document.documentElement, {
218
+ childList: true,
219
+ subtree: true,
220
+ })
221
+ })
222
+ }
223
+
224
+ // MARK: Mobile Check
225
+ function istMobile() {
226
+ // Überprüfen, ob das Gerät ein Touchscreen hat
227
+ if ("ontouchstart" in window || (navigator.maxTouchPoints && window.innerWidth < 768)) {
228
+ gradioContainer.classList.add("blur-container")
229
+ body.style.setProperty("--blur-value", "12px")
230
+ gradioApp.style.height = "calc(100vh - 120px)"
231
+ alertModalElem.style.display = ""
232
+ alertModalElemSpan.textContent = "Diese Seite ist nicht für mobile Geräte optimiert. Bitte besuche diese Seite von einem Desktop-Computer aus."
233
+ } else if (window.innerWidth < 1024) {
234
+ gradioContainer.classList.add("blur-container")
235
+ body.style.setProperty("--blur-value", "12px")
236
+ gradioApp.style.height = "calc(100vh - 120px)"
237
+ alertModalElem.style.display = ""
238
+ alertModalElemSpan.textContent = "Bildschirm Auflösung oder Fensterbreite zu gering. Bitte besuche diese Seite von einem Desktop-Computer aus."
239
+ } else {
240
+ gradioContainer.classList.remove("blur-container")
241
+ body.style.setProperty("--blur-value", "0px")
242
+ gradioApp.style.height = ""
243
+ alertModalElem.style.display = "none"
244
+ alertModalElemSpan.textContent = ""
245
+ }
246
+ }
247
+
248
+ // MARK: Event Listeners
249
+ window.addEventListener("resize", () => {
250
+ console.log("Event Window resize.")
251
+ istMobile()
252
+ })
253
+
254
+ elementReady("body > gradio-app > div.gradio-container").then((element) => {
255
+ console.log("Element exist: " + element)
256
+ istMobile()
257
+ })
258
+
259
  return "Custom Gradio JS"
260
  }