Add quote generator beginnings
This commit is contained in:
parent
065a127c36
commit
9168154c79
174
wiktionary/quotes.html
Normal file
174
wiktionary/quotes.html
Normal file
@ -0,0 +1,174 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Quote generator</title>
|
||||
<style>
|
||||
label {
|
||||
display: block
|
||||
}
|
||||
.gloss {
|
||||
text-decoration-style: dotted;
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
const parameters = {
|
||||
"type": "Type",
|
||||
"language": "Language(s)",
|
||||
"text": "Text",
|
||||
"t": "Translation or re-wording",
|
||||
"year": "Year",
|
||||
"author": "Author",
|
||||
"title": "Title",
|
||||
"volume": "Volume",
|
||||
"translator": "Translator",
|
||||
"trans-title": "Translated title",
|
||||
"series": "Series",
|
||||
"isbn": "ISBN"
|
||||
}
|
||||
let presetMenu;
|
||||
addEventListener("DOMContentLoaded", (event) => {
|
||||
presetMenu = document.getElementById("presets");
|
||||
presetMenu.addEventListener("change", () => loadPreset(presetMenu.value));
|
||||
|
||||
loadPresetList();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="display: inline-block">en.wiktionary Quote Generator</h1> <span class="gloss" title="Enter values for each of the quote template fields. Once you're done, click Generate or Copy to clipboard to get the output as wikitext. You may set presets to skip out the repetitive bits if quoting from the same book many times.">(?)</span>
|
||||
<form>
|
||||
<hr>
|
||||
<h2>Basic information</h2>
|
||||
<hr>
|
||||
<label for="type">Type</label>
|
||||
<select id="type">
|
||||
<option value="book">Book</option>
|
||||
<option value="web">Web</option>
|
||||
<option value="song">Song</option>
|
||||
<option value="journal">Journal</option>
|
||||
<option value="wikipedia">Wikipedia</option>
|
||||
</select>
|
||||
<label>Language(s)</label> <input type="text" id="language">
|
||||
<label>Text</label> <input type="text" id="text">
|
||||
<label>Translation or re-wording</label> <input type="text" id="t">
|
||||
<label>Year</label> <input type="text" id="year">
|
||||
<label>Author</label> <input type="text" id="author">
|
||||
<label>Title</label> <input type="text" id="title">
|
||||
<hr>
|
||||
<h2>Additional information</h2>
|
||||
<hr>
|
||||
<br>
|
||||
<label>Volume</label> <input type="text" id="volume">
|
||||
<label>Translator</label> <input type="text" id="translator">
|
||||
<label>Translated title</label> <input type="text" id="trans-title">
|
||||
<label>Series</label> <input type="text" id="series">
|
||||
<label>ISBN</label> <input type="text" id="isbn">
|
||||
<br>
|
||||
<input type="button" onclick="generate()" value="Generate" title="Generate">
|
||||
<input type="button" onclick="copy()" value="Copy to clipboard" title="Copy to clipboard">
|
||||
<br>
|
||||
<textarea readonly="true" id="out" cols="40" rows="4"></textarea>
|
||||
|
||||
<hr>
|
||||
<label>Preset <span class="gloss" title="When a preset name is input in the 'preset name' box below, you can save the current state of each option as a preset, which will be loaded again even if the page is refreshed.">(?)</span></label>
|
||||
<select id="presets">
|
||||
|
||||
</select>
|
||||
<label>Preset name</label> <input type="text" id="preset-name">
|
||||
<input type="button" value="Save" onclick="savePreset()">
|
||||
<input type="button" value="Delete" onclick="deletePreset()">
|
||||
</form>
|
||||
<script>
|
||||
function getTemplateName(type) {
|
||||
return `quote-${type}`;
|
||||
}
|
||||
function generate() {
|
||||
// Template type chosen
|
||||
const type = document.getElementById("type").value;
|
||||
const templateName = getTemplateName(type);
|
||||
|
||||
// Language name passed as a positional parameter
|
||||
const languages = document.getElementById("language").value;
|
||||
|
||||
// Generate template object
|
||||
let out = `{{${templateName}|${languages}`;
|
||||
out += addNamedParameters(getParameterObject());
|
||||
out += "}}";
|
||||
|
||||
document.getElementById("out").innerText = out;
|
||||
}
|
||||
function copy() {
|
||||
generate();
|
||||
navigator.clipboard.writeText(document.getElementById("out").innerHTML);
|
||||
}
|
||||
function addNamedParameters(obj) {
|
||||
let out = "";
|
||||
for (const key in obj) {
|
||||
out += `|${key}=${obj[key]}`;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function loadPresetList() {
|
||||
const items = {...localStorage};
|
||||
for (const key in items) {
|
||||
addPresetToMenu(key);
|
||||
}
|
||||
}
|
||||
function addPresetToMenu(key) {
|
||||
const existingPresets = document.querySelectorAll("#presets option");
|
||||
for (const node of existingPresets) {
|
||||
if (node.value === key) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const elem = document.createElement("option");
|
||||
elem.value = key;
|
||||
elem.innerText = key;
|
||||
presetMenu.appendChild(elem);
|
||||
}
|
||||
function savePreset() {
|
||||
const presetName = document.getElementById("preset-name").value;
|
||||
localStorage.setItem(presetName, JSON.stringify(getParameterObject()));
|
||||
addPresetToMenu(presetName);
|
||||
presetMenu.value = presetName;
|
||||
}
|
||||
function getParameterObject() {
|
||||
const out = {}
|
||||
for (const key in parameters) {
|
||||
out[key] = document.getElementById(key).value;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
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];
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
presetMenu.removeChild(currentPresetOptionNode);
|
||||
if (presetMenu.children.length === 1) {
|
||||
document.getElementById("preset-name").value = presetMenu.children[0].value;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user