This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
95 lines (82 loc) · 3.06 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function getByText(selector, text) {
return Array.from(
document.querySelectorAll(selector)
).find(div => div.textContent.includes(text));
}
function getByInnerText(selector, text) {
return Array.from(
document.querySelectorAll(selector)
).find(div => div.innerText.includes(text));
}
function replace() {
// get pawified
const getVerified = getByInnerText("div[data-testid='UserName'] > div.css-175oi2r", "Get verified")
if (getVerified) {
getVerified.innerHTML = getVerified.innerHTML.replace("Get verified", "Get pawified")
}
const headerReplacements = {
"Home": "Pawm",
"Explore": "Pawsplore",
"Notifications": "Pawifications",
"Messages": "Pawssages",
"Lists": "Pawlists",
"Bookmarks": "Pawmarks",
"Jobs": "Pawjobs",
"Communities": "Pawomunities",
"Premium": "Pawmium",
"Verified Orgs": "Verified Paworgs",
"Profile": "Pawfile",
"Grok": "Pawk",
}
const dropdownReplacements = {
"Create your Space": "Create your Pawspace",
"Monetization": "Pawjobization",
"Ads": "Pawds",
"Settings and privacy": "Pawtings and pawvacy",
}
// headerReplacements
for (
const [originalText, newText] of Object.entries(headerReplacements)
) {
// https://stackoverflow.com/a/38399344/26767691
const headerElement = document.querySelector(`header > * a[aria-label*='${originalText}' i]`)
if (headerElement) {
const textElement = headerElement.querySelector("div > div[dir=ltr]:not([aria-label]) > span")
if (textElement) {
textElement.innerHTML = newText
}
}
}
// dropdownReplacements
for (
const [originalText, newText] of Object.entries(dropdownReplacements)
) {
const dropdownElement = getByText("div[data-testid='Dropdown'] > div > div > a", originalText)
if (dropdownElement) {
const textElement = dropdownElement.querySelector("div > div[dir=ltr]:not([aria-label]) > span")
if (textElement) {
textElement.innerHTML = newText
}
}
}
// "Post" button (#5)
const postButton = document.querySelector("header > * a[aria-label='Post']")
const postText = postButton?.querySelector("span > span")
if (postText) { postText.innerHTML = "Pawst" }
// Premium -> Pawmium on https://twitter.com/i/premium_sign_up
const dialog = document.querySelector("div[role='dialog'][aria-modal=true]")
const dialogTexts = dialog.querySelectorAll("span")
Array.from(dialogTexts).forEach(dialogText => {
if (!dialogText) { return }
dialogText.innerHTML = dialogText.innerHTML.replace("Premium", "Pawmium")
})
}
let previousHTML = document.querySelector('body').innerHTML
function checkForChanges() {
const currentHTML = document.querySelector('body').innerHTML
if (currentHTML !== previousHTML) {
replace()
previousHTML = currentHTML
}
}
setInterval(checkForChanges, 100)