Greasy Fork is available in English.

Amazon URL Shortener

Adds a button to copy the short link of Amazon products and optionally modifies the URL in the address bar

  1. // ==UserScript==
  2. // @name Amazon URL Shortener
  3. // @namespace https://github.com/Leproide/Amazon_URLShortener/
  4. // @version 1.6.4
  5. // @description:en Adds a button to copy the short link of Amazon products and optionally modifies the URL in the address bar
  6. // @description:it Aggiunge un pulsante per copiare il link corto dei prodotti Amazon, opzionalmente modifica l'URL nella barra degli indirizzi.
  7. // @author Leproide
  8. // @include *://*.amazon.*/*
  9. // @include https://*.amazon.co.jp/*
  10. // @include https://*.amazon.com/*
  11. // @include https://*.amazon.ae/*
  12. // @include https://*.amazon.co.uk/*
  13. // @include https://*.amazon.it/*
  14. // @include https://*.amazon.in/*
  15. // @include https://*.amazon.eg/*
  16. // @include https://*.amazon.com.au/*
  17. // @include https://*.amazon.nl/*
  18. // @include https://*.amazon.ca/*
  19. // @include https://*.amazon.sa/*
  20. // @include https://*.amazon.sg/*
  21. // @include https://*.amazon.se/*
  22. // @include https://*.amazon.de/*
  23. // @include https://*.amazon.com.tr/*
  24. // @include https://*.amazon.com.br/*
  25. // @include https://*.amazon.fr/*
  26. // @include https://*.amazon.com.be/*
  27. // @include https://*.amazon.pl/*
  28. // @include https://*.amazon.com.mx/*
  29. // @include https://*.amazon.cn/*
  30. // @icon data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAAGYktHRAD/AP8A/6C9p5MAAAAJcEhZcwAADhYAAA4WAXnTFKIAAAAHdElNRQfpAQkOHxxuMvkLAAAJG0lEQVR42s3beYxdZRnH8c+dpRu0lVKogGGnLRQoWBBsKbJIgopGFGMhNRHUGGUPFFA0CmJEVEACEVmKYbMQjIYl1qhAqCBQtkIrWsACRqRSWrtNt5m5/vGce3vmdOaec9o7nXmSm/TeOe/y/Z13eZ7nfVsxCK16wYzsT7tjOk7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DA6MDAxmEkSAAAAEnRFWHRleGlmOkV4aWZPZmZzZXQAMjZTG6JlAAAAJnRFWHRleGlmOlVzZXJDb21tZW50AC4uLi4uLi4uVmVyc2lvbiAxLjAuMPyZPSEAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC
  31. // @license GPL v2
  32. // @description Adds a button to copy the short link of Amazon products and optionally modifies the URL in the address bar
  33. // ==/UserScript==
  34.  
  35. (function () {
  36. 'use strict';
  37.  
  38. // Configuration: Enable or disable features
  39. const enableButton = true; // true to add the copy button, false to disable it
  40. const modifyUrl = true; // true to modify the browser URL, false to leave it unchanged
  41. const popupDuration = 1500; // Popup duration in milliseconds (1.5 seconds)
  42.  
  43. // Function to generate the short link
  44. function generateShortLink() {
  45. const currentUrl = window.location.href;
  46. let match = currentUrl.match(/\/dp\/([A-Z0-9]{10})/); // Find the ASIN in /dp/
  47. if (!match) {
  48. match = currentUrl.match(/\/gp\/product\/([A-Z0-9]{10})/); // Find the ASIN in /gp/product/
  49. if (match) {
  50. return `${window.location.origin}/dp/${match[1]}`;
  51. }
  52. } else {
  53. return `${window.location.origin}/dp/${match[1]}`;
  54. }
  55. return null;
  56. }
  57.  
  58. // Function to copy text to clipboard
  59. function copyToClipboard(text) {
  60. const tempInput = document.createElement('input');
  61. document.body.appendChild(tempInput);
  62. tempInput.value = text;
  63. tempInput.select();
  64. document.execCommand('copy');
  65. document.body.removeChild(tempInput);
  66. showPopup(text);
  67. }
  68.  
  69. // Function to show popup
  70. function showPopup(text) {
  71. const lang = navigator.language || navigator.userLanguage;
  72. const message = lang.startsWith('it') ? 'Link copiato in clipboard' : 'Link copied to clipboard';
  73.  
  74. const popup = document.createElement('div');
  75. const line1 = document.createElement('div');
  76. const line2 = document.createElement('div');
  77.  
  78. // Line 1: "Link copiato"
  79. line1.textContent = message;
  80. line1.style.marginBottom = '8px';
  81. line1.style.fontWeight = 'bold';
  82.  
  83. // Line 2: Short link
  84. line2.textContent = text;
  85. line2.style.wordBreak = 'break-all'; // Prevent text overflow
  86.  
  87. // Popup container
  88. popup.appendChild(line1);
  89. popup.appendChild(line2);
  90. popup.style.position = 'fixed';
  91. popup.style.top = '50%';
  92. popup.style.left = '50%';
  93. popup.style.transform = 'translate(-50%, -50%)';
  94. popup.style.padding = '20px 40px';
  95. popup.style.backgroundColor = '#ffa41c';
  96. popup.style.color = '#111';
  97. popup.style.borderRadius = '12px';
  98. popup.style.fontSize = '16px';
  99. popup.style.textAlign = 'center';
  100. popup.style.boxShadow = '0 8px 15px rgba(0, 0, 0, 0.3)'; // Shadow around the popup
  101. popup.style.zIndex = '9999';
  102. popup.style.opacity = '0'; // Start hidden
  103. popup.style.transition = 'opacity 0.4s'; // Fade effect
  104.  
  105. document.body.appendChild(popup);
  106.  
  107. // Fade in
  108. setTimeout(() => {
  109. popup.style.opacity = '1';
  110. }, 10);
  111.  
  112. // Fade out and remove
  113. setTimeout(() => {
  114. popup.style.opacity = '0';
  115. setTimeout(() => popup.remove(), 400); // Ensure it is removed after fade-out
  116. }, popupDuration);
  117. }
  118.  
  119. // Modify the URL in the address bar if enabled
  120. if (modifyUrl) {
  121. const shortLink = generateShortLink();
  122. if (shortLink) {
  123. window.history.replaceState(null, '', shortLink);
  124. }
  125. }
  126.  
  127. // Add the copy button if enabled
  128. if (enableButton) {
  129. // Find the product title
  130. const productTitleElement = document.getElementById('productTitle');
  131. if (productTitleElement) {
  132. // Detect browser language
  133. const lang = navigator.language || navigator.userLanguage;
  134. const buttonText = lang.startsWith('it') ? 'Copia Link Breve' : 'Copy Short Link';
  135.  
  136. // Create the button
  137. const copyButton = document.createElement('button');
  138. copyButton.textContent = buttonText;
  139. copyButton.style.marginTop = '10px';
  140. copyButton.style.marginBottom = '4px'; // Add spacing below the button
  141. copyButton.style.padding = '8px 16px';
  142. copyButton.style.backgroundColor = '#ffa41c';
  143. copyButton.style.color = '#111';
  144. copyButton.style.border = '1px solid #ffa41c';
  145. copyButton.style.cursor = 'pointer';
  146. copyButton.style.borderRadius = '20px';
  147. copyButton.style.display = 'block'; // Ensure the button is on a new line
  148. copyButton.style.fontSize = '14px';
  149. copyButton.style.textAlign = 'center';
  150. copyButton.style.textDecoration = 'none';
  151. copyButton.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.15)';
  152.  
  153. // Add click event to the button
  154. copyButton.addEventListener('click', () => {
  155. const shortLink = generateShortLink();
  156. if (shortLink) {
  157. copyToClipboard(shortLink);
  158. } else {
  159. const errorText = lang.startsWith('it') ? 'Errore: impossibile generare il link breve.' : 'Error: Unable to generate the short link.';
  160. alert(errorText);
  161. }
  162. });
  163.  
  164. // Insert the button below the product title
  165. productTitleElement.parentNode.insertBefore(copyButton, productTitleElement.nextSibling);
  166. }
  167. }
  168. })();