Greasy Fork is available in English.

Diskuse » Development

Modify Html tag

§
Posted: 09. 04. 2024
Edited: 09. 04. 2024

Hi everyone,

I would like to create a simple script that modifies the html tag, only on a specific site, as follows:

from <html lang="it"

to

<html lang="en-US"

Anyone want give me support?

Thanks in advance

§
Posted: 11. 04. 2024
Edited: 11. 04. 2024

This code should work:

document.querySelector('html').lang = "en-US";

Or, if you want to make use of a variable:

let elementHTML;
elementHTML = document.querySelector('html');
elementHTML.lang = "en-US";
§
Posted: 23. 04. 2024

Thanks for replying.
Could you please share me the complete code to use? (including the initial commits)
I tried but it doesn't seem to work.
When I load the specific page that I inserted in // @match, the extension icon flashes in the browser but the final result is not as expected, as you can see in my console (see attached image).

Thanks

§
Posted: 23. 04. 2024

This code should work:

// ==UserScript==
// @name        Sent lang to en-us
// @namespace   set-lang-to-en-us
// @description Redirect to raw archived pages.
// @supportURL  https://greasyfork.org/en/discussions/development/238912-modify-html-tag
// @match       *://*/*
// @version     0.1
// @run-at      document-end
// @grant       none
// ==/UserScript==

(function () {

  document.querySelector('html').lang = "en-US";

})();

If it does not work, please write the URL of that page so I can test it.

document.documentElement.lang = "en-US";

Post reply

Sign in to post a reply.