Skip to content

Commit

Permalink
feat(startpage): added support for startpage, wip, cleanup necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ManagarmrWhisperer committed Mar 13, 2024
1 parent 8e073c4 commit d5aa1ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 39 deletions.
56 changes: 21 additions & 35 deletions js/search/bing.js → js/search/startpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ const wikis = prepareWikisInfo( getWikis( false, true ), {


class DdgSearchModule extends GenericSearchModule {
ENGINE_LAYOUT_SELECTOR = '#b_results';
RESULT_CONTAINER_SELECTOR = 'li.b_algo, div.slide';
ORDINARY_RESULT_CLASS_NAME = 'b_algo';
URL_ELEMENT_SELECTOR = 'h2#b_topTitle';
SPAN_TITLE_ELEMENT_SELECTOR = 'h2 > a';
ANCHOR_ELEMENT_SELECTOR = 'div > cite';
NETWORK_NAME_ELEMENT_SELECTOR = '.tptt';
BLACKLIST = 'slide'; // TODO: This should be a list
ENGINE_LAYOUT_SELECTOR = '.w-gl--desktop';
RESULT_CONTAINER_SELECTOR = '.w-gl__result';
URL_ELEMENT_SELECTOR = '.w-gl__result-url';
SPAN_TITLE_ELEMENT_SELECTOR = '.w-gl__result-title > h3';
BADGE_ELEMENT_SELECTOR = '.w-gl__result-title';
ANCHOR_ELEMENT_SELECTOR = '.w-gl__result-url'; // URL breadcumb
/**
* @protected
* @return {string}
Expand Down Expand Up @@ -56,7 +54,7 @@ class DdgSearchModule extends GenericSearchModule {

findNearestGgResult( wikiInfo, boundaryElement ) {
for ( const node of document.querySelectorAll( wikiInfo.search.goodSelector ) ) {
if ( this.isBlacklisted( node ) && ( node.compareDocumentPosition( boundaryElement ) & 0x02 ) ) {
if ( node.compareDocumentPosition( boundaryElement ) & 0x02 ) {
return crawlUntilParentFound( node, this.RESULT_CONTAINER_SELECTOR );
}
}
Expand All @@ -70,24 +68,7 @@ class DdgSearchModule extends GenericSearchModule {
* @param {HTMLElement} _foundLinkElement
*/
async hideResult( wikiInfo, containerElement, _foundLinkElement ) {
// This is just a placeholder, what if we had different elements?
if ( containerElement.classList.contains( this.ORDINARY_RESULT_CLASS_NAME ) ) {

// Try to find the first wiki.gg result after this one
const ggResult = this.findNearestGgResult( wikiInfo, containerElement );

let replacement;
if ( ggResult ) {
replacement = ggResult;
} else {
replacement = constructReplacementMarker( wikiInfo );
}
containerElement.textContent = '';
containerElement.append( replacement );
} else {
containerElement.style.display = 'none';
}

super.hideResult( wikiInfo, containerElement, _foundLinkElement );
}


Expand All @@ -114,20 +95,25 @@ class DdgSearchModule extends GenericSearchModule {
const badgeElement = constructRedirectBadge( {
allMoved: true,
theme: {
fontSize: '60%',
color: '#222'
fontSize: '80%',
color: document.documentElement.classList.contains("startpage-html--dark" || "startpage-html--night") ? '#a7b1fc' : '#000000',
marginBottom: '1%',
display: 'inline-block'
}
} );
titleSpan.appendChild( badgeElement );
containerElement.querySelector( this.BADGE_ELEMENT_SELECTOR ).appendChild( badgeElement );

// Rewrite URL breadcrumb
//Rewrite URL breadcrumb
for ( const url of containerElement.querySelectorAll( this.ANCHOR_ELEMENT_SELECTOR ) ) {
RewriteUtil.doUrlSpan( wikiInfo, url );
}

// Rewrite network name
containerElement.querySelector( this.NETWORK_NAME_ELEMENT_SELECTOR ).textContent = 'wiki.gg';
}
}

DdgSearchModule.invoke( wikis );
debugger;
document.onreadystatechange = () => {
if (document.readyState === "complete") {
DdgSearchModule.invoke( wikis );

}
};
7 changes: 4 additions & 3 deletions manifests/chrome_dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@
},
{
"matches": [
"https://www.bing.com/*"
"https://www.startpage.com/sp/search/*"
],
"js": [
"built/bing.js"
"built/startpage.js"
],
"run_at": "document_end"
}
Expand Down Expand Up @@ -125,7 +125,8 @@
"https://www.google.pl/*",
"https://www.google.pt/*",
"https://duckduckgo.com/*",
"https://www.bing.com/*"
"https://www.bing.com/*",
"https://www.startpage.com/*"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion rollup-config-background.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const scripts = [
{ script: 'popup' },
{ script: 'search/google', output: 'google', isContentScript: true },
{ script: 'search/ddg', output: 'ddg', isContentScript: true },
{ script: 'search/bing', output: 'bing', isContentScript: true },
{ script: 'search/startpage', output: 'startpage', isContentScript: true },
{ script: 'fandom', isContentScript: true },
];

Expand Down

0 comments on commit d5aa1ca

Please sign in to comment.