Skip to content

Instantly share code, notes, and snippets.

@sirius-beck
Last active April 9, 2024 14:54
Show Gist options
  • Save sirius-beck/1822478720e100ce3b13dde0e54415c0 to your computer and use it in GitHub Desktop.
Save sirius-beck/1822478720e100ce3b13dde0e54415c0 to your computer and use it in GitHub Desktop.
Stop browser from translating any code in the page.

Don't Translate Any Code

Stop browser from translating any code in the page.

Usage

Browser's URL Bar

Type javascript: in the browser's url bar, paste the following code and press enter.

var q=document.querySelectorAll;var o={p:q('pre'),c:q('code'),h1:q('h1'),h2:q('h2'),h3:q('h3'),a:q('a')};for(i in o){o[i].forEach((e)=>{e.setAttribute('translate', 'no')})};

DevTools Console

Open the devtools console, paste the following code and press enter.

const elements = {
  preElements: document.querySelectorAll('pre'),
  codeElements: document.querySelectorAll('code'),
  h1Elements: document.querySelectorAll('h1'),
  h2Elements: document.querySelectorAll('h2'),
  h3Elements: document.querySelectorAll('h3'),
  aElements: document.querySelectorAll('a')
}
for (element in elements) {
  elements[element].forEach((el) => {
    el.setAttribute('translate', 'no')
  })
}

How it works

The code above selects all pre, code, h1, h2, h3, and a elements in the page and sets the translate attribute to no for each of them. This attribute tells the browser not to translate the content of the element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment