forked from sumimakito/Chrome-qwq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject.js
111 lines (105 loc) · 3.92 KB
/
inject.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Created by makito on 2017/9/5.
*/
var QWQ = "<span> qwq</span>";
var scheduled = false;
var currentSite = -1;
var TWITTER = 0;
var WEIBO = 1;
var initRetries = 0;
if (/(^.*\.weibo\.com$|^weibo\.com$)/g.exec(window.location.host) !== null) {
currentSite = WEIBO;
} else if (/(^twitter\.com$)/g.exec(window.location.host) !== null) {
currentSite = TWITTER;
}
function qwqize() {
if (currentSite === TWITTER) {
var elements_tweet_text = document.getElementsByClassName("tweet-text");
for (var i = 0; i < elements_tweet_text.length; i++) {
var el = elements_tweet_text[i];
if (el.getAttribute("qwq") === "true" ||
el.innerHTML.endsWith(QWQ)) {
continue;
}
el.innerHTML += QWQ;
el.setAttribute("qwq", "true");
}
scheduled = false;
}
else if (currentSite === WEIBO) {
var elements = document.getElementsByClassName("WB_text");
for (var i = 0; i < elements.length; i++) {
var el = elements[i];
if (el.getAttribute("qwq") === "true") continue;
if (el.getAttribute("node-type") === "feed_list_content") {
if (el.innerHTML.endsWith(QWQ)) {
continue;
}
el.innerHTML = el.innerHTML.replace(/([^q][^w][^q])(\/\/<a)/g, "$1qwq//<a"); // literally insert a qwq if the string doesn't end with qwq
el.innerHTML = el.innerHTML.replace(/([a-zA-z])(qwq\/\/<a)/g, "$1 $2"); // avoid qwq being connected with alphabetic string
el.innerHTML += QWQ;
el.setAttribute("qwq", "true");
} else if (el.getAttribute("node-type") === "feed_list_reason") {
el.innerHTML += QWQ;
el.setAttribute("qwq", "true");
}
}
var buttons = document.getElementsByClassName("W_btn_a");
for (var i = 0; i < buttons.length; i++) {
var el = buttons[i];
if (el.getAttribute("qwq") === "true") continue;
if (el.getAttribute("node-type") === "submit") {
if (el.innerHTML.endsWith(QWQ)) {
continue;
}
el.innerText = "卖萌";
el.setAttribute("qwq", "true");
}
}
var pf_intro = document.getElementsByClassName("pf_intro");
if (pf_intro !== null && pf_intro.length >= 1) {
var intro = pf_intro[0];
if (intro.getAttribute("qwq") !== "true"){
intro.innerHTML += "<br>賣萌博主";
intro.setAttribute("qwq", "true");
}
}
scheduled = false;
}
}
function schedule() {
if (scheduled) return;
scheduled = true;
setTimeout(qwqize, 2000);
}
function init() {
var done = false;
if (currentSite === TWITTER) {
var stream = document.getElementsByClassName("stream");
if (stream !== null && stream.length >= 1) {
document.getElementsByClassName("stream")[0].addEventListener("DOMNodeInserted", schedule, false);
document.getElementById("global-new-tweet-button").innerHTML = '<span class="text">卖萌</span>';
done = true;
}
}
else if (currentSite === WEIBO) {
var homefeed = document.getElementById("v6_pl_content_homefeed");
var profilefeed = document.getElementById("Pl_Official_MyProfileFeed__22");
if (homefeed !== null) {
homefeed.addEventListener("DOMNodeInserted", schedule, false);
done = true;
} else if (profilefeed !== null) {
profilefeed.addEventListener("DOMNodeInserted", schedule, false);
done = true;
}
document.body.addEventListener("DOMNodeInserted", schedule, false);
}
if (!done) {
if (initRetries++ < 10) {
setTimeout(init, 1000);
}
} else {
qwqize();
}
}
init();