Last active
February 23, 2023 01:48
-
-
Save dcts/46a804dc1ffd55f56429b1a0a7ab2c03 to your computer and use it in GitHub Desktop.
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
// HELPER FUNCTIONS | |
function setLoading(bool) { | |
const bttn = document.querySelector(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewTranslateBttn_"); | |
const bttnText = document.querySelector(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewTranslateBttnText_"); | |
const bttnTextSpanLoader = document.querySelector(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewTranslateBttnTextSpanLoader_"); | |
if (bool) { // set loading state | |
bttn.classList.add("isLoading_"); | |
bttnText.classList.add("isLoading_"); | |
bttnTextSpanLoader.classList.add("isLoading_"); | |
} else { // unset loading state | |
bttn.classList.remove("isLoading_"); | |
bttnText.classList.remove("isLoading_"); | |
bttnTextSpanLoader.classList.remove("isLoading_"); | |
} | |
} | |
function resetLanguageSelection() { | |
document.querySelector(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewOutputArea_").value = ""; | |
document.querySelectorAll(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewLanguageSelectionUnorderedListItem_").forEach(li => li.classList.remove("isActive_")); | |
} | |
function getCodeFromInput() { | |
const code = document.querySelector(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewInputArea_").value; | |
return encodeURIComponent(code); | |
} | |
function getSelectedLanguage() { | |
const activeItem = document.querySelector(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewLanguageSelectionUnorderedListItem_.isActive_") | |
return encodeURIComponent(activeItem.dataset.lang); | |
} | |
// SITE INTERACTIVITY | |
setTimeout(() => { | |
console.log("JS loaded from raw.git"); | |
// chose target language functionality | |
document.querySelectorAll(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewLanguageSelectionUnorderedListItem_").forEach(li => { | |
li.addEventListener("click", (ev) => { | |
document.querySelector(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewOutputArea_").value = ""; | |
document.querySelectorAll(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewLanguageSelectionUnorderedListItem_").forEach(li => li.classList.remove("isActive_")); | |
li.classList.add("isActive_"); | |
}) | |
}) | |
// translate button logic | |
const translateBttn = document.querySelector(".experimentalEngeduGtiProjectsWeek20230206EmeaTeam03JavaComGoogleBoqCodetransUiHomeHomeViewTranslateBttn_"); | |
translateBttn.addEventListener("click", () => { | |
setLoading(true); | |
document.location.href = `/?code=${getCodeFromInput()}&target_language=${getSelectedLanguage()}`; | |
}) | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment