Last active
November 22, 2025 00:38
-
-
Save siers/dc5b5517888e9027316e9d7502635686 to your computer and use it in GitHub Desktop.
local dual wiktionary viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <script> | |
| function arrayRotate(arr, count) { | |
| const len = arr.length | |
| arr.push(...arr.splice(0, (-count % len + len) % len)) | |
| return arr | |
| } | |
| // | |
| // const activeIndex = 0 // .at(activeIndex) | |
| const activeIndex = -1 // .at(activeIndex) | |
| let counter = 0 | |
| function wordChange() { | |
| counter += 1 | |
| const lastCounter = counter | |
| setTimeout(() => { if (lastCounter == counter) applyWord() }, 300) | |
| } | |
| function setAnchor(anchor) { | |
| location.href = "#" + anchor | |
| } | |
| function getWords() { | |
| const words = document.querySelector(".word").value.split(/\n/) | |
| return words.filter(word => word.length > 0) | |
| } | |
| function setWord(word) { | |
| document.querySelector(".word").value = word | |
| } | |
| function applyWord() { | |
| const en = document.querySelector(".en") | |
| const de = document.querySelector(".de") | |
| const count = document.querySelector(".count") | |
| const words = getWords() | |
| const wordsEnc = words.map(word => encodeURI(word)) | |
| const wordEnc = (wordsEnc || ['']).at(activeIndex) | |
| count.innerText = words.length | |
| // console.log(`words: ${words} // wordsEnc: ${wordsEnc} // wordEnc: ${wordEnc}`) | |
| if (wordEnc) { | |
| en.src = `https://en.wiktionary.org/wiki/${wordEnc}#German` | |
| de.src = `https://de.wiktionary.org/wiki/${wordEnc}#${wordEnc}_(Deutsch)` | |
| } else { | |
| en.src = `about:blank` | |
| de.src = `about:blank` | |
| } | |
| setAnchor(wordsEnc.join('-')) | |
| } | |
| const useAnchor = (event) => { | |
| if (location.hash.length > 2) { | |
| const anchor = location.hash.substr(1) | |
| setWord(decodeURI(anchor).replaceAll('-', '\n')) | |
| applyWord() | |
| } | |
| } | |
| const rotateWord = (direction) => { | |
| setWord(arrayRotate(getWords(), direction).join('\n')) | |
| applyWord() | |
| } | |
| const destroyWord = () => { | |
| const newWords = [...getWords()] | |
| newWords.splice(activeIndex, 1) | |
| setWord(newWords.join('\n')) | |
| applyWord() | |
| } | |
| addEventListener("DOMContentLoaded", useAnchor) | |
| addEventListener("hashchange", useAnchor) | |
| </script> | |
| <style> | |
| body { margin-top: 0; } | |
| .container { display: flex; height: calc(100vh - 60px); flex-direction: column; } | |
| .ui { display: flex; flex-direction: row; justify-content: center; padding: 20px 0; } | |
| .word { display: block; width: 300px; font-family: sans-serif; } | |
| .next, .prev { display: block; margin: 0 0 0 10px; } | |
| .en, .de { flex-grow: 1; border: 0; } | |
| .en { background: #f5f5f5; } | |
| .de { background: #f9f9f9; } | |
| .count { margin: 0.5em 0 0 1em; } | |
| </style> | |
| <body> | |
| <div class="ui"> | |
| <textarea class="word" type="text" onkeyup="wordChange()" rows=2></textarea> | |
| <button class="prev" onclick="rotateWord(1)"><-</button> | |
| <button class="next" onclick="rotateWord(-1)">-></button> | |
| <button class="next" onclick="destroyWord()">x</button> | |
| <span class="count"></span> | |
| </div> | |
| <div class="container"> | |
| <iframe class="en"></iframe> | |
| <iframe class="de"></iframe> | |
| </div> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment