Skip to content

Instantly share code, notes, and snippets.

@Flithor
Created January 17, 2025 00:43
Show Gist options
  • Select an option

  • Save Flithor/2a1517cf35d22cba7718ba8e4ab420a6 to your computer and use it in GitHub Desktop.

Select an option

Save Flithor/2a1517cf35d22cba7718ba8e4ab420a6 to your computer and use it in GitHub Desktop.
Set Or Remove "noTranslate" for any element in selector
// Ctrl+C/V to chrome developer tools source code - snippets and run it.
// Execute setNoTranslate or setCanTranslate with element selector
// to set or remove notranslate attribute on those.
// Then can make elements non-translatable which you want,
// and also make non-translatable element translatable.
function setNoTranslate(selector, setAttribute=true) {
var elements = document.querySelectorAll(selector);
if (setAttribute) {
elements.forEach(element=>element.classList.add('notranslate'));
} else {
return Array.from(elements);
}
}
function setCanTranslate(selector, setAttribute=true) {
var elements = document.querySelectorAll(selector);
if (setAttribute) {
elements.forEach(element=>{
element.classList.remove('notranslate');
element.translate="yes";
});
} else {
return Array.from(elements);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment