Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hellpanderrr committed Apr 20, 2024
1 parent 6d46534 commit 510c831
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion wiktionary_pron/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<i class="fa fa-moon-o"></i>
</p>
<h1 style="flex: 1;">Online IPA Converter</h1>
<a href="#" id="dark_mode" onclick="dark()">
<a href="#" id="dark_mode" onclick="toggleDarkMode()">
<i class="fa fa-moon-o"></i>
</a>
</div>
Expand Down
36 changes: 20 additions & 16 deletions wiktionary_pron/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,10 @@ async function updateOptionsUponLanguageSelection(event) {
}

function selectTTS(language) {
const relevantVoices = Array.from(
document.querySelector("#tts").options,
).filter((x) => (x.getAttribute("data-lang") || "").includes(language));
const voices = Array.from(document.querySelector("#tts").options);
const relevantVoices = voices.filter((option) =>
(option.getAttribute("data-lang") || "").includes(language),
);

if (relevantVoices.length > 0) {
document.querySelector("#tts").value = relevantVoices[0].value;
Expand All @@ -441,36 +442,39 @@ document
.getElementById("lang")
.addEventListener("change", updateOptionsUponLanguageSelection);

async function pdfExport(e) {
const thisElement = e.currentTarget;
const link = thisElement.querySelector("i");
await thisElement.setAttribute("disabled", "true");
const oldClassName = link.className;
link.className = "fa fa-spinner fa-spin";
async function pdfExport(event) {
const buttonElement = event.currentTarget;
const iconElement = buttonElement.querySelector("i");

buttonElement.disabled = true;
const oldIconClass = iconElement.className;
iconElement.className = "fa fa-spinner fa-spin";

await toPdf(
globalThis.transcriptionMode,
isDarkMode(),
globalThis.transcriptionLang,
);
link.className = oldClassName;
await thisElement.removeAttribute("disabled");

iconElement.className = oldIconClass;
buttonElement.disabled = false;
}
document.getElementById("export_pdf").addEventListener("click", pdfExport);

function dark() {
function toggleDarkMode() {
console.log("setting dark");
if (document.body.classList.contains("dark_mode")) {
console.log("dark already setting light");
light_mode();
toggleLightMode();
} else {
document.body.classList.add("dark_mode");
document.querySelector("#header>a>i").className = "fa fa-sun-o";
document.querySelector("#header > a > i").className = "fa fa-sun-o";
}
}

function light_mode() {
function toggleLightMode() {
document.querySelector("#header>a>i").className = "fa fa-moon-o";
document.body.classList.remove("dark_mode");
}

document.getElementById("dark_mode").addEventListener("click", dark);
document.getElementById("dark_mode").addEventListener("click", toggleDarkMode);
1 change: 0 additions & 1 deletion wiktionary_pron/scripts/pdf_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ async function main(layoutType, darkMode, transcriptionLang) {
};
const rowsUnpacked = getTableRowsUnpacked();
const rows = getTableRows();
let items;
switch (layoutType) {
case "line":
putDivsLineByLine(rowsUnpacked, pdfDoc, 15, darkMode);
Expand Down

0 comments on commit 510c831

Please sign in to comment.