Last active
November 25, 2022 17:22
-
-
Save hangim/13f188bfd0e1bd6654c2e85f1b1bade1 to your computer and use it in GitHub Desktop.
This file contains 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
// ==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