Country of origin for Amazon products

userscript to fetch and display the country of origin for amazon products. initially developed to make boycotting the CCP more easy.

目前為 2021-11-27 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Country of origin for Amazon products
  3. // @name:de Herkunftsland für Amazon Produkte
  4. // @name:fr Pays d'origine des produits Amazon
  5. // @name:it Paese di origine per i prodotti Amazon
  6. // @name:es País de origen de los productos de Amazon
  7. // @name:nl Land van herkomst voor Amazon-producten
  8. // @name:sv Ursprungsland för Amazon-produkter
  9. // @name:ja Amazon製品の原産国
  10. // @namespace http://tampermonkey.net/
  11. // @version 2.2.3
  12. // @description userscript to fetch and display the country of origin for amazon products. initially developed to make boycotting the CCP more easy.
  13. // @description:de Userscript zum Abrufen und Anzeigen des Herkunftslandes von Amazon-Produkten. ursprünglich entwickelt, um den Boykott der KPC zu erleichtern.
  14. // @description:fr userscript pour récupérer et afficher le pays d'origine des produits amazon. initialement développé pour faciliter le boycott du PCC.
  15. // @description:it userscript per recuperare e visualizzare il paese di origine dei prodotti Amazon. inizialmente sviluppato per rendere più facile il boicottaggio del PCC.
  16. // @description:es usercript para buscar y mostrar el país de origen de los productos de Amazon. inicialmente desarrollado para facilitar el boicot al PCCh.
  17. // @description:nl userscript om het land van herkomst voor Amazon-producten op te halen en weer te geven. oorspronkelijk ontwikkeld om het boycotten van de CCP gemakkelijker te maken.
  18. // @description:sv användarskript för att hämta och visa ursprungslandet för Amazon-produkter. ursprungligen utvecklad för att göra det lättare att bojkotta KKP.
  19. // @description:ja アマゾン製品の原産国を取得して表示するためのユーザースクリプト。 当初はCCPのボイコットをより簡単にするために開発されました。
  20. // @author Sidem, calne_ca
  21. // @license GPL-3.0-only
  22. // @match https://www.amazon.de/*
  23. // @match https://www.amazon.fr/*
  24. // @match https://www.amazon.it/*
  25. // @match https://www.amazon.es/*
  26. // @match https://www.amazon.nl/*
  27. // @match https://www.amazon.se/*
  28. // @match https://www.amazon.com/*
  29. // @match https://www.amazon.co.jp/*
  30. // @match https://www.amazon.co.uk/*
  31. // @match https://www.amazon.com.mx/*
  32. // @match https://www.amazon.com.au/*
  33. // @contributionURL https://cointr.ee/sidem
  34. // @grant none
  35. // ==/UserScript==
  36. /* jshint esversion: 6 */
  37.  
  38. (function () {
  39. 'use strict';
  40.  
  41. let countryCodes = {
  42. "AF": "Afghanistan", "AL": "Albania", "DZ": "Algeria", "AS": "American Samoa", "AD": "Andorra", "AO": "Angola", "AI": "Anguilla", "AQ": "Antarctica", "AG": "Antigua and Barbuda", "AR": "Argentina", "AM": "Armenia", "AW": "Aruba", "AU": "Australia", "AT": "Austria", "AZ": "Azerbaijan", "BS": "Bahamas", "BH": "Bahrain", "BD": "Bangladesh", "BB": "Barbados", "BY": "Belarus", "BE": "Belgium", "BZ": "Belize", "BJ": "Benin", "BM": "Bermuda", "BT": "Bhutan", "BO": "Bolivia", "BA": "Bosnia and Herzegovina", "BW": "Botswana", "BV": "Bouvet Island", "BR": "Brazil", "IO": "British Indian Ocean Territory", "BN": "Brunei Darussalam", "BG": "Bulgaria", "BF": "Burkina Faso", "BI": "Burundi", "KH": "Cambodia", "CM": "Cameroon", "CA": "Canada", "CV": "Cape Verde", "KY": "Cayman Islands", "CF": "Central African Republic", "TD": "Chad", "CL": "Chile", "CN": "China", "CX": "Christmas Island", "CC": "Cocos (Keeling) Islands", "CO": "Colombia", "KM": "Comoros", "CG": "Congo", "CD": "Congo, the Democratic Republic of the", "CK": "Cook Islands", "CR": "Costa Rica", "CI": "Cote D'Ivoire", "HR": "Croatia", "CU": "Cuba", "CY": "Cyprus", "CZ": "Czech Republic", "DK": "Denmark", "DJ": "Djibouti", "DM": "Dominica", "DO": "Dominican Republic", "EC": "Ecuador", "EG": "Egypt", "SV": "El Salvador", "GQ": "Equatorial Guinea", "ER": "Eritrea", "EE": "Estonia", "ET": "Ethiopia", "FK": "Falkland Islands (Malvinas)", "FO": "Faroe Islands", "FJ": "Fiji", "FI": "Finland", "FR": "France", "GF": "French Guiana", "PF": "French Polynesia", "TF": "French Southern Territories", "GA": "Gabon", "GM": "Gambia", "GE": "Georgia", "DE": "Germany", "GH": "Ghana", "GI": "Gibraltar", "GR": "Greece", "GL": "Greenland", "GD": "Grenada", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", "GN": "Guinea", "GW": "Guinea-Bissau", "GY": "Guyana", "HT": "Haiti", "HM": "Heard Island and McDonald Islands", "VA": "Holy See (Vatican City State)", "HN": "Honduras", "HK": "Hong Kong", "HU": "Hungary", "IS": "Iceland", "IN": "India", "ID": "Indonesia", "IR": "Iran, Islamic Republic of", "IQ": "Iraq", "IE": "Ireland", "IL": "Israel", "IT": "Italy", "JM": "Jamaica", "JP": "Japan", "JO": "Jordan", "KZ": "Kazakhstan", "KE": "Kenya", "KI": "Kiribati", "KP": "North Korea", "KR": "South Korea", "KW": "Kuwait", "KG": "Kyrgyzstan", "LA": "Lao People's Democratic Republic", "LV": "Latvia", "LB": "Lebanon", "LS": "Lesotho", "LR": "Liberia", "LY": "Libya", "LI": "Liechtenstein", "LT": "Lithuania", "LU": "Luxembourg", "MO": "Macao", "MG": "Madagascar", "MW": "Malawi", "MY": "Malaysia", "MV": "Maldives", "ML": "Mali", "MT": "Malta", "MH": "Marshall Islands", "MQ": "Martinique", "MR": "Mauritania", "MU": "Mauritius", "YT": "Mayotte", "MX": "Mexico", "FM": "Micronesia, Federated States of", "MD": "Moldova, Republic of", "MC": "Monaco", "MN": "Mongolia", "MS": "Montserrat", "MA": "Morocco", "MZ": "Mozambique", "MM": "Myanmar", "NA": "Namibia", "NR": "Nauru", "NP": "Nepal", "NL": "Netherlands", "NC": "New Caledonia", "NZ": "New Zealand", "NI": "Nicaragua", "NE": "Niger", "NG": "Nigeria", "NU": "Niue", "NF": "Norfolk Island", "MK": "North Macedonia, Republic of", "MP": "Northern Mariana Islands", "NO": "Norway", "OM": "Oman", "PK": "Pakistan", "PW": "Palau", "PS": "Palestinian Territory, Occupied", "PA": "Panama", "PG": "Papua New Guinea", "PY": "Paraguay", "PE": "Peru", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PT": "Portugal", "PR": "Puerto Rico", "QA": "Qatar", "RE": "Reunion", "RO": "Romania", "RU": "Russia", "RW": "Rwanda", "SH": "Saint Helena", "KN": "Saint Kitts and Nevis", "LC": "Saint Lucia", "PM": "Saint Pierre and Miquelon", "VC": "Saint Vincent and the Grenadines", "WS": "Samoa", "SM": "San Marino", "ST": "Sao Tome and Principe", "SA": "Saudi Arabia", "SN": "Senegal", "SC": "Seychelles", "SL": "Sierra Leone", "SG": "Singapore", "SK": "Slovakia", "SI": "Slovenia", "SB": "Solomon Islands", "SO": "Somalia", "ZA": "South Africa", "GS": "South Georgia and the South Sandwich Islands", "ES": "Spain", "LK": "Sri Lanka", "SD": "Sudan", "SR": "Suriname", "SJ": "Svalbard and Jan Mayen", "SZ": "Eswatini", "SE": "Sweden", "CH": "Switzerland", "SY": "Syrian Arab Republic", "TW": "Taiwan", "TJ": "Tajikistan", "TZ": "Tanzania, United Republic of", "TH": "Thailand", "TL": "Timor-Leste", "TG": "Togo", "TK": "Tokelau", "TO": "Tonga", "TT": "Trinidad and Tobago", "TN": "Tunisia", "TR": "Turkey", "TM": "Turkmenistan", "TC": "Turks and Caicos Islands", "TV": "Tuvalu", "UG": "Uganda", "UA": "Ukraine", "AE": "United Arab Emirates", "GB": "UK", "US": "USA", "UM": "United States Minor Outlying Islands", "UY": "Uruguay", "UZ": "Uzbekistan", "VU": "Vanuatu", "VE": "Venezuela", "VN": "Vietnam", "VG": "Virgin Islands, British", "VI": "Virgin Islands, U.S.", "WF": "Wallis and Futuna", "EH": "Western Sahara", "YE": "Yemen", "ZM": "Zambia", "ZW": "Zimbabwe", "AX": "Åland Islands", "BQ": "Bonaire, Sint Eustatius and Saba", "CW": "Curaçao", "GG": "Guernsey", "IM": "Isle of Man", "JE": "Jersey", "ME": "Montenegro", "BL": "Saint Barthélemy", "MF": "Saint Martin (French part)", "RS": "Serbia", "SX": "Sint Maarten (Dutch part)", "SS": "South Sudan", "XK": "Kosovo"
  43. };
  44.  
  45. var applyLogoSprite = function () {
  46. let amazonLogo = document.getElementById("amazonOriginalProduct");
  47. if (amazonLogo != null) {
  48. amazonLogo.style.objectFit = "none";
  49. amazonLogo.style.objectPosition = "-2px -71px";
  50. amazonLogo.style.width = "55px";
  51. amazonLogo.style.height = "28px";
  52. }
  53. }
  54.  
  55. var codeToFlag = function (isoCode, countryName, sellerName) {
  56. if (sellerName.includes("Amazon")) {
  57. return "<img class='countryOfOriginFlag' id='amazonOriginalProduct' src='https://m.media-amazon.com/images/G/01/AUIClients/AmazonUIIcon-beacon_light_1x-2767b239bb9543c0a4af44c843ab017f27080532._V2_.png' alt='" + sellerName + "' title='" + sellerName + "'>";
  58. } else if (isoCode != "") {
  59. return "<img class='countryOfOriginFlag' src='https://flagcdn.com/w40/" + isoCode.toLowerCase() + ".png' alt='" + countryName + ", " + sellerName + "' title='" + countryName + ", " + sellerName + "'>";
  60. } else {
  61. return "";
  62. }
  63.  
  64. };
  65. var stringToHTML = function (str) {
  66. var parser = new DOMParser();
  67. var doc = parser.parseFromString(str, 'text/html');
  68. return doc;
  69. };
  70.  
  71. function runCountryFetch() {
  72. document.getElementById("productTitle").innerHTML = "<img src='https://images-eu.ssl-images-amazon.com/images/G/03/javascripts/lib/popover/images/snake._CB485935607_.gif' width='25' height='25'> " + document.getElementById("productTitle").innerText;
  73.  
  74. let thirdPartySeller = document.getElementById('sellerProfileTriggerId');
  75. if (thirdPartySeller == null) {
  76. let siteLinks = document.getElementsByClassName("a-link-normal");
  77. for (let link of siteLinks) {
  78. if (link.href.endsWith("ref=dp_merchant_link")) {
  79. thirdPartySeller = link;
  80. }
  81. }
  82. }
  83.  
  84. if (thirdPartySeller != null) {
  85. let sellerPage = thirdPartySeller.href;
  86.  
  87. fetch(sellerPage)
  88. .then(function (response) {
  89. switch (response.status) {
  90. case 200:
  91. return response.text();
  92. case 404:
  93. throw response;
  94. }
  95. })
  96. .then(function (template) {
  97. let sellerPageDOM = stringToHTML(template);
  98. let items = sellerPageDOM.getElementsByClassName("a-list-item");
  99. let sellerName = sellerPageDOM.getElementById("sellerName").innerText;
  100. let originCountry = "";
  101. let originCountryCode = "";
  102. let isChina = false;
  103. for (let i of items) {
  104. if (countryCodes.hasOwnProperty(i.innerText)) {
  105. originCountryCode = i.innerText;
  106. originCountry = countryCodes[i.innerText];
  107. if (originCountryCode == "CN") isChina = true;
  108. }
  109. }
  110. if (isChina) originCountry = "☠ " + originCountry + " ☠";
  111. document.getElementById("productTitle").innerHTML = codeToFlag(originCountryCode, originCountry, sellerName) + " " + document.getElementById("productTitle").innerText;
  112. })
  113. .catch(function (response) {
  114. console.log(response);
  115. })
  116. .finally(function (response) {
  117. applyLogoSprite();
  118. });
  119. } else {
  120. document.getElementById("productTitle").innerHTML = codeToFlag("", "", "Amazon") + " " + document.getElementById("productTitle").innerText;
  121. applyLogoSprite();
  122. }
  123. }
  124. let priceBox = document.getElementById('corePrice_desktop');
  125. const observer = new MutationObserver(function (mutation) {
  126. if(mutation[0].target.id.includes('deal_expiry_timer')) {
  127. runCountryFetch();
  128. }
  129. });
  130. observer.observe(priceBox, { subtree: true, childList: true });
  131. runCountryFetch();
  132.  
  133. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址