Skip to content

Commit

Permalink
fix(ddg) cleaned up code according to PR
Browse files Browse the repository at this point in the history
  • Loading branch information
ManagarmrWhisperer committed Jan 13, 2024
1 parent 4f87af1 commit f8e2c45
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions js/ddg.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { getWikis, getNativeSettings } from './util.js';
import {
prepareWikisInfo,
invokeSearchModule,
awaitElement
awaitElement,
observeMutation
} from './baseSearch.js';


Expand Down Expand Up @@ -185,6 +186,7 @@ const rewrite = {
this.rewriteLink( wiki, a );
}


// Rewrite title and append a badge
for ( const span of element.querySelectorAll( this.SPAN_TITLE_ELEMENT_SELECTOR ) ) {
if ( !wiki.search.titlePattern.test( span.textContent ) ) {
Expand All @@ -194,40 +196,40 @@ const rewrite = {
this.rewriteSpan( wiki, span );
}

element.querySelector(this.SPAN_TITLE_ELEMENT_SELECTOR).appendChild( this.makeBadgeElement( isTopLevel ) );

element.querySelector( this.SPAN_TITLE_ELEMENT_SELECTOR ).appendChild( this.makeBadgeElement( isTopLevel ) );
// Rewrite URL element
for ( const url of element.querySelectorAll( this.ANCHOR_ELEMENT_SELECTOR ) ) {
this.rewriteURLElement( wiki, url );
}


this.lock( element );
}
}
}
};



getNativeSettings().local.get( [ 'ddgEnable' ], result => {
if ( result.ddgEnable || result.ddgEnable === undefined ) {
awaitElement(
document.getElementById( 'react-layout' ),
'div > div > section',
sectionNode => {
awaitElement(
sectionNode,
'.react-results--main',
node => {
invokeSearchModule( wikis, rewrite.run.bind( rewrite ), filter.run.bind( filter ), node );
const moreResultsContainer = document.getElementById( 'react-layout' );
const dynamicObserver = new MutationObserver( updates => {
for ( const update of updates ) {
if ( update.addedNodes && update.addedNodes.length > 0 ) {
for ( const addedNode of update.addedNodes ) {
invokeSearchModule( wikis, rewrite.run.bind( rewrite ), filter.run.bind( filter ) );
}
);
}
}
);
} );

dynamicObserver.observe( moreResultsContainer, {
childList: true,
subtree: true
} );

}
} );

document.querySelector('#react-layout').addEventListener("click", (event) => {
if( event.target.id === 'more-results') {
invokeSearchModule( wikis, rewrite.run.bind( rewrite ), filter.run.bind( filter ) );
}
});

0 comments on commit f8e2c45

Please sign in to comment.