Skip to content

Instantly share code, notes, and snippets.

@hangim
Last active November 25, 2022 17:22
Show Gist options
  • Save hangim/13f188bfd0e1bd6654c2e85f1b1bade1 to your computer and use it in GitHub Desktop.
Save hangim/13f188bfd0e1bd6654c2e85f1b1bade1 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Remove Twitter Lang Attribute
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Remove Twitter Lang Attribute
// @author You
// @match https://twitter.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Ref: https://ryankubik.com/blog/remove-twitter-distractions
// Ref: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
// Select the node that will be observed for mutations
const targetNode = document.querySelector('html');
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
mutationsList.forEach(mutation => mutation.target.querySelectorAll("[lang]").forEach(dom => dom.removeAttribute("lang")));
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
// Delete once when load
document.querySelectorAll("[lang]").forEach(x => x.removeAttribute("lang"))
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment