Skip to content

Commit d5aa1ca

Browse files
feat(startpage): added support for startpage, wip, cleanup necessary
1 parent 8e073c4 commit d5aa1ca

File tree

3 files changed

+26
-39
lines changed

3 files changed

+26
-39
lines changed

js/search/bing.js renamed to js/search/startpage.js

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ const wikis = prepareWikisInfo( getWikis( false, true ), {
1919

2020

2121
class DdgSearchModule extends GenericSearchModule {
22-
ENGINE_LAYOUT_SELECTOR = '#b_results';
23-
RESULT_CONTAINER_SELECTOR = 'li.b_algo, div.slide';
24-
ORDINARY_RESULT_CLASS_NAME = 'b_algo';
25-
URL_ELEMENT_SELECTOR = 'h2#b_topTitle';
26-
SPAN_TITLE_ELEMENT_SELECTOR = 'h2 > a';
27-
ANCHOR_ELEMENT_SELECTOR = 'div > cite';
28-
NETWORK_NAME_ELEMENT_SELECTOR = '.tptt';
29-
BLACKLIST = 'slide'; // TODO: This should be a list
22+
ENGINE_LAYOUT_SELECTOR = '.w-gl--desktop';
23+
RESULT_CONTAINER_SELECTOR = '.w-gl__result';
24+
URL_ELEMENT_SELECTOR = '.w-gl__result-url';
25+
SPAN_TITLE_ELEMENT_SELECTOR = '.w-gl__result-title > h3';
26+
BADGE_ELEMENT_SELECTOR = '.w-gl__result-title';
27+
ANCHOR_ELEMENT_SELECTOR = '.w-gl__result-url'; // URL breadcumb
3028
/**
3129
* @protected
3230
* @return {string}
@@ -56,7 +54,7 @@ class DdgSearchModule extends GenericSearchModule {
5654

5755
findNearestGgResult( wikiInfo, boundaryElement ) {
5856
for ( const node of document.querySelectorAll( wikiInfo.search.goodSelector ) ) {
59-
if ( this.isBlacklisted( node ) && ( node.compareDocumentPosition( boundaryElement ) & 0x02 ) ) {
57+
if ( node.compareDocumentPosition( boundaryElement ) & 0x02 ) {
6058
return crawlUntilParentFound( node, this.RESULT_CONTAINER_SELECTOR );
6159
}
6260
}
@@ -70,24 +68,7 @@ class DdgSearchModule extends GenericSearchModule {
7068
* @param {HTMLElement} _foundLinkElement
7169
*/
7270
async hideResult( wikiInfo, containerElement, _foundLinkElement ) {
73-
// This is just a placeholder, what if we had different elements?
74-
if ( containerElement.classList.contains( this.ORDINARY_RESULT_CLASS_NAME ) ) {
75-
76-
// Try to find the first wiki.gg result after this one
77-
const ggResult = this.findNearestGgResult( wikiInfo, containerElement );
78-
79-
let replacement;
80-
if ( ggResult ) {
81-
replacement = ggResult;
82-
} else {
83-
replacement = constructReplacementMarker( wikiInfo );
84-
}
85-
containerElement.textContent = '';
86-
containerElement.append( replacement );
87-
} else {
88-
containerElement.style.display = 'none';
89-
}
90-
71+
super.hideResult( wikiInfo, containerElement, _foundLinkElement );
9172
}
9273

9374

@@ -114,20 +95,25 @@ class DdgSearchModule extends GenericSearchModule {
11495
const badgeElement = constructRedirectBadge( {
11596
allMoved: true,
11697
theme: {
117-
fontSize: '60%',
118-
color: '#222'
98+
fontSize: '80%',
99+
color: document.documentElement.classList.contains("startpage-html--dark" || "startpage-html--night") ? '#a7b1fc' : '#000000',
100+
marginBottom: '1%',
101+
display: 'inline-block'
119102
}
120103
} );
121-
titleSpan.appendChild( badgeElement );
104+
containerElement.querySelector( this.BADGE_ELEMENT_SELECTOR ).appendChild( badgeElement );
122105

123-
// Rewrite URL breadcrumb
106+
//Rewrite URL breadcrumb
124107
for ( const url of containerElement.querySelectorAll( this.ANCHOR_ELEMENT_SELECTOR ) ) {
125108
RewriteUtil.doUrlSpan( wikiInfo, url );
126109
}
127-
128-
// Rewrite network name
129-
containerElement.querySelector( this.NETWORK_NAME_ELEMENT_SELECTOR ).textContent = 'wiki.gg';
130110
}
131111
}
132112

133-
DdgSearchModule.invoke( wikis );
113+
debugger;
114+
document.onreadystatechange = () => {
115+
if (document.readyState === "complete") {
116+
DdgSearchModule.invoke( wikis );
117+
118+
}
119+
};

manifests/chrome_dev.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@
7777
},
7878
{
7979
"matches": [
80-
"https://www.bing.com/*"
80+
"https://www.startpage.com/sp/search/*"
8181
],
8282
"js": [
83-
"built/bing.js"
83+
"built/startpage.js"
8484
],
8585
"run_at": "document_end"
8686
}
@@ -125,7 +125,8 @@
125125
"https://www.google.pl/*",
126126
"https://www.google.pt/*",
127127
"https://duckduckgo.com/*",
128-
"https://www.bing.com/*"
128+
"https://www.bing.com/*",
129+
"https://www.startpage.com/*"
129130
]
130131
}
131132
],

rollup-config-background.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const scripts = [
66
{ script: 'popup' },
77
{ script: 'search/google', output: 'google', isContentScript: true },
88
{ script: 'search/ddg', output: 'ddg', isContentScript: true },
9-
{ script: 'search/bing', output: 'bing', isContentScript: true },
9+
{ script: 'search/startpage', output: 'startpage', isContentScript: true },
1010
{ script: 'fandom', isContentScript: true },
1111
];
1212

0 commit comments

Comments
 (0)