-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamznshipwarn.js
125 lines (114 loc) · 4.75 KB
/
amznshipwarn.js
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
// @ts-check
/**
* This extension is created by Alexander Voglsperger (MrMinemeet) and is licensed under the MIT License.
* See LICENSE file for more information or visit https://github.com/MrMinemeet/AmznShipWarn/blob/main/LICENSE
*/
console.info("Amazon Shipping Warning Extension loaded");
if (0 < document.getElementsByClassName("amzhshipwarn").length) {
console.info("Amzshipwarn content on page detected. Extension possibly already loaded. Exiting…");
} else {
init();
}
/**
* Checks for non-Amazon offers and adds a warning to the page if any are found
* @returns {void}
*/
function init() {
if (!isNonAmazonFulfillment()) {
console.info("No non-amazon offers found");
return;
}
console.info("Non-Amazon offers found! Adding warning to page");
// Insert warning in seller/shipment/… info box
const expanderContent = document.getElementsByClassName("offer-display-features-container")[0];
if (expanderContent) {
// Display warning
const warningElement = document.createElement("div");
warningElement.className = "amzhshipwarn";
warningElement.id = "non-amazon-warning";
warningElement.style.backgroundColor = "#ff0000";
warningElement.style.color = "#ffffff";
warningElement.style.padding = "5px";
warningElement.style.margin = "5px";
warningElement.style.borderRadius = "5px";
const warningText = `⚠️ ${getWarning()}`;
warningElement.innerText = warningText;
warningElement.title = warningText;
expanderContent.parentElement?.insertBefore(warningElement, expanderContent);
} else {
console.warn("Offer box not found. Failed to add warning message")
}
// Add warning symbols to "Buy now" and "Add to cart" buttons
const addToCartButton = document.getElementById("submit.add-to-cart");
if (addToCartButton) {
addToCartButton.textContent = `📦🚨 ${addToCartButton.textContent}`;;
} else {
console.warn("'Add to cart' button not found. Not able to add warning symbol");
}
const buyNowButton = document.getElementById("submit.buy-now");
if (buyNowButton) {
buyNowButton.textContent = `📦🚨 ${buyNowButton.textContent}`;
} else {
console.warn("'Buy now button' not found. Not able to add warning symbol");
}
}
/**
* Checks wether the item on the current page is fulfilled by some non-amazon seller
* @returns {boolean} True if non-amazon offer is found
*/
function isNonAmazonFulfillment() {
// Get element of class "offer-display-feature" and "offer-display-feature-name=*fulfiller-info"
const offerTextElementsArray = Array.from(document.getElementsByClassName("offer-display-feature-text-message"));
// Check if the inner-html for any non-amazon "Sending" offers
if (offerTextElementsArray.length === 0) {
console.error("No offer text found! Cannot determine if non-amazon offer");
return false;
}
if (offerTextElementsArray.some((element) =>
element.tagName === "SPAN" && // Message is in a span element
!element.innerText.toLowerCase().includes("amazon") && // Sender should not be amauon
element.parentElement?.parentElement?.parentElement?.id.toLowerCase().includes("fulfillerinfo") // should have parent with "fulfillerInfo" in id
)) {
return true;
}
// When logged in on the mobile view, then the "seller and fulfiller" info may be combined into one line
console.debug("No non-amazon offer found in traditonal layout! Checking combined 'sold and fulfiled' layout");
// "fulfillerInfoFeature_feature_div" has to have no children
if (document.getElementById("fulfillerInfoFeature_feature_div")?.childElementCount === 0) {
return offerTextElementsArray.some((element) =>
element.tagName === "SPAN" && // Message is in a span element
!element.innerText.toLowerCase().includes("amazon") && // Sender should not be amauon
element.parentElement?.parentElement?.parentElement?.id.toLowerCase().includes("merchantinfofeature") // should have parent with "merchantInfoFeature" in id
);
}
return false;
}
/**
* Returns the warning message based on the current hostname
* @returns {string} Warning message
*/
function getWarning() {
switch (window.location.hostname.replace("www.", "").replace("amazon.", "")) {
case "de":
return "Dieses Produkt wird nicht von Amazon versendet";
case "fr":
return "Ce produit n'est pas expédié par Amazon";
case "it":
return "Questo prodotto non è spedito da Amazon";
case "es":
case "com.mx":
return "Este producto no es enviado por Amazon";
case "nl":
return "Dit product wordt niet verzonden door Amazon";
case "com.tr":
return "Bu ürün Amazon tarafından gönderilmemektedir";
case "com.br":
return "Este produto não é enviado pela Amazon";
case "co.jp":
return "この商品はAmazonが発送していません";
case "cn":
return "此产品不由亚马逊发货";
default:
return "This product is not shipped by Amazon";
}
}