Skip to content

Commit e5e1236

Browse files
committed
feat: support changing notifications
1 parent 5bb8566 commit e5e1236

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

script.user.js

+31-16
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@
2121
const TWITTER_LOGO = `<svg viewBox="0 0 24 24" aria-hidden="true" class="__FUCK_MUSK_BLUE__ r-4qtqp9 r-yyyyoo r-16y2uox r-8kz0gk r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-lrsllp">${TWITTER_LOGO_G}</svg>`;
2222
/** @see https://greasyfork.org/zh-CN/scripts/471576-f-kelonmusk-twitter-com */
2323
const TWITTER_LOGO_FOR_SHORTCUT_ICON = `data:image/svg+xml,%3Csvg width='500' height='500' viewBox='0 0 500 500' xmlns='http://www.w3.org/2000/svg'%3E%3Ctitle%3Etwitter-logo%3C/title%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cpath d='M170.2264 442.7654c162.2648 0 251.0168-140.0367 251.0168-261.4758 0-3.9775 0-7.9371-.258-11.8788 17.2659-13.009 32.1701-29.1167 44.0148-47.5687-16.1013 7.4318-33.1817 12.3057-50.6712 14.4587 18.4168-11.4849 32.2005-29.5486 38.786-50.8295-17.3177 10.7044-36.2637 18.2483-56.0204 22.3062-27.3466-30.29-70.8-37.7036-105.9942-18.0837-35.194 19.62-53.3763 61.3941-44.351 101.8979-70.9346-3.7043-137.0242-38.6047-181.8212-96.0154-23.4157 41.9903-11.4554 95.7083 27.3136 122.6754-14.0397-.4335-27.7732-4.3786-40.0416-11.5025v1.1646c.0115 43.7452 29.6141 81.4229 70.778 90.085-12.9882 3.6897-26.6156 4.229-39.8352 1.5766 11.5575 37.4355 44.6783 63.0807 82.4224 63.8192-31.2398 25.5748-69.831 39.4584-109.564 39.4166A172.495 172.495 0 0 1 35 401.4854c40.345 26.9696 87.2885 41.275 135.2264 41.2083' fill='%231DA1F2'/%3E%3Cpath d='M35 35h430v430H35z'/%3E%3C/g%3E%3C/svg%3E%0A`;
24+
const FUCKER_X =
25+
'<g><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"></path></g>';
2426

