-
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
473 lines (408 loc) · 9.31 KB
/
Copy pathcontent.js
File metadata and controls
473 lines (408 loc) · 9.31 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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
"use strict";
const api = globalThis.browser ?? globalThis.chrome;
const ENGINE_CONFIGS = [
{
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']"
],
preferredLinkSelectors: [
"a[href] h2",
"a[href] .title"
]
},
{
matches(hostname) {
return (
hostname.endsWith("yandex.com") ||
hostname.endsWith("yandex.ru")
);
},
resultSelectors: [
"li.serp-item",
".serp-item"
],
) {
if (
result.isConnected &&
hostname &&
hostnameCache.has(hostname)
) {
setResultHidden(
result,
hostnameCache.get(hostname)
);
}
}
}
function scheduleResultsFromRoot(root) {
collectResults(
root,
resultSelector,
pendingResults
);
if (
pendingResults.size > 0 &&
!scheduled
) {
scheduled = true;
requestAnimationFrame(() => {
flushPendingResults().catch((error) => {
console.error(
"SERP Domain Index processing failed:",
error
);
});
});
}
}
function invalidateCacheAndRescan() {
lookupGeneration++;
hostnameCache.clear();
scheduleResultsFromRoot(document);
}
scheduleResultsFromRoot(document);
const observer = new MutationObserver(
(mutationRecords) => {
for (const record of mutationRecords) {
for (const node of record.addedNodes) {
if (node.nodeType === Node.ELEMENT_NODE) {
scheduleResultsFromRoot(node);
}
}
}
}
);
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
api.runtime.onMessage.addListener((message) => {
if (
message?.type !== "filter-state-changed"
) {
return undefined;
}
invalidateCacheAndRescan();
return undefined;
});
}