From f4f0939ceee64833d9156d3b13b659fc31cc8034 Mon Sep 17 00:00:00 2001 From: kiril Date: Sun, 11 Aug 2024 00:25:41 +0000 Subject: [PATCH] Make the quote generator generically extensible & declarative --- wiktionary/quotes.html | 133 +++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 44 deletions(-) diff --git a/wiktionary/quotes.html b/wiktionary/quotes.html index 1ce205d..59d060b 100644 --- a/wiktionary/quotes.html +++ b/wiktionary/quotes.html @@ -13,27 +13,59 @@ text-decoration-style: dotted; text-decoration: underline; } + html { + background-color: black; + filter: invert(1); + } @@ -42,36 +74,21 @@

en.wiktionary Quote Generator

(?)

-

Basic information

+
+

Basic information

+
+

- - - - - - - - -
-

Additional information

-
-
- - - - - +
+

Additional information

+
+
+


- +
@@ -105,20 +122,50 @@ generate(); navigator.clipboard.writeText(document.getElementById("out").innerHTML); } - function addNamedParameters(obj) { + function addNamedParameters(obj, ignore = ["type", "language"]) { let out = ""; for (const key in obj) { + if (obj[key] == "" || ignore.includes(key)) continue; out += `|${key}=${obj[key]}`; } return out; } function loadPresetList() { - const items = {...localStorage}; + const items = {...localStorage}; delete items.latestPreset; for (const key in items) { addPresetToMenu(key); } + console.log(localStorage.getItem("latestPreset")); + loadPreset(localStorage.getItem("latestPreset")); } - function addPresetToMenu(key) { + function generatePropertyInputs() { + for (const key in parameters) { + const label = document.createElement("label"); + label.innerText = parameters[key].label; + + let input; + if (parameters[key].type === "dropdown") { + input = document.createElement("select"); + for (const optionName in parameters[key].fields) { + const option = document.createElement("option"); + option.value = optionName; + option.innerText = parameters[key].fields[optionName]; + input.appendChild(option) + } + } else if (parameters[key].type === "textarea") { + input = document.createElement("textarea"); + input.cols = 60; + input.rows = 6; + } else { + input = document.createElement("input"); + input.type = "text"; + } + input.id = key; + document.getElementById(parameters[key].section).appendChild(label); + document.getElementById(parameters[key].section).appendChild(input); + } + } + function addPresetToMenu(key) { const existingPresets = document.querySelectorAll("#presets option"); for (const node of existingPresets) { if (node.value === key) { @@ -146,19 +193,17 @@ function loadPreset(presetName) { document.getElementById("preset-name").value = presetMenu.value; const parameterValues = JSON.parse(localStorage.getItem(presetName)); - console.log(parameterValues) for (const key in parameterValues) { document.getElementById(key).value = parameterValues[key]; } + localStorage.setItem("latestPreset", presetName); } function deletePreset() { const presetName = document.getElementById("preset-name").value; localStorage.removeItem(presetName); const existingPresets = presetMenu.children; let currentPresetOptionNode; - console.log(presetName); for (const node of existingPresets) { - console.log(node.value); if (node.value === presetName) { currentPresetOptionNode = node; break;