-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmazonProductCopier.js
More file actions
225 lines (200 loc) · 9.91 KB
/
AmazonProductCopier.js
File metadata and controls
225 lines (200 loc) · 9.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// ==UserScript==
// @name Amazon Product Copier
// @description Copies Amazon product information to the clipboard with the press of a button.
// @author Tim Macy
// @license AGPL-3.0-or-later
// @version 1.2.3
// @namespace TimMacy.AmazonProductCopier
// @include /^https:\/\/www\.amazon\..+?\/.*/
// @icon https://www.google.com/s2/favicons?sz=64&domain=amazon.com
// @run-at document-end
// @noframes
// @homepageURL https://github.com/TimMacy/AmazonProductCopier
// @supportURL https://github.com/TimMacy/AmazonProductCopier/issues
// @updateURL https://raw.githubusercontent.com/TimMacy/AmazonProductCopier/main/AmazonProductCopier.js
// @downloadURL https://raw.githubusercontent.com/TimMacy/AmazonProductCopier/main/AmazonProductCopier.js
// ==/UserScript==
/************************************************************************
* *
* Copyright © 2026 Tim Macy *
* GNU Affero General Public License v3.0 *
* Version: 1.2.3 - Amazon Product Copier *
* *
* Visit: https://github.com/TimMacy *
* *
************************************************************************/
(async function () {
'use strict';
// CSS
const styleSheet = document.createElement('style');
styleSheet.textContent = `
#amazonCopierBtn {
position: fixed;
left: 20px;
bottom: 20px;
z-index: 9999;
padding: 4px 8px;
margin-left: 8px;
font-size: 12px;
font-weight: 500;
cursor: pointer;
border-radius: 2px;
border: 1px solid #a88734;
background: var(--__dChw-LmGoMXsPxT,#ffd814);
color: var(--__dChw-LmGoMXsw4B,#0f1111);
}
#amazonCopierBtn:hover {
background: var(--__dChw-LmGofIsPxT,#ffce12);
}
.CentAnni-force-visibility .a-expander-borderless .a-section-expander-inner,
.CentAnni-force-visibility #productDetails_feature_div div.a-expander-content,
.CentAnni-force-visibility #voyagerAccordian_feature_div .a-section-expander-inner,
.CentAnni-force-visibility #cr-product-insights-cards div[id^="aspect-bottom-sheet-"],
.CentAnni-force-visibility #productDetailsWithModules_feature_div div.a-expander-content,
.CentAnni-force-visibility #centerCol #nutritionalInfoAndIngredients_feature_div div.a-expander-content.a-expander-section-content,
.CentAnni-force-visibility div#productDescription_feature_div div[data-a-expander-name="toggle_description"] div.a-expander-content.a-expander-extend-content {
display: block !important;
}
.CentAnni-force-visibility #reviewsMedley [data-testid="bottomsheet-box"] [id^="rh_controls_aspect_"] {
display: flex !important;
}
.CentAnni-force-visibility div#productOverview_feature_div span.a-expander-prompt,
.CentAnni-force-visibility div#productDescription_feature_div span.a-expander-prompt {
display: none;
}
.CentAnni-overlay {
position: fixed;
display: flex;
z-index: 2053;
left: 0;
top: 0;
width: 100%;
height: 100%;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, .5);
backdrop-filter: blur(5px);
}
.CentAnni-notification {
background: hsl(0, 0%, 7%);
padding: 20px 30px;
border-radius: 8px;
border: 1px solid hsl(0, 0%, 18.82%);
max-width: 80%;
text-align: center;
font-family: -apple-system, "Roboto", "Arial", sans-serif;
font-size: 16px;
color: white;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
`;
// append css
(document.head
? Promise.resolve(document.head)
: new Promise(resolve => {
document.readyState === 'loading'
? document.addEventListener('DOMContentLoaded', () => resolve(document.head), { once: true })
: resolve(document.head);
})
).then(head => {
if (head)
head.appendChild(styleSheet);
else {
document.documentElement.appendChild(styleSheet);
console.error("AmazonProductCopier: Failed to find head element. Using backup to append stylesheet.");
}
});
// elements to copy
const productTitleSelector = "#productTitle";
const infoSelectors = [
'#social-proofing-faceout-title-tk_bought',
'div[id^="corePriceDisplay_"] > div.aok-relative > span:first-child',
'div[id^="corePriceDisplay_"] > div.a-spacing-small span.aok-offscreen',
'div#productOverview_feature_div',
'div#featurebullets_feature_div',
'div.a-expander-collapsed-height.a-row.a-expander-container.a-spacing-medium.a-expander-partial-collapse-container',
'#centerCol #nutritionalInfoAndIngredients_feature_div',
'.a-cardui.brand-snapshot-card-container',
'#aplus',
'div#productDetails_feature_div',
'div#productDetailsWithModules_feature_div',
'div#importantInformation_feature_div',
'div#productDescription_feature_div:first-child',
'div#detailBulletsWithExceptions_feature_div',
'div#detailBulletsReverseInterleaveContainer_feature_v2',
'#detailBullets2_feature_div',
'#reviewsMedley #averageCustomerReviewsAnchor',
'span[data-hook="rating-out-of-text"]',
'span[data-hook="total-review-count"]',
'#histogramTable',
'#reviewsMedley .cm_cr_grid_center_right div[data-csa-c-item-id="cr-product-insights-cards"] h3',
'#reviewsMedley .cm_cr_grid_center_right #cr-product-insights-cards h3',
'#reviewsMedley h3[data-testid="heading"]',
'#reviewsMedley [data-testid="overall-summary"]',
'#reviewsMedley [data-testid="ai-disclaimer"]',
'#reviewsMedley [data-testid="bottomsheet-box"] [id^="rh_controls_aspect_"]',
'#reviewsMedley .cm_cr_grid_center_right div[data-csa-c-item-id="cr-product-insights-cards"] div[data-testid="overall-summary"]',
'#reviewsMedley .cm_cr_grid_center_right #cr-product-insights-cards #product-summary p.a-spacing-small > span',
'#reviewsMedley .cm_cr_grid_center_right div[data-csa-c-item-id="cr-product-insights-cards"] div[data-testid="ai-disclaimer"] > span:first-child',
'#reviewsMedley .cm_cr_grid_center_right #cr-product-insights-cards #product-summary #summary-disclaimer-title',
'#reviewsMedley .cm_cr_grid_center_right div[data-csa-c-item-id="cr-product-insights-cards"] div[data-csa-c-item-id="cr-product-insights-cards-popover"] div[id^="rh_controls_aspect_"]',
'#reviewsMedley .cm_cr_grid_center_right #cr-product-insights-cards div[data-csa-c-slot-id="cr-product-insights-cards-popover"]'
];
// build content
const buildContent = () => {
const titleNode = document.querySelector(productTitleSelector);
const rawTitle = titleNode?.textContent?.trim();
const title = rawTitle ? rawTitle.replace(/\s+/g, " ") : "";
if (!title) return "";
const rawBlocks = infoSelectors.flatMap(selector => Array.from(document.querySelectorAll(selector))).map(node => node?.innerText?.trim()).filter(text => text && text.length > 0);
const fixedBlocks = rawBlocks.map(block => {
if (!block.includes('5 star') || !block.includes('3 star')) return block;
const lines = block.split('\n').map(line => line.trim()).filter(line => line.length > 0);
if (lines.length % 2 !== 0) return block;
const merged = [];
for (let i = 0; i < lines.length; i += 2) merged.push(lines[i] + ' ' + lines[i + 1]);
return merged.join('\n');
});
const infoText = fixedBlocks.join('\n\n');
if (!infoText) return "";
const header = `<product: ${title}>\n`;
const footer = `\n</product: ${title}>`;
return header + infoText + footer;
};
// copy to clipboard
const copyToClipboard = async () => {
document.body.classList.add("CentAnni-force-visibility");
const payload = buildContent();
if (payload) {
await navigator.clipboard.writeText(payload);
showNotification('Content Copied to Clipboard.');
}
document.body.classList.remove("CentAnni-force-visibility");
};
// function to display the notification
function showNotification(message) {
const overlay = document.createElement('div');
overlay.classList.add('CentAnni-overlay');
const modal = document.createElement('div');
modal.classList.add('CentAnni-notification');
modal.textContent = message;
overlay.appendChild(modal);
document.body.appendChild(overlay);
setTimeout(() => { overlay.remove(); }, 600);
}
// add the button
const addButton = () => {
const titleSection = document.querySelector("#titleSection") || document.querySelector("#buybox");
if (!titleSection || document.querySelector("#amazonCopierBtn")) return;
const btn = document.createElement("button");
btn.id = "amazonCopierBtn";
btn.type = "button";
btn.textContent = "Copy Content";
btn.addEventListener("click", () => { copyToClipboard(); });
document.body.appendChild(btn);
};
document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", addButton, { once: true }) : addButton();
})();