diff --git a/defaults.js b/defaults.js index e88e45f..daf5d79 100644 --- a/defaults.js +++ b/defaults.js @@ -43,7 +43,11 @@ export default function () { }, ddg: { mode: 'rewrite' + }, + startpage: { + mode: 'rewrite' } + } }; } diff --git a/js/popup/DeclarativeSettings.js b/js/popup/DeclarativeSettings.js index fd6dd45..7a569b0 100644 --- a/js/popup/DeclarativeSettings.js +++ b/js/popup/DeclarativeSettings.js @@ -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 ); } diff --git a/js/popup/SearchFilterSettings.js b/js/popup/SearchFilterSettings.js index 4b171be..ed59741 100644 --- a/js/popup/SearchFilterSettings.js +++ b/js/popup/SearchFilterSettings.js @@ -1,7 +1,7 @@ import { createDomElement, getMessage -} from "../util.js"; +} from '../util.js'; /** @@ -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 + } ]; @@ -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 } ); diff --git a/js/popup/WikiList.js b/js/popup/WikiList.js index 38cc3ed..be6a05e 100644 --- a/js/popup/WikiList.js +++ b/js/popup/WikiList.js @@ -4,7 +4,7 @@ import { getWikis, createDomElement, getMessage -} from "../util.js"; +} from '../util.js'; function debounce( callback, wait ) { @@ -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 => { @@ -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 ) } - } ), + } ) } ); } @@ -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 ) { @@ -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', { @@ -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 } ); } } diff --git a/js/search/.#startpage.js b/js/search/.#startpage.js new file mode 120000 index 0000000..090a7ef --- /dev/null +++ b/js/search/.#startpage.js @@ -0,0 +1 @@ +nereida@Cygnus.10831:1699559769 \ No newline at end of file diff --git a/js/search/baseSearch.js b/js/search/baseSearch.js index b19591b..d8505ec 100644 --- a/js/search/baseSearch.js +++ b/js/search/baseSearch.js @@ -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?} */ @@ -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' ); @@ -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 ); } diff --git a/js/search/startpage.js b/js/search/startpage.js index a11450e..8972dd9 100644 --- a/js/search/startpage.js +++ b/js/search/startpage.js @@ -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'; } @@ -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 ); } @@ -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 ); + } + +} ); diff --git a/js/util.js b/js/util.js index a1b6d6f..88ebc3b 100644 --- a/js/util.js +++ b/js/util.js @@ -186,7 +186,7 @@ export function getNativeSettings() { * }>} [events] * @property {HTMLElement} [appendTo] * @property {HTMLElement} [prependTo] -*/ + */ /** * @param {keyof HTMLElementTagNameMap} tag