Skip to content

Commit

Permalink
feat(startpage): cleaned up code and ran linter according to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ManagarmrWhisperer committed Apr 7, 2024
1 parent 246103e commit 652e9e5
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 45 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'
}

}
};
}
4 changes: 2 additions & 2 deletions js/popup/DeclarativeSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export class Control {
_trackKey( key );

switch ( inputElement.type ) {
case "radio":
case 'radio':
return this.#initialiseRadio( key, inputElement );
case "checkbox":
case 'checkbox':
if ( inputElement.getAttribute( 'data-array-value' ) ) {
return this.#initialiseArrayCheckbox( key, inputElement );
}
Expand Down
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
30 changes: 15 additions & 15 deletions js/popup/WikiList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getWikis,
createDomElement,
getMessage
} from "../util.js";
} from '../util.js';


function debounce( callback, wait ) {
Expand Down Expand Up @@ -35,7 +35,7 @@ export default class WikiList {
html: createDomElement( 'input', {
attributes: {
type: 'text',
placeholder: getMessage( 'sites_search_pl' ),
placeholder: getMessage( 'sites_search_pl' )
},
events: {
keydown: debounce( event => {
Expand All @@ -44,9 +44,9 @@ export default class WikiList {
const isVisible = element.innerText.toLowerCase().includes( value );
element.parentNode.setAttribute( 'data-is-filtered-out', !isVisible );
}
}, 50 ),
}, 50 )
}
} ),
} )
} );
}

Expand All @@ -57,7 +57,7 @@ export default class WikiList {
*/
static #createSiteList( wikis ) {
const result = createDomElement( 'div', {
classes: [ 'site-list' ],
classes: [ 'site-list' ]
} );

for ( const pack of wikis ) {
Expand All @@ -68,13 +68,13 @@ export default class WikiList {
createDomElement( 'h3', {
classes: [ 'site-list__heading' ],
text: pack.spacer,
appendTo: result,
appendTo: result
} );
} else {
createDomElement( 'div', {
classes: [ 'site-list__entry' ],
attributes: {
'data-wiki-id': pack.id,
'data-wiki-id': pack.id
},
html: [
createDomElement( 'input', {
Expand All @@ -84,24 +84,24 @@ export default class WikiList {
'data-setting-id': 'disabledWikis',
'data-array-value': pack.id,
'data-on': 'false',
'data-off': 'true',
},
'data-off': 'true'
}
} ),
createDomElement( 'label', {
attributes: {
for: `site-list__toggle--${pack.id}`,
for: `site-list__toggle--${pack.id}`
},
text: pack.name,
text: pack.name
} ),
createDomElement( 'a', {
classes: [ 'site-list__site-link' ],
attributes: {
href: `https://${pack.id}.wiki.gg`,
target: '_blank',
},
} ),
target: '_blank'
}
} )
],
appendTo: result,
appendTo: result
} );
}
}
Expand Down
1 change: 1 addition & 0 deletions js/search/.#startpage.js
8 changes: 4 additions & 4 deletions js/search/baseSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export function prepareWikisInfo( wikis, options ) {
* If max depth is not given, this is equivalent to a simple null sanity check and a `closest` call for performance
* reasons.
*
* @param {HTMLElement} element
* @param {string} selector
* @param {HTMLElement} element
* @param {string} selector
* @param {int} [maxDepth=-1]
* @return {HTMLElement?}
*/
Expand Down Expand Up @@ -257,7 +257,7 @@ export const RewriteUtil = {
if ( link.tagName.toLowerCase() !== 'a' ) {
return;
}

let href = link.href;
if ( href.startsWith( '/url?' ) ) {
href = ( new URLSearchParams( link.href ) ).get( 'url' );
Expand All @@ -280,7 +280,7 @@ export const RewriteUtil = {
doH3( wiki, node ) {
for ( const child of node.childNodes ) {
if ( child.textContent ) {
child.textContent = child.textContent.replace( wiki.search.titlePattern, wiki.search.newTitle )
child.textContent = child.textContent.replace( wiki.search.titlePattern, wiki.search.newTitle );
} else {
this.doH3( wiki, child );
}
Expand Down
36 changes: 18 additions & 18 deletions js/search/startpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ 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 +68,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 +96,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 );
}

} );
2 changes: 1 addition & 1 deletion js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export function getNativeSettings() {
* }>} [events]
* @property {HTMLElement} [appendTo]
* @property {HTMLElement} [prependTo]
*/
*/

/**
* @param {keyof HTMLElementTagNameMap} tag
Expand Down

0 comments on commit 652e9e5

Please sign in to comment.