Skip to content

Commit 8ac8984

Browse files
committed
[userscript] amazon-prime-gaming-highlighter: fix collectClaimUrls to match urls even when button uses an onClick handler rather than href
1 parent 6755bf1 commit 8ac8984

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

userscripts/amazon-prime-gaming-highlighter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// @supportURL https://github.com/0xdevalias/userscripts/issues
1010
// @downloadURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/amazon-prime-gaming-highlighter/amazon-prime-gaming-highlighter.user.js
1111
// @namespace https://www.devalias.net/
12-
// @version 1.0.6
12+
// @version 1.0.7
1313
// @match https://gaming.amazon.com/home
1414
// @grant GM_openInTab
1515
// ==/UserScript==

userscripts/amazon-prime-gaming-highlighter/amazon-prime-gaming-highlighter.user.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// @supportURL https://github.com/0xdevalias/userscripts/issues
77
// @downloadURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/amazon-prime-gaming-highlighter/amazon-prime-gaming-highlighter.user.js
88
// @namespace https://www.devalias.net/
9-
// @version 1.0.6
9+
// @version 1.0.7
1010
// @match https://gaming.amazon.com/home
1111
// @grant GM_openInTab
1212
// ==/UserScript==
@@ -154,6 +154,12 @@
154154
return Array.from(document.querySelectorAll(sectionCardsSelector));
155155
}
156156

157+
function getBlocksInSection(section) {
158+
const sectionBlocksSelector = `div[data-a-target="${section}"] .offer-list__content__grid > .tw-block, div[data-a-target="${section}"] .grid-carousel__slide > .tw-block`;
159+
160+
return Array.from(document.querySelectorAll(sectionBlocksSelector));
161+
}
162+
157163
function getTitleForCard({ card, section }) {
158164
if (sectionsWithTitleInHeading.includes(section)) {
159165
return card.querySelector(
@@ -214,13 +220,36 @@
214220
}
215221

216222
function collectClaimURLs() {
217-
const claimButtons = new Set(
218-
Array.from(document.querySelectorAll('.item-card__claim-button a[href]'))
219-
.map((button) => button.href)
220-
.filter((url) => !url.includes('/web-games/')),
221-
);
223+
const uniqueClaimURLs = new Set();
224+
225+
sectionsToMatch.forEach((section) => {
226+
if (sectionsToIgnore.includes(section)) {
227+
DEBUG && console.log(`[APGH] Skipping claim URL for ignored section=${section}`);
228+
return;
229+
}
230+
231+
getBlocksInSection(section).forEach((sectionBlock) => {
232+
if (isItemCollected(sectionBlock)) {
233+
DEBUG && console.log(`[APGH] Skipping claim URL for collected item for section=${section}`);
234+
return;
235+
}
236+
237+
Array.from(
238+
new Set(
239+
Array.from(sectionBlock.querySelectorAll('[data-a-target="learn-more-card"]'))
240+
.map(el => el.href)
241+
.filter((url) => !url.includes('/web-games/'))
242+
.map(href => href.replace('/details', ''))
243+
)
244+
).forEach(url => {
245+
DEBUG && console.log(`[APGH] Found claim URL: ${url}`);
246+
247+
uniqueClaimURLs.add(url)
248+
});
249+
});
250+
});
222251

223-
return Array.from(claimButtons);
252+
return Array.from(uniqueClaimURLs);
224253
}
225254

226255
function copyURLsToClipboard(urls) {

0 commit comments

Comments
 (0)