-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
86 lines (70 loc) · 2.98 KB
/
Copy pathscript.js
File metadata and controls
86 lines (70 loc) · 2.98 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
javascript:(function(){ (async () => {
// ----- CONFIG -----
// Set this to the endpoint you are allowed to use.
// DO NOT point this at sellercentral.amazon.de unless you are explicitly authorized
// and you understand Amazon's rules and authentication requirements.
const apiUrl = "https://sellercentral.amazon.de/aplus/api/ArchiveContent"; // << replace with your authorized endpoint
// Optional: set an Authorization header if you have a bearer token for your own API.
// const authHeader = "Bearer YOUR_TOKEN_HERE"; // << only use if you are authorized
// Delay between requests (ms)
const delayMs = 500;
// ----- helper functions -----
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
// Extract content IDs from the grid
function getContentIdsFromGrid() {
const container = document.querySelector('.ag-center-cols-container');
if (!container) {
console.warn('Container not found.');
return [];
}
const katLinks = container.querySelectorAll('kat-link');
const ids = Array.from(katLinks)
.map(link => link.getAttribute('href'))
.filter(Boolean) // remove null/undefined
.filter(href => !href.endsWith('/asins')) // ignore /asins links
.map(href => href.split('/').pop()) // take the last segment
.filter(Boolean); // remove any empty strings
// deduplicate
return Array.from(new Set(ids));
}
// Generic POST helper
async function postProjectId(id) {
const payload = { projectId: id };
try {
const resp = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
// "Authorization": authHeader, // uncomment only if you legitimately have an auth token
},
body: JSON.stringify(payload),
// credentials: 'include' // if you want to include cookies for same-origin requests (use with caution)
});
// Try to parse JSON but handle non-JSON responses gracefully
let body;
try { body = await resp.json(); } catch(e) { body = await resp.text(); }
return { ok: resp.ok, status: resp.status, body };
} catch (err) {
return { ok: false, error: String(err) };
}
}
// ----- Main flow -----
const contentIds = getContentIdsFromGrid();
console.log('Found content IDs:', contentIds);
if (!contentIds.length) {
console.log('No content IDs found — aborting.');
return;
}
// OPTIONAL: Ask user for confirmation in the console before proceeding
// (Uncomment if you want a safety confirmation)
// const proceed = confirm(`Send ${contentIds.length} POST requests to ${apiUrl}?`);
// if (!proceed) { console.log('Aborted by user.'); return; }
for (const id of contentIds) {
console.log(`Posting projectId=${id} ...`);
const result = await postProjectId(id);
console.log(`Result for ${id}:`, result);
// rate limit between requests
await sleep(delayMs);
}
console.log('Done.');
})(); })();