2527
/**
2628
* @param {string} selector
27-
* @returns {Promise<HTMLElement>}
29+
* @returns {Promise<HTMLElement[]>}
2830
*/
29-
const waitForElement = (selector) =>
31+
const waitForElements = (selector) =>
3032
new Promise((resolve) => {
31-
if (document.querySelector(selector)) {
32-
return resolve(document.querySelector(selector));
33+
if (document.querySelectorAll(selector).length > 0) {
34+
return resolve(document.querySelectorAll(selector));
3335
}
3436
const observer = new MutationObserver(() => {
35-
if (document.querySelector(selector)) {
36-
resolve(document.querySelector(selector));
37+
if (document.querySelectorAll(selector).length > 0) {
38+
resolve(document.querySelectorAll(selector));
3739
observer.disconnect();
3840
}
3941
});
@@ -45,7 +47,7 @@
4547
} catch {
4648
// If failed, try again after 100ms
4749
setTimeout(() => {
48-
resolve(waitForElement(selector));
50+
resolve(waitForElements(selector));
4951
}, 100);
5052
}
5153
});
@@ -84,6 +86,7 @@
8486
"main > div > div > div > div:nth-child(2) > div > svg";
8587
const LOGOUT_ICON_SELECTOR =
8688
'div[data-testid="confirmationSheetDialog"] > svg';
89+
const NOTIFICATIONS_SELECTOR = "article";
8790

8891
const createStyleMaker =
8992
(selector) =>
@@ -102,54 +105,66 @@
102105
function initChangers() {
103106
GM_addStyle(COLOR_CSS);
104107

105-
waitForElement(ICON_SELECTOR).then((iconEl) => {
108+
waitForElements(ICON_SELECTOR).then(([iconEl]) => {
106109
iconEl.href = TWITTER_LOGO_FOR_SHORTCUT_ICON;
107110
});
108111

109112
GM_addStyle(makePlaceholderStyle(false));
110-
waitForElement(PLACEHOLDER_SELECTOR).then((placeholder) => {
113+
waitForElements(PLACEHOLDER_SELECTOR).then(([placeholder]) => {
111114
placeholder.children[0].innerHTML = TWITTER_LOGO;
112115
GM_addStyle(makePlaceholderStyle(true));
113116
});
114117

115118
GM_addStyle(makeTwitterLogoStyle(false));
116-
waitForElement(LOGO_SELECTOR).then((a) => {
119+
waitForElements(LOGO_SELECTOR).then(([a]) => {
117120
a.children[0].innerHTML = TWITTER_LOGO;
118121
GM_addStyle(makeTwitterLogoStyle(true));
119122
});
120123

121124
if (location.pathname === "/") {
122125
GM_addStyle(makeHomepageIconStyle(false));
123-
waitForElement(HOMEPAGE_ICON_SELECTOR).then((svg) => {
124-
svg.innerHTML = TWITTER_LOGO_G;
126+
waitForElements(HOMEPAGE_ICON_SELECTOR).then(([svg]) => {
125127
svg.classList.add("__FUCK_MUSK_BLUE__");
128+
svg.innerHTML = TWITTER_LOGO_G;
126129
GM_addStyle(makeHomepageIconStyle(true));
127130
});
128131

129132
GM_addStyle(makeHomepageLeftIconStyle(false));
130-
waitForElement(HOMEPAGE_LEFT_ICON_SELECTOR).then((svg) => {
133+
waitForElements(HOMEPAGE_LEFT_ICON_SELECTOR).then(([svg]) => {
131134
svg.innerHTML = TWITTER_LOGO_G;
132135
GM_addStyle(makeHomepageLeftIconStyle(true));
133136
});
134137
}
135138

136139
if (location.pathname === "/home") {
137140
GM_addStyle(makeTwitterNavbarLogoStyle(false));
138-
waitForElement(NAVBAR_LOGO_SELECTOR).then((div) => {
139-
div.children[1].innerHTML = TWITTER_LOGO;
141+
waitForElements(NAVBAR_LOGO_SELECTOR).then(([div]) => {
140142
div.children[1].classList.add("__FUCK_MUSK_BLUE__");
143+
div.children[1].innerHTML = TWITTER_LOGO;
141144
GM_addStyle(makeTwitterNavbarLogoStyle(true));
142145
});
143146
}
144147

145148
if (location.pathname === "/logout") {
146149
GM_addStyle(makeLogoutIconStyle(false));
147-
waitForElement(LOGOUT_ICON_SELECTOR).then((svg) => {
150+
waitForElements(LOGOUT_ICON_SELECTOR).then(([svg]) => {
148151
svg.classList.add("__FUCK_MUSK_BLUE__");
149152
svg.innerHTML = TWITTER_LOGO_G;
150153
GM_addStyle(makeLogoutIconStyle(true));
151154
});
152155
}
156+
157+
if (location.pathname === "/notifications") {
158+
waitForElements(NOTIFICATIONS_SELECTOR).then((notifications) => {
159+
for (const notification of notifications) {
160+
const svg = notification.children[0].children[0].children[0];
161+
if (svg.innerHTML === FUCKER_X) {
162+
svg.classList.add("__FUCK_MUSK_BLUE__");
163+
svg.innerHTML = TWITTER_LOGO_G;
164+
}
165+
}
166+
});
167+
}
153168
}
154169
initChangers();
155170
observeUrlChange(initChangers);

0 commit comments

Comments
 (0)