Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/startpage new arch #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant new line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still pending.

}
};
}
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already told you there's no need for lines unrelated to the startpage change to be modified.

},
{
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
122 changes: 122 additions & 0 deletions js/search/startpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
'use strict';


import { getWikis } from '../util.js';
import {
GenericSearchModule,
prepareWikisInfo,
crawlUntilParentFound,
awaitElement,
RewriteUtil
} from './baseSearch.js';
import { constructRedirectBadge, constructReplacementMarker } from './components.js';


const wikis = prepareWikisInfo( getWikis( false, true ), {
titles: true,
selectors: true
} );


class DdgSearchModule extends GenericSearchModule {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class name.

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' ];

/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing new lines between property and method.

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


/**
* Finds a general result container for a given element, if any.
*
* @protected
* @param {HTMLElement} element Element to find result container for.
* @return {HTMLElement?}
*/
resolveResultContainer( element ) {
return crawlUntilParentFound( element, this.RESULT_CONTAINER_SELECTOR );
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be two lines between methods.

/**
* @protected
* @param {SiteRecord} wikiInfo
* @param {HTMLElement} boundaryElement
* @return {HTMLElement?}
*/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary new line.

findNearestGgResult( wikiInfo, boundaryElement ) {
for ( const node of document.querySelectorAll( wikiInfo.search.goodSelector ) ) {
if ( node.compareDocumentPosition( boundaryElement ) & 0x02 ) {
return crawlUntilParentFound( node, this.RESULT_CONTAINER_SELECTOR );
}
}
return null;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be two lines between methods.

/**
* @protected
* @param {SiteRecord} wikiInfo
* @param {HTMLElement} containerElement
* @param {HTMLElement} _foundLinkElement
*/
async hideResult( wikiInfo, containerElement, _foundLinkElement ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since it doesn't override the parent's functionality.

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


/**
* @protected
* @param {SiteRecord} wikiInfo
* @param {HTMLElement} containerElement
* @param {HTMLElement} _foundLinkElement
*/
async replaceResult( wikiInfo, containerElement, _foundLinkElement ) {
// Rewrite anchor href links
for ( const a of containerElement.getElementsByTagName( 'a' ) ) {
RewriteUtil.doLink( wikiInfo, a );
}

// Rewrite title and append a badge
// TODO: Maybe use All just incase that we get more elements
const titleSpan = containerElement.querySelector( this.SPAN_TITLE_ELEMENT_SELECTOR );
if ( wikiInfo.search.titlePattern.test( titleSpan.textContent ) ) {
RewriteUtil.doH3( wikiInfo, titleSpan );
}

// Insert our badge
const badgeElement = constructRedirectBadge( {
allMoved: true,
theme: {
fontSize: '80%',
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
for ( const url of containerElement.querySelectorAll( this.ANCHOR_ELEMENT_SELECTOR ) ) {
RewriteUtil.doUrlSpan( wikiInfo, url );
}
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two lines after a class definition and before other code.


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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant new line.

} );
15 changes: 14 additions & 1 deletion manifests/chrome_dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@
"built/fandom.js"
],
"run_at": "document_end"
},
{
"matches": [
"https://www.startpage.com/sp/search/*"
],
"js": [
"built/startpage.js"
],
"run_at": "document_end"
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant new lines.

],
"icons": {
"128": "icons/128_dev.png"
Expand Down Expand Up @@ -113,7 +124,9 @@
"https://www.google.nl/*",
"https://www.google.pl/*",
"https://www.google.pt/*",
"https://duckduckgo.com/*"
"https://duckduckgo.com/*",
"https://www.bing.com/*",
"https://www.startpage.com/*"
]
}
],
Expand Down
1 change: 1 addition & 0 deletions rollup-config-background.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const scripts = [
{ script: 'popup' },
{ script: 'search/google', output: 'google', isContentScript: true },
{ script: 'search/ddg', output: 'ddg', isContentScript: true },
{ script: 'search/startpage', output: 'startpage', isContentScript: true },
{ script: 'fandom', isContentScript: true },
];

Expand Down
Loading