Pop-up dictionary browser extension for language learning. Successor to Yomichan. (PERSONAL FORK)
at lambda-fork/main 63 lines 2.4 kB view raw
1/* 2 * Copyright (C) 2023-2025 Yomitan Authors 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18HtmlTestUtilities.runMain(() => { 19 let totalCount = 0; 20 const container = document.querySelector('#container'); 21 const counter = document.querySelector('#counter'); 22 23 /** 24 * @param {number} count 25 * @param {Event} event 26 */ 27 function addElements(count, event) { 28 event.preventDefault(); 29 30 if (container !== null) { 31 for (let i = 0; i < count; ++i) { 32 const element = document.createElement('div'); 33 element.textContent = 'ありがとう'; 34 container.appendChild(element); 35 } 36 } 37 38 totalCount += count; 39 if (counter !== null) { 40 counter.textContent = `${totalCount}`; 41 } 42 } 43 44 for (const element of document.querySelectorAll('.add-elements')) { 45 if (!(element instanceof HTMLElement)) { continue; } 46 const {count} = element.dataset; 47 if (typeof count !== 'string') { continue; } 48 const countValue = Number.parseInt(count, 10); 49 if (!Number.isFinite(countValue)) { continue; } 50 element.addEventListener('click', addElements.bind(null, countValue)); 51 } 52 53 const shadowIframeContainer = document.querySelector('#shadow-iframe-container-open'); 54 if (shadowIframeContainer !== null) { 55 const shadow = shadowIframeContainer.attachShadow({mode: 'open'}); 56 const templateElement = document.querySelector('#shadow-iframe-container-open-content-template'); 57 if (templateElement instanceof HTMLTemplateElement) { 58 const template = templateElement.content; 59 const content = document.importNode(template, true); 60 shadow.appendChild(content); 61 } 62 } 63});