Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f57a7e4

Browse filesBrowse files
committed
Add experimental amazon.com support
1 parent 4351f05 commit f57a7e4
Copy full SHA for f57a7e4

File tree

Expand file treeCollapse file tree

6 files changed

+74
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+74
-12
lines changed
Open diff view settings
Collapse file

‎assets/chrome_webstore_description.txt‎

Copy file name to clipboardExpand all lines: assets/chrome_webstore_description.txt
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
New in 0.4.0
22
* Support for navigating to Top Stories, Twitter, Videos, and callouts
33
* Support for remapping keys with key sequences
4-
* Initial support for Youtube and Startpage (optional, needs to be enabled in
5-
options)
4+
* Experimental support for Youtube and Startpage (optional, needs to be enabled
5+
in options)
66
* Bugfixes
77

88
New in 0.3.3
Collapse file

‎src/manifest.json‎

Copy file name to clipboardExpand all lines: src/manifest.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"https://startpage.com/*",
2222
"https://www.startpage.com/*",
2323
"https://www.youtube.com/*",
24-
"https://scholar.google.com/*"
24+
"https://scholar.google.com/*",
25+
"https://www.amazon.com/*"
2526
],
2627
"options_page": "options_page.html",
2728
"options_ui": {
Collapse file

‎src/options_page.html‎

Copy file name to clipboardExpand all lines: src/options_page.html
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,18 @@ <h3>Google specific settings</h3>
3939
</div>
4040
</div>
4141
<div id="search-engines-container">
42-
<h3>Alternative search engines</h3>
42+
<h3>EXPERIMENTAL: Alternative search engines</h3>
4343
<div class="option">
44-
<input type="checkbox" id="startpage" name="startpage">Add Startpage</input>
45-
<input type="checkbox" id="youtube" name="youtube">Add Youtube</input>
46-
<input type="checkbox" id="google-scholar" name="google-scholar">Add Google Scholar</input>
44+
<input type="checkbox" id="startpage" name="startpage"> Add Startpage</input>
45+
</div>
46+
<div class="option">
47+
<input type="checkbox" id="youtube" name="youtube"> Add Youtube</input>
48+
</div>
49+
<div class="option">
50+
<input type="checkbox" id="google-scholar" name="google-scholar"> Add Google Scholar</input>
51+
</div>
52+
<div class="option">
53+
<input type="checkbox" id="amazon" name="amazon"> Add Amazon</input>
4754
</div>
4855
</div>
4956
<div id="keybindings-container">
Collapse file

‎src/options_page.js‎

Copy file name to clipboardExpand all lines: src/options_page.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const OPTIONAL_PERMISSIONS_URLS = {
1414
'https://www.youtube.com/*',
1515
],
1616
'google-scholar': ['https://scholar.google.com/*'],
17+
'amazon': [
18+
'https://www.amazon.com/*',
19+
// TODO: Add other Amazon domains (UK etc).
20+
],
1721
};
1822

1923
const DIV_TO_OPTION_NAME = {
@@ -58,6 +62,10 @@ class OptionsPageManager {
5862
googleScholar.addEventListener('change', () => {
5963
this.setSearchEnginePermission(googleScholar);
6064
});
65+
const amazon = document.getElementById('amazon');
66+
amazon.addEventListener('change', () => {
67+
this.setSearchEnginePermission(amazon);
68+
});
6169
// NOTE: this.saveOptions cannot be passed directly or otherwise `this`
6270
// won't be bound to the object.
6371
document.getElementById('save').addEventListener('click', () => {
@@ -82,6 +90,8 @@ class OptionsPageManager {
8290
'youtube').checked;
8391
options.searchEngines.googleScholar = document.getElementById(
8492
'google-scholar').checked;
93+
options.searchEngines.amazon = document.getElementById(
94+
'amazon').checked;
8595
// Handle keybinding options
8696
for (const [key, optName] of Object.entries(DIV_TO_OPTION_NAME)) {
8797
// Options take commands as strings separated by commas.
@@ -138,6 +148,10 @@ class OptionsPageManager {
138148
(url) => {
139149
return permissions.origins.includes(url);
140150
});
151+
const amazon = document.getElementById('amazon');
152+
amazon.checked = OPTIONAL_PERMISSIONS_URLS['amazon'].every((url) => {
153+
return permissions.origins.includes(url);
154+
});
141155
}
142156

143157
/**
Collapse file

‎src/search_engines.js‎

Copy file name to clipboardExpand all lines: src/search_engines.js
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,47 @@ class GoogleScholar {
484484
}
485485
}
486486

487+
class Amazon {
488+
constructor(options) {
489+
this.options = options;
490+
}
491+
get urlPattern() {
492+
return /(www\.)?amazon\.com\/s\?/;
493+
}
494+
get searchBoxSelector() {
495+
return '#twotabsearchtextbox';
496+
}
497+
498+
getSearchResults() {
499+
const includedElements = [
500+
{
501+
nodes: document.querySelectorAll(
502+
'.s-search-results h2 .a-link-normal.a-text-normal'),
503+
highlightClass: 'amazon-focused-search-result',
504+
// containerSelector: (n) => n.closest('.sg-row').parentElement.closest('.sg-row')
505+
},
506+
{
507+
nodes: document.querySelectorAll('.a-pagination a'),
508+
highlightClass: 'amazon-focused-search-result',
509+
},
510+
];
511+
return getSortedSearchResults(includedElements, []);
512+
}
513+
514+
get tabs() {
515+
const pagesTabs = {
516+
navigateNextResultPage:
517+
document.querySelector('.a-pagination .a-last a'),
518+
};
519+
const paginationContainer = document.querySelector('.a-pagination');
520+
if (paginationContainer && paginationContainer.children[0] && !paginationContainer.children[0].classList.contains('a-normal')) {
521+
pagesTabs.navigatePreviousResultPage =
522+
paginationContainer.children[0].querySelector('a');
523+
}
524+
return pagesTabs;
525+
}
526+
}
527+
487528
// Get search engine object matching the current url
488529
/* eslint-disable-next-line no-unused-vars */
489530
const getSearchEngine = (options) => {
@@ -492,6 +533,7 @@ const getSearchEngine = (options) => {
492533
new StartPage(options),
493534
new Youtube(options),
494535
new GoogleScholar(options),
536+
new Amazon(options),
495537
];
496538
// Switch over all compatible search engines
497539
const href = window.location.href;
Collapse file

‎src/search_results.css‎

Copy file name to clipboardExpand all lines: src/search_results.css
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
position: absolute;
66
}
77

8-
.google-focused-card {
8+
.google-focused-card,
9+
.google-scholar-next-page,
10+
.amazon-focused-search-result {
911
/* NOTE: Without !important the style is overridden by Google stylesheets */
1012
border: 1px solid black!important;
1113
}
@@ -28,7 +30,3 @@
2830
.no-outline:focus {
2931
outline: none;
3032
}
31-
32-
.google-scholar-next-page {
33-
border: 1px solid black!important;
34-
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.