-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: master
Are you sure you want to change the base?
Changes from all commits
ee683e3
246103e
34d8be6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,11 @@ export default function () { | |
}, | ||
ddg: { | ||
mode: 'rewrite' | ||
}, | ||
startpage: { | ||
mode: 'rewrite' | ||
} | ||
|
||
} | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
]; | ||
|
||
|
||
|
@@ -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 | ||
} ); | ||
|
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' ]; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?} | ||
*/ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ); | ||
} | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant new line. |
||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant new lines. |
||
], | ||
"icons": { | ||
"128": "icons/128_dev.png" | ||
|
@@ -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/*" | ||
] | ||
} | ||
], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still pending.