Skip to content

Commit

Permalink
feat: change title to Twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve committed Jul 28, 2023
1 parent d8f5385 commit 83667d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Fuck Elon Musk

> Fuck Elon Musk! Let's bring the Twitter bird back
> Fuck Elon Musk! Let's bring Twitter back.
[Install on Greasyfork](https://greasyfork.org/zh-CN/scripts/471602-elon-musk)
19 changes: 13 additions & 6 deletions script.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @name Fuck Elon Musk
// @namespace https://greasyfork.org/scripts/471597-elon-musk
// @version 0.4.3
// @description Fuck Elon Musk! Let's bring the Twitter bird back.
// @description Fuck Elon Musk! Let's bring Twitter back.
// @author Ray (https://github.com/so1ve)
// @license MIT
// @run-at document-start
Expand Down Expand Up @@ -45,16 +45,18 @@
});
});

function observeUrlChange(callback) {
let oldHref = document.location.href;
const createObserver = (valueToWatch) => (callback) => {
let oldValue = valueToWatch();
const observer = new MutationObserver(() => {
if (oldHref !== document.location.href) {
oldHref = document.location.href;
if (oldValue !== valueToWatch()) {
oldValue = valueToWatch();
callback();
}
});
observer.observe(document.body, { childList: true, subtree: true });
}
};
const observeUrlChange = createObserver(() => document.location.href);
const observeTitleChange = createObserver(() => document.title);

const LOGO_SELECTOR = 'a[href="/home"][aria-label="Twitter"]';
const NAVBAR_LOGO_SELECTOR =
Expand Down Expand Up @@ -103,4 +105,9 @@
initChangers();
observeUrlChange(initChangers);
window.addEventListener("resize", initChangers);
observeTitleChange(() => {
if (document.title.endsWith("X")) {
document.title = `${document.title.slice(0, -1)}Twitter`;
}
});
})();

0 comments on commit 83667d4

Please sign in to comment.