Skip to content

Commit

Permalink
feat(startpage): fixed code according to PR comments, ran linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ManagarmrWhisperer committed Apr 8, 2024
1 parent 246103e commit 34d8be6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
4 changes: 4 additions & 0 deletions defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export default function () {
},
ddg: {
mode: 'rewrite'
},
startpage: {
mode: 'rewrite'
}

}
};
}
15 changes: 10 additions & 5 deletions js/popup/SearchFilterSettings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
createDomElement,
getMessage
} from "../util.js";
} from '../util.js';


/**
Expand All @@ -18,13 +18,18 @@ export default class SearchFilterSettings {
{
id: 'google',
supportsFilter: true,
supportsRewrite: true,
supportsRewrite: true
},
{
id: 'ddg',
supportsFilter: true,
supportsRewrite: true,
supportsRewrite: true
},
{
id: 'startpage',
supportsFilter: true,
supportsRewrite: true
}
];


Expand All @@ -37,14 +42,14 @@ export default class SearchFilterSettings {
createDomElement( 'tr', {
html: [
createDomElement( 'td', {
text: getMessage( `sfs_engine_${info.id}` ),
text: getMessage( `sfs_engine_${info.id}` )
} ),
this.#createRadioCell( `sfs_mode_${info.id}`, 'sfs_rewrite', `sfs.${info.id}.mode`, 'rewrite',
false ),
this.#createRadioCell( `sfs_mode_${info.id}`, 'sfs_filter', `sfs.${info.id}.mode`, 'filter',
false ),
this.#createRadioCell( `sfs_mode_${info.id}`, 'sfs_rewrite', `sfs.${info.id}.mode`, 'none',
true ),
true )
],
appendTo: tbody
} );
Expand Down
39 changes: 21 additions & 18 deletions js/search/startpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ const wikis = prepareWikisInfo( getWikis( false, true ), {


class DdgSearchModule extends GenericSearchModule {
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
ENGINE_LAYOUT_SELECTOR = '.w-gl--desktop, .w-gl';
RESULT_CONTAINER_SELECTOR = '.w-gl__result, .result';
SPAN_TITLE_ELEMENT_SELECTOR = '.w-gl__result-title > h3, .result-title > h2';
BADGE_ELEMENT_SELECTOR = this.SPAN_TITLE_ELEMENT_SELECTOR;
// Element that will hold the badge.
ANCHOR_ELEMENT_SELECTOR = '.w-gl__result-url, .css-1su0nhd > span, .css-1qvmgy0 > span';
// URL breadcumb
DARK_THEMES = [ 'startpage-html--dark', 'startpage-html--night' ];

/**
* @protected
* @return {string}
*/
getId() {
return 'ddg';
return 'startpage';
}


Expand Down Expand Up @@ -68,7 +71,7 @@ class DdgSearchModule extends GenericSearchModule {
* @param {HTMLElement} _foundLinkElement
*/
async hideResult( wikiInfo, containerElement, _foundLinkElement ) {
super.hideResult( wikiInfo, containerElement, _foundLinkElement );
super.hideResult( wikiInfo, containerElement, _foundLinkElement );
}


Expand Down Expand Up @@ -96,24 +99,24 @@ class DdgSearchModule extends GenericSearchModule {
allMoved: true,
theme: {
fontSize: '80%',
color: document.documentElement.classList.contains("startpage-html--dark" || "startpage-html--night") ? '#a7b1fc' : '#000000',
marginBottom: '1%',
display: 'inline-block'
color: Array.from( document.documentElement.classList ).some( _class => this.DARK_THEMES.includes( _class ) ) ? '#a7b1fc' : '#000000',
marginBottom: '1%',
display: 'inline-block'
}
} );
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 );
}
}
}

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

}
};
document.addEventListener( 'readystatechange', event => {
if ( event.target.readyState === 'complete' ) {
DdgSearchModule.invoke( wikis );
}

} );

0 comments on commit 34d8be6

Please sign in to comment.