Skip to content

Commit df7eb97

Browse files
committed
[userscript] amazon-prime-gaming-highlighter: add utility buttons to copy claim urls to clipboard and/or to open in new tabs
1 parent 8ab5f69 commit df7eb97

File tree

2 files changed

+138
-4
lines changed

2 files changed

+138
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
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.4
12+
// @version 1.0.5
1313
// @match https://gaming.amazon.com/home
14-
// @grant none
14+
// @grant GM_openInTab
1515
// ==/UserScript==
1616
```
1717

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

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
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.4
9+
// @version 1.0.5
1010
// @match https://gaming.amazon.com/home
11-
// @grant none
11+
// @grant GM_openInTab
1212
// ==/UserScript==
1313

1414
// Amazon Prime Gaming - CSS Selectors / etc: https://gist.github.com/0xdevalias/2d156a148902e31580f247e3d80d38c3
@@ -207,9 +207,143 @@
207207
});
208208
}
209209

210+
function collectClaimURLs() {
211+
const claimButtons = new Set(
212+
Array.from(document.querySelectorAll('.item-card__claim-button a[href]'))
213+
);
214+
215+
return Array.from(claimButtons)
216+
.map(button => button.href)
217+
.filter(url => !url.includes('/web-games/'));
218+
}
219+
220+
function copyURLsToClipboard(urls) {
221+
const tempTextarea = document.createElement("textarea");
222+
tempTextarea.value = urls.join("\n");
223+
document.body.appendChild(tempTextarea);
224+
tempTextarea.select();
225+
document.execCommand("copy");
226+
document.body.removeChild(tempTextarea);
227+
228+
alert("URLs copied to clipboard!");
229+
}
230+
231+
function createUtilityButtons() {
232+
const containerId = "apgh-utility-buttons-container";
233+
234+
// Check if the container already exists
235+
let container = document.getElementById(containerId);
236+
if (container) {
237+
return; // Bail early if the container already exists
238+
}
239+
240+
// Create the main container
241+
container = document.createElement("div");
242+
container.id = containerId;
243+
container.style.position = "fixed";
244+
container.style.bottom = "10px";
245+
container.style.right = "20px";
246+
container.style.zIndex = "1000";
247+
container.style.display = "flex";
248+
container.style.flexDirection = "column";
249+
container.style.alignItems = "flex-end"; // Align everything to the right
250+
container.style.backgroundColor = "transparent";
251+
container.style.gap = "10px";
252+
253+
let isExpanded = true; // Start expanded
254+
255+
// Create a flex container for the toggle button
256+
const toggleContainer = document.createElement("div");
257+
toggleContainer.style.display = "flex";
258+
toggleContainer.style.justifyContent = "flex-end"; // Keep the toggle button right-aligned
259+
toggleContainer.style.width = "100%";
260+
261+
// Create the toggle button
262+
const toggleButton = document.createElement("button");
263+
toggleButton.textContent = "⚙️"; // Toggle button without up/down icons
264+
toggleButton.style.width = "40px";
265+
toggleButton.style.height = "40px";
266+
toggleButton.style.border = "none";
267+
toggleButton.style.borderRadius = "50%";
268+
toggleButton.style.backgroundColor = "#0073e6";
269+
toggleButton.style.color = "#fff";
270+
toggleButton.style.fontSize = "16px";
271+
toggleButton.style.cursor = "pointer";
272+
toggleButton.style.display = "flex";
273+
toggleButton.style.alignItems = "center";
274+
toggleButton.style.justifyContent = "center";
275+
toggleButton.style.boxShadow = "0 2px 5px rgba(0, 0, 0, 0.1)";
276+
toggleButton.style.transition = "background-color 0.3s ease";
277+
278+
toggleButton.onmouseenter = () => (toggleButton.style.backgroundColor = "#005bb5");
279+
toggleButton.onmouseleave = () => (toggleButton.style.backgroundColor = "#0073e6");
280+
281+
toggleButton.onclick = () => {
282+
isExpanded = !isExpanded;
283+
updateContainerVisibility();
284+
};
285+
286+
// Append the toggle button to its container
287+
toggleContainer.appendChild(toggleButton);
288+
289+
const createButton = (text, onClick) => {
290+
const button = document.createElement("button");
291+
button.textContent = text;
292+
button.style.padding = "10px 15px";
293+
button.style.fontSize = "14px";
294+
button.style.cursor = "pointer";
295+
button.style.border = "1px solid #0073e6";
296+
button.style.borderRadius = "5px";
297+
button.style.backgroundColor = "#0073e6";
298+
button.style.color = "#fff";
299+
button.style.boxShadow = "0 2px 5px rgba(0, 0, 0, 0.1)";
300+
button.style.transition = "background-color 0.3s ease";
301+
302+
button.onmouseenter = () => (button.style.backgroundColor = "#005bb5");
303+
button.onmouseleave = () => (button.style.backgroundColor = "#0073e6");
304+
305+
button.onclick = onClick;
306+
return button;
307+
};
308+
309+
const copyButton = createButton("Copy Claim URLs", () => {
310+
const urls = collectClaimURLs();
311+
copyURLsToClipboard(urls);
312+
});
313+
314+
const openButton = createButton("Open Claim URLs", () => {
315+
const urls = collectClaimURLs();
316+
urls.forEach(url => GM_openInTab(url, { active: false }));
317+
});
318+
319+
const updateContainerVisibility = () => {
320+
if (isExpanded) {
321+
copyButton.style.display = "block";
322+
openButton.style.display = "block";
323+
} else {
324+
copyButton.style.display = "none";
325+
openButton.style.display = "none";
326+
}
327+
};
328+
329+
// Append buttons to the main container
330+
container.appendChild(copyButton);
331+
container.appendChild(openButton);
332+
333+
// Append the toggle container to the main container
334+
container.appendChild(toggleContainer);
335+
336+
// Append the main container to the body
337+
document.body.appendChild(container);
338+
339+
// Initialize visibility
340+
updateContainerVisibility();
341+
}
342+
210343
const observer = new MutationObserver(highlightGames);
211344
observer.observe(document.body, { childList: true, subtree: true });
212345

213346
// Run initial highlighting
214347
highlightGames();
348+
createUtilityButtons();
215349
})();

0 commit comments

Comments
 (0)