code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
constructor() { this.sync = createSyncedOptions(); this.local = new BrowserStorage(browser.storage.local, { lastQueryUrl: null, lastFocusedIndex: 0, }); }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
constructor
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
load() { return Promise.all([this.local.load(), this.sync.load()]); }
@param {StorageArea} storage The storage area to which this section will write. @param {Object} defaultValues The default options. @constructor
load
javascript
infokiller/web-search-navigator
src/options.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options.js
MIT
setSearchEnginePermission_ = async (checkbox) => { const urls = OPTIONAL_PERMISSIONS_URLS[checkbox.id]; if (checkbox.checked) { checkbox.checked = false; const granted = await browser.permissions.request({origins: urls}); checkbox.checked = granted; } else { browser.permissions.remove({origins: urls}); } }
Add other search engines domain on user input @param {Element} checkbox
setSearchEnginePermission_
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
setSearchEnginePermission_ = async (checkbox) => { const urls = OPTIONAL_PERMISSIONS_URLS[checkbox.id]; if (checkbox.checked) { checkbox.checked = false; const granted = await browser.permissions.request({origins: urls}); checkbox.checked = granted; } else { browser.permissions.remove({origins: urls}); } }
Add other search engines domain on user input @param {Element} checkbox
setSearchEnginePermission_
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
async init() { await this.loadOptions(); const braveSearch = document.getElementById('brave-search'); braveSearch.addEventListener('change', () => { setSearchEnginePermission_(braveSearch); }); const startpage = document.getElementById('startpage'); startpage.addEventListener('change', () => { setSearchEnginePermission_(startpage); }); const youtube = document.getElementById('youtube'); youtube.addEventListener('change', () => { setSearchEnginePermission_(youtube); }); const googleScholar = document.getElementById('google-scholar'); googleScholar.addEventListener('change', () => { setSearchEnginePermission_(googleScholar); }); const github = document.getElementById('github'); github.addEventListener('change', () => { setSearchEnginePermission_(github); }); const amazon = document.getElementById('amazon'); amazon.addEventListener('change', () => { setSearchEnginePermission_(amazon); }); const gitlab = document.getElementById('gitlab'); gitlab.addEventListener('change', () => { setSearchEnginePermission_(gitlab); }); const customGitlab = document.getElementById('custom-gitlab'); customGitlab.addEventListener('change', () => { setSearchEnginePermission_(customGitlab); }); // NOTE: this.saveOptions and this.resetToDefaults cannot be passed directly // or otherwise `this` won't be bound to the object. document.getElementById('save').addEventListener('click', () => { this.saveOptions(); }); document.getElementById('reset').addEventListener('click', () => { this.resetToDefaults(); }); }
Add other search engines domain on user input @param {Element} checkbox
init
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
async saveOptions() { const getOpt = (key) => { return this.options.get(key); }; const setOpt = (key, value) => { this.options.set(key, value); }; // Handle non-keybindings settings first setOpt( 'wrapNavigation', document.getElementById('wrap-navigation').checked, ); setOpt( 'autoSelectFirst', document.getElementById('auto-select-first').checked, ); setOpt('hideOutline', document.getElementById('hide-outline').checked); setOpt('delay', document.getElementById('delay').value); setOpt( 'googleIncludeCards', document.getElementById('google-include-cards').checked, ); setOpt( 'googleIncludeMemex', document.getElementById('google-include-memex').checked, ); setOpt( 'googleIncludePlaces', document.getElementById('google-include-places').checked, ); // Handle keybinding options for (const [key, optName] of Object.entries(KEYBINDING_TO_DIV)) { // Keybindings are stored internally as arrays, but edited by users as // comman delimited strings. setOpt( key, keybindingStringToArray(document.getElementById(optName).value), ); } const customCSS = document.getElementById('custom-css-textarea').value; if (getOpt('customCSS') !== DEFAULT_CSS || customCSS !== DEFAULT_CSS) { if (customCSS.trim()) { setOpt('customCSS', customCSS); } else { setOpt('customCSS', DEFAULT_CSS); } } setOpt( 'simulateMiddleClick', document.getElementById('simulate-middle-click').checked, ); const gitlabURLRegex = document.getElementById('custom-gitlab-url').value; try { new RegExp(gitlabURLRegex); setOpt( 'customGitlabUrl', document.getElementById('custom-gitlab-url').value, ); } catch (e) { const status = document.getElementById('status'); status.textContent = `Invalid gitlab URL regex: ${e.message}`; return; } try { await this.options.save(); this.flashMessage('Options saved'); } catch (e) { this.flashMessage('Error when saving options'); } }
Add other search engines domain on user input @param {Element} checkbox
saveOptions
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
getOpt = (key) => { return this.options.get(key); }
Add other search engines domain on user input @param {Element} checkbox
getOpt
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
getOpt = (key) => { return this.options.get(key); }
Add other search engines domain on user input @param {Element} checkbox
getOpt
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
setOpt = (key, value) => { this.options.set(key, value); }
Add other search engines domain on user input @param {Element} checkbox
setOpt
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
setOpt = (key, value) => { this.options.set(key, value); }
Add other search engines domain on user input @param {Element} checkbox
setOpt
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
loadSearchEnginePermissions_(permissions) { // Check what URLs we have permission for. const braveSearch = document.getElementById('brave-search'); braveSearch.checked = OPTIONAL_PERMISSIONS_URLS['brave-search'].every( (url) => { return permissions.origins.includes(url); }, ); const startpage = document.getElementById('startpage'); startpage.checked = OPTIONAL_PERMISSIONS_URLS['startpage'].every((url) => { return permissions.origins.includes(url); }); const youtube = document.getElementById('youtube'); youtube.checked = OPTIONAL_PERMISSIONS_URLS['youtube'].every((url) => { return permissions.origins.includes(url); }); const googleScholar = document.getElementById('google-scholar'); googleScholar.checked = OPTIONAL_PERMISSIONS_URLS['google-scholar'].every( (url) => { return permissions.origins.includes(url); }, ); const amazon = document.getElementById('amazon'); amazon.checked = OPTIONAL_PERMISSIONS_URLS['amazon'].every((url) => { return permissions.origins.includes(url); }); const github = document.getElementById('github'); github.checked = OPTIONAL_PERMISSIONS_URLS['github'].every((url) => { return permissions.origins.includes(url); }); const gitlab = document.getElementById('gitlab'); gitlab.checked = OPTIONAL_PERMISSIONS_URLS['gitlab'].every((url) => { return permissions.origins.includes(url); }); const customGitlab = document.getElementById('custom-gitlab'); customGitlab.checked = OPTIONAL_PERMISSIONS_URLS['custom-gitlab'].every( (url) => { return permissions.origins.includes(url); }, ); }
Add other search engines domain on user input @param {Element} checkbox
loadSearchEnginePermissions_
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
async loadOptions() { this.options = createSyncedOptions(); const [, permissions] = await Promise.all([ this.options.load(), browser.permissions.getAll(), ]); this.loadSearchEnginePermissions_(permissions); const getOpt = (key) => { return this.options.get(key); }; // Handle checks separately. document.getElementById('wrap-navigation').checked = getOpt('wrapNavigation'); document.getElementById('auto-select-first').checked = getOpt('autoSelectFirst'); document.getElementById('hide-outline').checked = getOpt('hideOutline'); document.getElementById('delay').value = getOpt('delay'); document.getElementById('custom-gitlab-url').value = getOpt('customGitlabUrl'); document.getElementById('google-include-cards').checked = getOpt('googleIncludeCards'); document.getElementById('google-include-memex').checked = getOpt('googleIncludeMemex'); document.getElementById('google-include-places').checked = getOpt( 'googleIncludePlaces', ); // Restore options from divs. for (const [key, optName] of Object.entries(KEYBINDING_TO_DIV)) { // Keybindings are stored internally as arrays, but edited by users as // comman delimited strings. document.getElementById(optName).value = keybindingArrayToString( getOpt(key), ); } // Load custom CSS document.getElementById('custom-css-textarea').value = getOpt('customCSS'); document.getElementById('simulate-middle-click').checked = getOpt( 'simulateMiddleClick', ); }
Add other search engines domain on user input @param {Element} checkbox
loadOptions
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
getOpt = (key) => { return this.options.get(key); }
Add other search engines domain on user input @param {Element} checkbox
getOpt
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
getOpt = (key) => { return this.options.get(key); }
Add other search engines domain on user input @param {Element} checkbox
getOpt
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
async resetToDefaults() { try { await this.options.clear(); await this.loadOptions(); this.flashMessage('Options set to defaults'); } catch (e) { this.flashMessage('Error when setting options to defaults'); } }
Add other search engines domain on user input @param {Element} checkbox
resetToDefaults
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
flashMessage(message) { // Update status to let user know. const status = document.getElementById('status'); status.textContent = message; setTimeout(() => { status.textContent = ''; }, 3000); }
Add other search engines domain on user input @param {Element} checkbox
flashMessage
javascript
infokiller/web-search-navigator
src/options_page.js
https://github.com/infokiller/web-search-navigator/blob/master/src/options_page.js
MIT
constructor( element, anchorSelector, highlightClass, highlightedElementSelector, containerSelector, ) { this.#element = element; this.#anchorSelector = anchorSelector; this.highlightClass = highlightClass; this.#highlightedElementSelector = highlightedElementSelector; this.#containerSelector = containerSelector; }
@param {Element} element @param {function|null} anchorSelector @param {string} highlightClass @param {function|null} highlightedElementSelector @param {function|null} containerSelector
constructor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get anchor() { if (!this.#anchorSelector) { return this.#element; } return this.#anchorSelector(this.#element); }
@param {Element} element @param {function|null} anchorSelector @param {string} highlightClass @param {function|null} highlightedElementSelector @param {function|null} containerSelector
anchor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get container() { if (!this.#containerSelector) { return this.#element; } return this.#containerSelector(this.#element); }
@param {Element} element @param {function|null} anchorSelector @param {string} highlightClass @param {function|null} highlightedElementSelector @param {function|null} containerSelector
container
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get highlightedElement() { if (!this.#highlightedElementSelector) { return this.#element; } return this.#highlightedElementSelector(this.#element); }
@param {Element} element @param {function|null} anchorSelector @param {string} highlightClass @param {function|null} highlightedElementSelector @param {function|null} containerSelector
highlightedElement
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getSortedSearchResults = ( includedSearchResults, excludedNodeList = [], ) => { const excludedResultsSet = new Set(); for (const node of excludedNodeList) { excludedResultsSet.add(node); } const searchResults = []; for (const results of includedSearchResults) { for (const node of results.nodes) { const searchResult = new SearchResult( node, results.anchorSelector, results.highlightClass, results.highlightedElementSelector, results.containerSelector, ); const anchor = searchResult.anchor; // Use offsetParent to exclude hidden elements, see: // https://stackoverflow.com/a/21696585/1014208 if ( anchor != null && !excludedResultsSet.has(anchor) && anchor.offsetParent !== null ) { // Prevent adding the same node multiple times. excludedResultsSet.add(anchor); searchResults.push(searchResult); } } } // Sort searchResults by their document position. searchResults.sort((a, b) => { const position = a.anchor.compareDocumentPosition(b.anchor); if (position & Node.DOCUMENT_POSITION_FOLLOWING) { return -1; } else if (position & Node.DOCUMENT_POSITION_PRECEDING) { return 1; } else { return 0; } }); return searchResults; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
getSortedSearchResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getSortedSearchResults = ( includedSearchResults, excludedNodeList = [], ) => { const excludedResultsSet = new Set(); for (const node of excludedNodeList) { excludedResultsSet.add(node); } const searchResults = []; for (const results of includedSearchResults) { for (const node of results.nodes) { const searchResult = new SearchResult( node, results.anchorSelector, results.highlightClass, results.highlightedElementSelector, results.containerSelector, ); const anchor = searchResult.anchor; // Use offsetParent to exclude hidden elements, see: // https://stackoverflow.com/a/21696585/1014208 if ( anchor != null && !excludedResultsSet.has(anchor) && anchor.offsetParent !== null ) { // Prevent adding the same node multiple times. excludedResultsSet.add(anchor); searchResults.push(searchResult); } } } // Sort searchResults by their document position. searchResults.sort((a, b) => { const position = a.anchor.compareDocumentPosition(b.anchor); if (position & Node.DOCUMENT_POSITION_FOLLOWING) { return -1; } else if (position & Node.DOCUMENT_POSITION_PRECEDING) { return 1; } else { return 0; } }); return searchResults; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
getSortedSearchResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getFixedSearchBoxTopMargin = (searchBoxContainer, element) => { // When scrolling down, the search box can have a fixed position and can hide // search results, so we try to compensate for it. if (!searchBoxContainer || searchBoxContainer.contains(element)) { return 0; } return searchBoxContainer.getBoundingClientRect().height; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
getFixedSearchBoxTopMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getFixedSearchBoxTopMargin = (searchBoxContainer, element) => { // When scrolling down, the search box can have a fixed position and can hide // search results, so we try to compensate for it. if (!searchBoxContainer || searchBoxContainer.contains(element)) { return 0; } return searchBoxContainer.getBoundingClientRect().height; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
getFixedSearchBoxTopMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
isFirefox = () => { return navigator.userAgent.toLowerCase().indexOf('firefox') >= 0; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
isFirefox
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
isFirefox = () => { return navigator.userAgent.toLowerCase().indexOf('firefox') >= 0; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
isFirefox
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getDefaultBottomMargin = (element) => { return 28; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
getDefaultBottomMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getDefaultBottomMargin = (element) => { return 28; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
getDefaultBottomMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
selectorElementGetter = (selector) => { return () => { return document.querySelector(selector); }; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
selectorElementGetter
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
selectorElementGetter = (selector) => { return () => { return document.querySelector(selector); }; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
selectorElementGetter
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
nParent = (element, n) => { while (n > 0 && element) { element = element.parentElement; n--; } return element; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
nParent
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
nParent = (element, n) => { while (n > 0 && element) { element = element.parentElement; n--; } return element; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
nParent
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
debounce = (callback, delayMs) => { let timeoutId; return (...args) => { clearTimeout(timeoutId); timeoutId = setTimeout(() => { return callback(...args); }, delayMs); }; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
debounce
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
debounce = (callback, delayMs) => { let timeoutId; return (...args) => { clearTimeout(timeoutId); timeoutId = setTimeout(() => { return callback(...args); }, delayMs); }; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
debounce
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
constructor(options) { this.options = options; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
constructor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get urlPattern() { return /^https:\/\/(www\.)?google\./; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
urlPattern
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get searchBoxSelector() { // Must match search engine search box // NOTE: we used '#searchform input[name=q]' before 2020-06-05 but that // doesn't work in the images search tab. Another option is to use // 'input[role="combobox"]' but this doesn't work when there's also a // dictionary search box. // return '#searchform input[name=q]', return 'form[role=search] [name=q]'; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
searchBoxSelector
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getTopMargin(element) { return getFixedSearchBoxTopMargin( document.querySelector('#searchform.minidiv'), element, ); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
getTopMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getBottomMargin(element) { return isFirefox() ? 0 : getDefaultBottomMargin(); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
getBottomMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
onChangedResults(callback) { if (GoogleSearch.#isImagesTab()) { return GoogleSearch.#onImageSearchResults(callback); } if (this.options.googleIncludeMemex) { return GoogleSearch.#onMemexResults(callback); } // https://github.com/infokiller/web-search-navigator/issues/464 const container = document.querySelector('#rcnt'); if (!container) { return; } const observer = new MutationObserver( debounce((mutationsList, observer) => { callback(true); }, 50), ); observer.observe(container, { attributes: false, childList: true, subtree: true, }); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
onChangedResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
nearestChildOrSiblingOrParentAnchor = (element) => { const childAnchor = element.querySelector('a'); if (childAnchor && childAnchor.href) { return childAnchor; } const siblingAnchor = element.parentElement.querySelector('a'); if (siblingAnchor && siblingAnchor.href) { return siblingAnchor; } return element.closest('a'); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
nearestChildOrSiblingOrParentAnchor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
nearestChildOrSiblingOrParentAnchor = (element) => { const childAnchor = element.querySelector('a'); if (childAnchor && childAnchor.href) { return childAnchor; } const siblingAnchor = element.parentElement.querySelector('a'); if (siblingAnchor && siblingAnchor.href) { return siblingAnchor; } return element.closest('a'); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
nearestChildOrSiblingOrParentAnchor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
nearestCardContainer = (element) => { return element.closest('g-inner-card'); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
nearestCardContainer
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
nearestCardContainer = (element) => { return element.closest('g-inner-card'); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
nearestCardContainer
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getSearchResults() { if (GoogleSearch.#isImagesTab()) { return GoogleSearch.#getImagesTabResults(); } const includedElements = GoogleSearch.#regularResults(); if (this.options.googleIncludeCards) { includedElements.push(...GoogleSearch.#cardResults()); } if (this.options.googleIncludePlaces) { includedElements.push(...GoogleSearch.#placesResults()); } if (this.options.googleIncludeMemex) { includedElements.push(...GoogleSearch.#memexResults()); } const excludedElements = document.querySelectorAll( [ // People also ask. Each one of the used selectors should be // sufficient, but we use both to be more robust to upstream DOM // changes. '.related-question-pair a', '#search .kp-blk:not(.c2xzTb) .r > a:first-of-type', // Right hand sidebar. We exclude it because it is after all the // results in the document order (as determined by // Node.DOCUMENT_POSITION_FOLLOWING used in getSortedSearchResults), // and it's confusing. '#rhs a', ].join(', '), ); return getSortedSearchResults(includedElements, excludedElements); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
getSearchResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get previousPageButton() { if (GoogleSearch.#isImagesTab()) { return null; } return selectorElementGetter('#pnprev'); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
previousPageButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get nextPageButton() { if (GoogleSearch.#isImagesTab()) { return null; } return selectorElementGetter('#pnnext'); }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
nextPageButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get tabs() { if (GoogleSearch.#isImagesTab()) { return GoogleSearch.#imageSearchTabs(); } return { navigateSearchTab: selectorElementGetter( // eslint-disable-next-line max-len 'a[href*="/search?q="]:not([href*="&tbm="]):not([href*="maps.google."])', ), navigateImagesTab: selectorElementGetter('a[href*="&tbm=isch"]'), navigateVideosTab: selectorElementGetter('a[href*="&tbm=vid"]'), navigateMapsTab: selectorElementGetter('a[href*="maps.google."]'), navigateNewsTab: selectorElementGetter('a[href*="&tbm=nws"]'), navigateShoppingTab: selectorElementGetter('a[href*="&tbm=shop"]'), navigateBooksTab: selectorElementGetter('a[href*="&tbm=bks"]'), navigateFlightsTab: selectorElementGetter('a[href*="&tbm=flm"]'), navigateFinancialTab: selectorElementGetter('[href*="/finance?"]'), }; }
@param {Array} includedSearchResults An array of tuples. Each tuple contains collection of the search results optionally accompanied with their container selector. @constructor
tabs
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
changeTools(period) { const searchParams = new URLSearchParams(window.location.search); // Use the last value of the tbs param in case there are multiple ones, // since the last one overrides the previous ones. const allTbsValues = searchParams.getAll('tbs'); const lastTbsValue = allTbsValues[allTbsValues.length - 1] || ''; const match = /(qdr:.|li:1)(,sbd:.)?/.exec(lastTbsValue); const currentPeriod = (match && match[1]) || ''; const currentSort = (match && match[2]) || ''; if (period === 'a') { searchParams.delete('tbs'); } else if (period) { let newTbs = ''; if (period === 'v') { if (currentPeriod === 'li:1') { newTbs = ''; } else { newTbs = 'li:1'; } } else { newTbs = `qdr:${period}`; } searchParams.set('tbs', `${newTbs}${currentSort}`); // Can't apply sort when not using period. } else if (currentPeriod) { searchParams.set( 'tbs', `${currentPeriod}` + (currentSort ? '' : ',sbd:1'), ); } const newSearchString = '?' + searchParams.toString(); if (newSearchString !== window.location.search) { window.location.search = newSearchString; } return false; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
changeTools
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
changeImageSize(size) { const sizeOptions = { LARGE: {value: 0, name: 'Large', code: 'l'}, MEDIUM: {value: 1, name: 'Medium', code: 'e'}, ICON: {value: 2, name: 'Icon', code: 'i'}, }; const openTool = document.querySelector( '[class="PNyWAd ZXJQ7c"][jsname="I4bIT"]', ); if (openTool != null) { openTool.click(); } const openSizeDropDown = document.querySelector('[aria-label="Size"]'); if (openSizeDropDown != null) { openSizeDropDown.click(); } const dropDownWithSize = document.querySelector( '[class="xFo9P r9PaP Fmo8N"][jsname="wLFV5d"]', ); const getButton = (selector) => { let button; if (document.querySelector(selector) != null) { button = document.querySelector(selector); } else { button = null; } return button; }; const setImageSize = (dropDownWithSize, buttonSelector) => { let button = getButton(buttonSelector); if (dropDownWithSize == null && button != null) { button.click(); } else if (dropDownWithSize != null && button == null) { dropDownWithSize.click(); button = getButton(buttonSelector); button.click(); } else if (dropDownWithSize != null && button != null) { button.click(); } }; switch (size) { case sizeOptions.LARGE.code: if ( dropDownWithSize == null || dropDownWithSize.getAttribute('aria-label') != sizeOptions.LARGE.name ) { setImageSize( dropDownWithSize, '[class="MfLWbb"][aria-label="Large"]', ); } break; case sizeOptions.MEDIUM.code: if ( dropDownWithSize == null || dropDownWithSize.getAttribute('aria-label') != sizeOptions.MEDIUM.name ) { setImageSize( dropDownWithSize, '[class="MfLWbb"][aria-label="Medium"]', ); } break; case sizeOptions.ICON.code: if ( dropDownWithSize == null || dropDownWithSize.getAttribute('aria-label') != sizeOptions.ICON.name ) { setImageSize(dropDownWithSize, '[class="MfLWbb"][aria-label="Icon"]'); } break; default: break; } }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
changeImageSize
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getButton = (selector) => { let button; if (document.querySelector(selector) != null) { button = document.querySelector(selector); } else { button = null; } return button; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getButton = (selector) => { let button; if (document.querySelector(selector) != null) { button = document.querySelector(selector); } else { button = null; } return button; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
setImageSize = (dropDownWithSize, buttonSelector) => { let button = getButton(buttonSelector); if (dropDownWithSize == null && button != null) { button.click(); } else if (dropDownWithSize != null && button == null) { dropDownWithSize.click(); button = getButton(buttonSelector); button.click(); } else if (dropDownWithSize != null && button != null) { button.click(); } }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
setImageSize
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
setImageSize = (dropDownWithSize, buttonSelector) => { let button = getButton(buttonSelector); if (dropDownWithSize == null && button != null) { button.click(); } else if (dropDownWithSize != null && button == null) { dropDownWithSize.click(); button = getButton(buttonSelector); button.click(); } else if (dropDownWithSize != null && button != null) { button.click(); } }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
setImageSize
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
constructor(options) { this.options = options; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
constructor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get urlPattern() { return /^https:\/\/search\.brave\.com/; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
urlPattern
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get searchBoxSelector() { return '.form-input, input[id=searchbox]'; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
searchBoxSelector
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getTopMargin(element) { return getFixedSearchBoxTopMargin( document.querySelector('header.navbar'), element, ); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getTopMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
onChangedResults(callback) { const containers = document.querySelectorAll('#results'); const observer = new MutationObserver( debounce((mutationsList, observer) => { callback(true); }, 50), ); for (const container of containers) { observer.observe(container, { attributes: false, childList: true, subtree: true, }); } }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
onChangedResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getSearchResults() { if (BraveSearch.#isTabActive(this.tabs.navigateNewsTab)) { return BraveSearch.#getNewsTabResults(); } else if (BraveSearch.#isTabActive(this.tabs.navigateVideosTab)) { return BraveSearch.#getVideosTabResults(); } const includedElements = [ { nodes: document.querySelectorAll('.snippet.fdb > a'), highlightClass: 'wsn-brave-search-focused-link', containerSelector: (n) => n.parentElement, }, // News cards { nodes: document.querySelectorAll( '.card[data-type="news"]:nth-child(-n+3)', ), highlightClass: 'wsn-brave-search-focused-card', }, // Video cards { nodes: document.querySelectorAll( '.card[data-type="videos"]:nth-child(-n+3)', ), highlightClass: 'wsn-brave-search-focused-card', }, ]; return getSortedSearchResults(includedElements); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getSearchResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get tabs() { return { navigateSearchTab: document.querySelector('a[href*="/search?q="]'), navigateImagesTab: document.querySelector( '#tab-images > a:first-of-type', ), navigateNewsTab: document.querySelector('a[href*="/news?q="]'), navigateVideosTab: document.querySelector( '#tab-videos > a:first-of-type', ), }; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
tabs
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
constructor(options) { this.options = options; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
constructor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get urlPattern() { return /^https:\/\/(www\.)?startpage\./; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
urlPattern
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get searchBoxSelector() { return '#q'; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
searchBoxSelector
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getTopMargin(element) { return getFixedSearchBoxTopMargin( document.querySelector('div.layout-web__header'), element, ); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getTopMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getBottomMargin(element) { // Startpage in Firefox has an issue where trying to scroll can result in // window.scrollY being updated for a brief time although no scrolling is // done, which confuses the scrollToElement function, which can lead to // being stuck focused on a search result. return isFirefox() ? 0 : getDefaultBottomMargin(); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getBottomMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getSearchResults() { // Don't initialize results navigation on image search, since it doesn't // work there. if (StartPage.#isImagesTab()) { return []; } const containerSelector = (element) => { if (StartPage.#isSearchTab()) { return element.closest('.w-gl__result'); } return element; }; const includedElements = [ { nodes: document.querySelectorAll('a.w-gl__result-url'), highlightedElementSelector: containerSelector, highlightClass: 'wsn-startpage-focused-link', containerSelector: containerSelector, }, { nodes: document.querySelectorAll('.pagination--desktop button'), highlightClass: 'wsn-startpage-focused-link', }, // As of 2020-06-20, this doesn't seem to match anything. { nodes: document.querySelectorAll( '.vo-sp.vo-sp--default > a.vo-sp__link', ), highlightedElementSelector: containerSelector, highlightClass: 'wsn-startpage-focused-link', }, ]; const excludedElements = document.querySelectorAll('button[disabled]'); return getSortedSearchResults(includedElements, excludedElements); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getSearchResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
containerSelector = (element) => { if (StartPage.#isSearchTab()) { return element.closest('.w-gl__result'); } return element; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
containerSelector
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
containerSelector = (element) => { if (StartPage.#isSearchTab()) { return element.closest('.w-gl__result'); } return element; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
containerSelector
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get previousPageButton() { const menuLinks = document.querySelectorAll('.inline-nav-menu__link'); if (!menuLinks || menuLinks.length < 4) { return null; } return document.querySelector( 'form.pagination__form.next-prev-form--desktop:first-of-type', ); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
previousPageButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get nextPageButton() { const menuLinks = document.querySelectorAll('.inline-nav-menu__link'); if (!menuLinks || menuLinks.length < 4) { return null; } return document.querySelector( 'form.pagination__form.next-prev-form--desktop:last-of-type', ); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
nextPageButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get tabs() { const menuLinks = document.querySelectorAll('.inline-nav-menu__link'); if (!menuLinks || menuLinks.length < 4) { return {}; } return { navigateSearchTab: menuLinks[0], navigateImagesTab: menuLinks[1], navigateVideosTab: menuLinks[2], navigateNewsTab: menuLinks[3], }; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
tabs
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
changeTools(period) { const forms = document.forms; let timeForm; for (let i = 0; i < forms.length; i++) { if (forms[i].className === 'search-filter-time__form') { timeForm = forms[i]; } } switch (period) { case 'd': timeForm.elements['with_date'][1].click(); break; case 'w': timeForm.elements['with_date'][2].click(); break; case 'm': timeForm.elements['with_date'][3].click(); break; case 'y': timeForm.elements['with_date'][4].click(); break; default: break; } }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
changeTools
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
constructor(options) { this.options = options; this.gridNavigation = false; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
constructor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get urlPattern() { return /^https:\/\/(www)\.youtube\./; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
urlPattern
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get searchBoxSelector() { return 'input#search'; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
searchBoxSelector
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getTopMargin(element) { return getFixedSearchBoxTopMargin( document.querySelector('#masthead-container'), element, ); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getTopMargin
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
onChangedResults(callback) { // The ytd-section-list-renderer element may not exist yet when this code // runs, so we look for changes in the higher level elements until we find // ytd-section-list-renderer. const YT_CONTAINER_SELECTOR = [ 'ytd-section-list-renderer', '.ytd-section-list-renderer', 'ytd-rich-grid-renderer', 'ytd-shelf-renderer', ].join(','); const resultsObserver = new MutationObserver( debounce((mutationsList, observer) => { callback(true); }, 50), ); let lastLoadedURL = null; const pageObserverCallback = (mutationsList, observer) => { const url = window.location.pathname + window.location.search; if (url === lastLoadedURL) { return; } else { resultsObserver.disconnect(); } const containers = document.querySelectorAll(YT_CONTAINER_SELECTOR); if (containers.length == 0) { return; } lastLoadedURL = url; callback(false); for (const container of containers) { resultsObserver.observe(container, { attributes: false, childList: true, subtree: true, }); } }; // TODO: the observer callback is triggered many times because of the broad // changes that the observer tracks. I tried to use other observation specs // to limit it, but then it failed to detect URL changes without page load // (which is what happened in issue #337 [1]). // [1] https://github.com/infokiller/web-search-navigator/issues/337 const pageObserver = new MutationObserver( debounce(pageObserverCallback, 50), ); pageObserver.observe(document.querySelector('#page-manager'), { attributes: false, childList: true, subtree: true, }); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
onChangedResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
pageObserverCallback = (mutationsList, observer) => { const url = window.location.pathname + window.location.search; if (url === lastLoadedURL) { return; } else { resultsObserver.disconnect(); } const containers = document.querySelectorAll(YT_CONTAINER_SELECTOR); if (containers.length == 0) { return; } lastLoadedURL = url; callback(false); for (const container of containers) { resultsObserver.observe(container, { attributes: false, childList: true, subtree: true, }); } }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
pageObserverCallback
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
pageObserverCallback = (mutationsList, observer) => { const url = window.location.pathname + window.location.search; if (url === lastLoadedURL) { return; } else { resultsObserver.disconnect(); } const containers = document.querySelectorAll(YT_CONTAINER_SELECTOR); if (containers.length == 0) { return; } lastLoadedURL = url; callback(false); for (const container of containers) { resultsObserver.observe(container, { attributes: false, childList: true, subtree: true, }); } }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
pageObserverCallback
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getSearchResults() { const includedElements = [ // Videos in vertical search results: https://imgur.com/a/Z8KV5Oe { nodes: document.querySelectorAll('a#video-title.ytd-video-renderer'), highlightClass: 'wsn-youtube-focused-video', highlightedElementSelector: (n) => n.closest('ytd-video-renderer'), containerSelector: (n) => n.closest('ytd-video-renderer'), }, // Playlist results in vertical search results: https://imgur.com/a/nPjGd9H { nodes: document.querySelectorAll( 'ytd-playlist-renderer a[href*="/playlist"]', ), highlightClass: 'wsn-youtube-focused-video', highlightedElementSelector: (n) => n.closest('ytd-playlist-renderer'), containerSelector: (n) => n.closest('ytd-playlist-renderer'), }, // Playlists { nodes: document.querySelectorAll('a.ytd-playlist-video-renderer'), highlightClass: 'wsn-youtube-focused-video', highlightedElementSelector: (n) => n.closest('ytd-playlist-video-renderer'), containerSelector: (n) => n.closest('ytd-playlist-video-renderer'), }, // Mixes { nodes: document.querySelectorAll('div#content a.ytd-radio-renderer'), highlightClass: 'wsn-youtube-focused-video', }, // Channels { nodes: document.querySelectorAll( 'ytd-grid-video-renderer a#video-title:not([aria-hidden="true"])', ), highlightClass: 'wsn-youtube-focused-grid-video', highlightedElementSelector: (n) => n.closest('ytd-grid-video-renderer'), containerSelector: (n) => n.closest('ytd-grid-video-renderer'), }, ]; // checking if homepage results are present const homePageElements = { nodes: document.querySelectorAll( 'ytd-rich-item-renderer a#video-title-link', ), highlightClass: 'wsn-youtube-focused-video', highlightedElementSelector: (n) => n.closest('ytd-rich-item-renderer'), containerSelector: (n) => n.closest('ytd-rich-item-renderer'), }; const results = getSortedSearchResults( [...includedElements, homePageElements], [], ); // When navigating away from the home page, the home page elements are still // in the DOM but they are not visible, so we must check if they are // visible (using offsetParent), not just if they are present. const isHomePage = Array.from(homePageElements.nodes).some( (n) => n.offsetParent != null, ); const gridRow = document.querySelector('ytd-rich-grid-row'); if (isHomePage && gridRow != null) { results.itemsPerRow = gridRow.getElementsByTagName( 'ytd-rich-item-renderer', ).length; results.gridNavigation = results.itemsPerRow > 0; } return results; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getSearchResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
changeTools(period) { if (!document.querySelector('div#collapse-content')) { const toggleButton = document.querySelectorAll( 'a.ytd-toggle-button-renderer', )[0]; // Toggling the buttons ensures that div#collapse-content is loaded toggleButton.click(); toggleButton.click(); } const forms = document.querySelectorAll( 'div#collapse-content > *:first-of-type ytd-search-filter-renderer', ); let neededForm = null; switch (period) { case 'h': neededForm = forms[0]; break; case 'd': neededForm = forms[1]; break; case 'w': neededForm = forms[2]; break; case 'm': neededForm = forms[3]; break; case 'y': neededForm = forms[4]; break; } if (neededForm) { neededForm.childNodes[1].click(); } }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
changeTools
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
constructor(options) { this.options = options; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
constructor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get urlPattern() { return /^https:\/\/scholar\.google\./; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
urlPattern
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get searchBoxSelector() { return '#gs_hdr_tsi'; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
searchBoxSelector
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getSearchResults() { const includedElements = [ { nodes: document.querySelectorAll('.gs_rt a'), highlightClass: 'wsn-google-focused-link', highlightedElementSelector: (n) => n.closest('.gs_rt'), containerSelector: (n) => n.parentElement.parentElement, }, { nodes: document.querySelectorAll( '.gs_ico_nav_previous, .gs_ico_nav_next', ), anchorSelector: (n) => n.parentElement, highlightClass: 'wsn-google-scholar-next-page', highlightedElementSelector: (n) => n.parentElement.children[1], containerSelector: (n) => n.parentElement.children[1], }, ]; return getSortedSearchResults(includedElements, []); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getSearchResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get previousPageButton() { const previousPageElement = document.querySelector('.gs_ico_nav_previous'); if (previousPageElement !== null) { return previousPageElement.parentElement; } return null; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
previousPageButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get nextPageButton() { const nextPageElement = document.querySelector('.gs_ico_nav_next'); if (nextPageElement !== null) { return nextPageElement.parentElement; } return null; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
nextPageButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
constructor(options) { this.options = options; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
constructor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get urlPattern() { return /^https:\/\/(www\.)?amazon\./; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
urlPattern
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get searchBoxSelector() { return '#twotabsearchtextbox'; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
searchBoxSelector
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
onChangedResults(callback) { const container = document.querySelector('.s-main-slot'); if (!container) { return; } const observer = new MutationObserver( debounce((mutationsList, observer) => { callback(false); }, 50), ); observer.observe(container, { attributes: false, childList: true, subtree: false, }); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
onChangedResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getSearchResults() { const includedElements = [ // Carousel items { nodes: document.querySelectorAll( '.s-main-slot .a-carousel-card h2 .a-link-normal.a-text-normal', ), highlightedElementSelector: (n) => n.closest('.a-carousel-card'), highlightClass: 'wsn-amazon-focused-carousel-item', containerSelector: (n) => n.closest('.a-carousel-card'), }, // Regular items. // NOTE: Must appear after the carousel items because this selector is // more general. { nodes: document.querySelectorAll( '.s-main-slot h2 .a-link-normal.a-text-normal', ), // highlightedElementSelector: (n) => n.parentElement.children[1], highlightedElementSelector: (n) => n.closest('.a-section').parentElement.closest('.a-section'), highlightClass: 'wsn-amazon-focused-item', containerSelector: (n) => n.closest('.a-section').parentElement.closest('.a-section'), }, // Next/previous and page numbers. { nodes: document.querySelectorAll('a.s-pagination-item'), highlightClass: 'wsn-amazon-focused-item', }, // Shopping card items { nodes: document.querySelectorAll( '.sc-list-item-content .a-list-item .a-link-normal', ), highlightClass: 'wsn-amazon-focused-cart-item', highlightedElementSelector: (n) => n.closest('.sc-list-item-content'), containerSelector: (n) => n.closest('.sc-list-item-content'), }, ]; // Exclude active page number and hidden carousel elements. // TODO: The hidden carousel elements do not match at page load because // they don't yet have the aria-hidden property set. const excludedElements = document.querySelectorAll( '.a-pagination .a-selected a, .a-carousel-card[aria-hidden="true"] a', ); return getSortedSearchResults(includedElements, excludedElements); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getSearchResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get previousPageButton() { return document.querySelector('a.s-pagination-previous'); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
previousPageButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get nextPageButton() { return document.querySelector('a.s-pagination-next'); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
nextPageButton
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
constructor(options) { this.options = options; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
constructor
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get urlPattern() { return /^https:\/\/(www\.)?github\.com/; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
urlPattern
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
get searchBoxSelector() { // TODO: With the escape key, this only works the first time the keybinding // is used, Since Github seem to capture this as well, which causes it to // leave the search box. return 'input[name="q"]'; }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
searchBoxSelector
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
getSearchResults() { const includedElements = [ // Repos { nodes: document.querySelectorAll('.repo-list a'), highlightClass: 'wsn-github-focused-item', containerSelector: (n) => n.closest('.mt-n1'), }, // Code { nodes: document.querySelectorAll('#code_search_results .text-normal a'), highlightClass: 'wsn-github-focused-item', }, // Commits/PRs { nodes: Github.#getCommitSearchLinks(), highlightClass: 'wsn-github-focused-item', }, // Issues { nodes: document.querySelectorAll( '#issue_search_results .text-normal a', ), highlightClass: 'wsn-github-focused-item', }, // Marketplace { nodes: document.querySelectorAll( '#marketplace_search_results .text-normal a', ), highlightClass: 'wsn-github-focused-item', }, // Topics { nodes: document.querySelectorAll( '#topic_search_results .text-normal a', ), highlightClass: 'wsn-github-focused-item', }, // Wikis { nodes: document.querySelectorAll('#wiki_search_results .text-normal a'), highlightClass: 'wsn-github-focused-item', }, // Users { nodes: document.querySelectorAll('#user_search_results .text-normal a'), highlightClass: 'wsn-github-focused-item', }, // Pinned repos in user profile { nodes: document.querySelectorAll( '.pinned-item-list-item-content span.repo', ), highlightClass: 'wsn-github-focused-item', highlightedElementSelector: (n) => n.closest('a'), containerSelector: (n) => n.closest('a'), anchorSelector: (n) => n.closest('a'), }, // Personal repos list in user profile { nodes: document.querySelectorAll( '#user-repositories-list a[itemprop*="codeRepository"]', ), highlightClass: 'wsn-github-focused-item', containerSelector: (n) => n.closest('li') || n, }, // Next/previous and page numbers. { nodes: document.querySelectorAll('.paginate-container a'), highlightClass: 'wsn-github-focused-pagination', }, ]; const searchParams = new URLSearchParams(window.location.search); // Starred repos of user if (searchParams.get('tab') === 'stars') { includedElements.push({ nodes: document.querySelectorAll('h3 a'), highlightClass: 'wsn-github-focused-item', }); } const excludedElements = [ // Exclude small links ...document.querySelectorAll('.muted-link, .Link--muted'), // Exclude topic tags ...document.querySelectorAll('.topic-tag'), // Exclude small links in commits // ...document.querySelectorAll( // '#commit_search_results .text-normal a.message'), ]; return getSortedSearchResults(includedElements, excludedElements); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
getSearchResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT
onChangedResults(callback) { const container = document.querySelector('body'); if (!container) { return; } // Store the last URL to detect page navigations (for example going to the // next page of results). let lastURL = window.location.href; const observer = new MutationObserver( debounce((mutationsList, observer) => { let appendOnly = true; if (window.location.href !== lastURL) { lastURL = window.location.href; appendOnly = false; } callback(appendOnly); }, 50), ); observer.observe(container, { attributes: false, childList: true, subtree: false, }); }
Filter the results based on special properties @param {*} period, filter identifier. Accepted filter are : 'a' : all results 'h' : last hour 'd' : last day 'w' : last week 'm' : last month 'y' : last year 'v' : verbatim search null : toggle sort
onChangedResults
javascript
infokiller/web-search-navigator
src/search_engines.js
https://github.com/infokiller/web-search-navigator/blob/master/src/search_engines.js
MIT