-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontent3.min.js
151 lines (151 loc) · 4.55 KB
/
content3.min.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var sepPort = chrome.runtime.connect({ name: "search_engine_parser" });
let shContent = [];
function sepOnWindowLoad() {
let e = document.querySelector("title");
if (e) {
if (-1 != document.location.hostname.indexOf("youtube")) {
var t = document.title.toString();
new MutationObserver(function (e) {
e.some(function (e) {
var n = e.target.textContent.toString();
(n = (n = n.replace(/^\([0-9]{0,}\)\s/, "")).replace(/ +/g, " ")) !=
t &&
-1 != document.URL.indexOf("results?search_query") &&
(searchFlaggedData(n), (t = n));
});
}).observe(e, { subtree: !0, characterData: !0, childList: !0 });
}
sepCheckTitle(e);
} else setTimeout(bingIssueFix, 2e3);
}
function bingIssueFix() {
if (-1 != document.location.hostname.indexOf("bing")) {
let e = document.querySelector("input[type=search]");
if (e && "" != e.value) {
return void searchFlaggedData(e.value + " - bing");
}
}
}
function sepCheckTitle(e) {
if (e && (!e.text || "" == e.text)) return;
let t = e.text;
if (-1 != document.location.hostname.indexOf("youtube")) {
let e = /^\([0-9]{0,}\)\s/;
t = (t = t.replace(e, "")).replace(/ +/g, " ");
} else
-1 != document.location.hostname.indexOf("bing") &&
(t = t.toLowerCase().replace(" - search", " - bing"));
searchFlaggedData(t);
}
function searchFlaggedData(e) {
let t = !1;
for (let n = 0; n < shContent.length; n++) {
if (-1 != e.toLowerCase().indexOf("google")) {
let o = document.querySelector("div#taw");
if (
o &&
((indexStr = o.innerHTML
.toLowerCase()
.indexOf(shContent[n].toLowerCase())),
-1 != indexStr)
) {
let a = Array.from(o.getElementsByTagName("a")),
r = a.length > 0 ? a[0].href : "";
t ||
sendSHData(
e.toLowerCase().replace("- google search", "").trim(),
r,
shContent[n],
sepCleanDomainName(document.domain),
),
(t = !0);
}
} else if (-1 != e.toLowerCase().indexOf("bing")) {
let o = document.querySelector("li.b_ans.b_top");
if (
o &&
((indexStr = o.innerHTML
.toLowerCase()
.indexOf(shContent[n].toLowerCase())),
-1 != indexStr)
) {
let a = Array.from(o.getElementsByTagName("a")),
r = a.length > 0 ? a[0].href : "";
t ||
sendSHData(
e.toLowerCase().replace("- bing", "").trim(),
r,
shContent[n],
sepCleanDomainName(document.domain),
),
(t = !0);
}
} else if (-1 != e.toLowerCase().indexOf("yahoo search")) {
let o = document.querySelector("div#results div#main li.first");
if (
o &&
((indexStr = o.innerHTML
.toLowerCase()
.indexOf(shContent[n].toLowerCase())),
-1 != indexStr)
) {
let a = Array.from(o.getElementsByTagName("a")),
r = a.length > 0 ? a[0].href : "";
t ||
sendSHData(
e.toLowerCase().replace("- yahoo search results", "").trim(),
r,
shContent[n],
sepCleanDomainName(document.domain),
),
(t = !0);
}
} else if (-1 != e.toLowerCase().indexOf("- youtube")) {
let o = document.querySelector("ytd-emergency-onebox-renderer");
if (
o &&
((indexStr = o.innerHTML
.toLowerCase()
.indexOf(shContent[n].toLowerCase())),
-1 != indexStr)
) {
let a = Array.from(o.getElementsByTagName("a")),
r = a.length > 0 ? a[0].href : "";
t ||
sendSHData(
e.toLowerCase().replace("- youtube", "").trim(),
r,
shContent[n],
sepCleanDomainName(document.domain),
),
(t = !0);
}
}
if (t) break;
}
}
function sepSendData(e) {
sepPort.postMessage({ action: "fetchResult" });
}
function sendSHData(e, t, n, o) {
sepPort.postMessage({
action: "sendSHResult",
msg: e,
url: t,
matchedTerm: n,
domain: o,
});
}
function sepCleanDomainName(e) {
return e.replace(/^(?:https?:\/\/)?(?:www\.)?/i, "");
}
function sepCallWindowLoadWithTimeOut() {
sepSendData(), setTimeout(sepOnWindowLoad, 2e3);
}
sepPort.onMessage.addListener(function (e) {
shContent = e;
}),
window.addEventListener
? window.addEventListener("load", sepCallWindowLoadWithTimeOut, !1)
: window.attachEvent &&
window.attachEvent("onload", sepCallWindowLoadWithTimeOut);