-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleanURL.js
More file actions
26 lines (26 loc) · 1.16 KB
/
Copy pathCleanURL.js
File metadata and controls
26 lines (26 loc) · 1.16 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
javascript:(() => {
const currentURL = window.location.href;
const domain = currentURL.match(/https?:\/\/[a-z0-1-.]*(?<domain>(amazon|ebay|etsy|facebook|youtube)\.[^\/]*)/i).groups.domain;
let cleanURL;
if (domain.includes("amazon")) {
const id = currentURL.match(/(\/(dp|gp\/product(\/glance)?|gp\/aw\/d|exec\/obidos\/asin)\/)(?<id>[a-z0-9]*)/i).groups.id;
cleanURL = `https://${domain}/dp/${id}`;
}
if (domain.includes("ebay")) {
const id = currentURL.match(/(\/itm\/)(?<id>[0-9]*)/i).groups.id;
cleanURL = `https://${domain}/itm/${id}`;
}
if (domain.includes("etsy")) {
const id = currentURL.match(/(\/listing\/)(?<id>[0-9]*)/i).groups.id;
cleanURL = `https://${domain}/listing/${id}`;
}
if (domain.includes("facebook")) {
const id = currentURL.match(/(\/marketplace\/item\/)(?<id>[0-9]*)/i).groups.id;
cleanURL = `https://${domain}/marketplace/item/${id}`;
}
if (domain.includes("youtube")) {
const id = currentURL.match(/(\?v=)(?<id>[a-z0-9-_]*)/i).groups.id;
cleanURL = `https://youtu.be/${id}`;
}
navigator.clipboard.writeText(cleanURL);
})();