Skip to content

Commit

Permalink
google: support memex results
Browse files Browse the repository at this point in the history
  • Loading branch information
infokiller committed Jul 17, 2020
1 parent f7e28ac commit 68df065
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 12 deletions.
3 changes: 3 additions & 0 deletions assets/chrome_webstore_description.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

0.4.13
* Google: add options for adding WorldBrain's Memex extension results

0.4.12
* Fix issue with options saving

Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Web Search Navigator",
"version": "0.4.12",
"version": "0.4.13",
"description": "Keyboard shortcuts for Google, YouTube, Github, Amazon, Scholar, and Startpage.",
"author": "Web Search Navigator",
"icons": {
Expand Down
8 changes: 8 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ const DEFAULT_CSS = `/* NOTE:
border: 1px solid black !important;
}
.wsn-google-focused-memex-result {
border: 1px solid black !important;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
/* Startpage has dark themes where a black outline won't be visible */
.wsn-startpage-focused-link {
outline: 1px solid #435a69 !important;
Expand Down Expand Up @@ -105,6 +112,7 @@ const DEFAULT_OPTIONS = {
hideOutline: false,
delay: 0,
googleIncludeCards: true,
googleIncludeMemex: false,
customCSS: DEFAULT_CSS,
};

Expand Down
5 changes: 5 additions & 0 deletions src/options_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ <h2>Google specific settings</h2>
<input type="checkbox" id="google-include-cards"> Include cards (top stories, twitter, videos) in regular Google search page
</label>
</div>
<div class="option">
<label for="google-include-memex">
<input type="checkbox" id="google-include-memex"> Include WorldBrain's Memex extension results in Google
</label>
</div>
</section>
<section id="keybindings-container">
<h2>Keybindings</h2>
Expand Down
6 changes: 5 additions & 1 deletion src/options_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ class OptionsPageManager {
setOpt('delay',
document.getElementById('delay').value);
setOpt('googleIncludeCards',
document.getElementById('google-include-cards').value);
document.getElementById('google-include-cards').checked);
setOpt('googleIncludeMemex',
document.getElementById('google-include-memex').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
Expand Down Expand Up @@ -227,6 +229,8 @@ class OptionsPageManager {
document.getElementById('delay').value = getOpt('delay');
document.getElementById('google-include-cards').checked =
getOpt('googleIncludeCards');
document.getElementById('google-include-memex').checked =
getOpt('googleIncludeMemex');
// 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
Expand Down
51 changes: 41 additions & 10 deletions src/search_engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,12 @@ class GoogleSearch {
document.querySelector('#searchform.minidiv'), element);
}
onChangedResults(callback) {
if (!this.isImagesTab_()) {
return;
if (this.isImagesTab_()) {
return this.onImageSearchResults_(callback);
}
const container = document.querySelector('.islrc');
if (!container) {
return;
if (this.options.googleIncludeMemex) {
return this.onMemexResults_(callback);
}
const observer = new MutationObserver(async (mutationsList, observer) => {
callback(true);
});
observer.observe(container,
{attributes: false, childList: true, subtree: false});
}

isImagesTab_() {
Expand Down Expand Up @@ -252,6 +246,17 @@ class GoogleSearch {
},
);
}
if (this.options.googleIncludeMemex) {
includedElements.push(
{
nodes: document.querySelectorAll(
'#memexResults ._3d3zwUrsb4CVi1Li4H6CBw a'),
// anchorSelector: nearestChildOrParentAnchor,
// highlightedElementSelector: nearestCardContainer,
highlightClass: 'wsn-google-focused-memex-result',
},
);
}
// People also ask. Each one of the used selectors should be sufficient,
// but we use both to be more robust to upstream DOM changes.
const excludedElements = document.querySelectorAll([
Expand All @@ -261,6 +266,32 @@ class GoogleSearch {
return getSortedSearchResults(includedElements, excludedElements);
}

onImageSearchResults_(callback) {
const container = document.querySelector('.islrc');
if (!container) {
return;
}
const observer = new MutationObserver(async (mutationsList, observer) => {
callback(true);
});
observer.observe(container,
{attributes: false, childList: true, subtree: false});
}

onMemexResults_(callback) {
const container = document.querySelector('#rhs');
if (!container) {
return;
}
const observer = new MutationObserver(async (mutationsList, observer) => {
if (document.querySelector('#memexResults') != null) {
callback(true);
}
});
observer.observe(container,
{attributes: false, childList: true, subtree: true});
}

get imageSearchTabs_() {
const visibleTabs = document.querySelectorAll('.T47uwc > a');
// NOTE: The order of the tabs after the first two is dependent on the
Expand Down

0 comments on commit 68df065

Please sign in to comment.