-
Notifications
You must be signed in to change notification settings - Fork 0
Collapse file tree
Files
Search this repository(forward slash) forward slash/
/
Copy pathcontent.js
More file actions
More file actions
Latest commit
871 lines (749 loc) · 15.3 KB
/
Copy pathcontent.js
File metadata and controls
871 lines (749 loc) · 15.3 KB
You must be signed in to make or propose changes
More edit options
Edit and raw actions
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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
"use strict";
const api = globalThis.browser ?? globalThis.chrome;
const LOOKUP_BATCH_SIZE = 256;
const HOSTNAME_CACHE_LIMIT = 2000;
const ENGINE_CONFIGS = Object.freeze([
{
matches(hostname) {
return hostname.includes("google.");
},
resultSelectors: [
"#search .MjjYud",
"#search .g",
"#rso > div[data-hveid]",
"#botstuff .MjjYud"
],
preferredLinkSelectors: [
"a[href] h3"
],
unwrapUrl(url) {
if (
url.pathname === "/url" &&
url.hostname.includes("google.")
) {
const target =
url.searchParams.get("q") ??
url.searchParams.get("url");
if (target) {
try {
return new URL(target);
} catch {
return null;
}
}
}
return url;
}
},
{
matches(hostname) {
return hostname.endsWith("bing.com");
},
resultSelectors: [
"#b_results > li.b_algo"
],
preferredLinkSelectors: [
"h2 > a[href]"
]
},
{
matches(hostname) {
return hostname.endsWith(
"duckduckgo.com"
);
},
resultSelectors: [
"article[data-testid='result']",
".react-results--main article",
".results_links",
".result"
],
preferredLinkSelectors: [
"a[data-testid='result-title-a']",
"a.result__a"
],
unwrapUrl(url) {
if (
url.hostname.endsWith(
"duckduckgo.com"
) &&
url.pathname === "/l/"
) {
const target =
url.searchParams.get("uddg");
if (target) {
try {
return new URL(target);
} catch {
return null;
}
}
}
return url;
}
},
{
matches(hostname) {
return (
hostname === "search.yahoo.com"
);
},
resultSelectors: [
"#web > ol > li",
"#web .dd.algo"
],
preferredLinkSelectors: [
"h3 a[href]"
]
},
{
matches(hostname) {
return hostname.endsWith(
"startpage.com"
);
},
resultSelectors: [
".w-gl__result",
".result"
],
preferredLinkSelectors: [
"a.result-title[href]",
"h3 a[href]"
]
},
{
matches(hostname) {
return hostname.endsWith(
"ecosia.org"
);
},
resultSelectors: [
"article.result",
".result"
],
preferredLinkSelectors: [
"a.result-title[href]",
"h2 a[href]"
]
},
{
matches(hostname) {
return (
hostname === "search.brave.com"
);
},
resultSelectors: [
".snippet[data-type='web']",
"[data-type='web']"
],
if (
record.type ===
"attributes" &&
record.target instanceof
Element
) {
const result =
record.target.matches(
resultSelector
)
? record.target
: record.target.closest(
resultSelector
);
if (result) {
queueResult(result);
}
}
}
requestProcessing();
}
);
observer.observe(
document.documentElement,
{
childList: true,
subtree: true,
attributes: true,
attributeFilter: [
"href"
]
}
);
api.runtime.onMessage.addListener(
(message) => {
if (
message?.type !==
"filter-state-changed"
) {
return undefined;
}
invalidateAndRescan();
return undefined;
}
);
globalThis.addEventListener(
"pageshow",
(event) => {
if (event.persisted) {
invalidateAndRescan();
}
}
);
globalThis.addEventListener(
"pagehide",
() => {
observer?.disconnect();
pendingResults.clear();
hostnameCache.clear();
},
{
once: true
}
);
}