Amazon Shortlinks

Adds a shortlink to Amazon product pages

  1. // ==UserScript==
  2. // @name Amazon Shortlinks
  3. // @namespace https://github.com/felixfischer/show-amazon-shortlinks
  4. // @version 1.5
  5. // @description Adds a shortlink to Amazon product pages
  6. // @supportURL https://github.com/felixfischer/show-amazon-shortlinks/issues
  7. // @author Felix Fischer
  8. // @include *www.amazon.*
  9. // @include *smile.amazon.*
  10. // @grant GM_setClipboard
  11. // ==/UserScript==
  12.  
  13. (function(doc) {
  14.  
  15. var ASIN = doc.getElementById("ASIN") || doc.getElementsByName("ASIN.0")[0];
  16. if (ASIN) {
  17. ASIN = ASIN.value;
  18. history.replaceState(null, "", "/dp/" + ASIN);
  19. var amznTLDs = ['com', 'co.uk', 'de', 'fr'];
  20. var noDpTLDs = ['com'];
  21. var domainParts = window.location.hostname.split('.');
  22. var TLD = domainParts.slice( domainParts.indexOf('amazon')+1 ).join('.');
  23. var SLD = amznTLDs.includes(TLD) ? 'amzn' : 'amazon';
  24. var pre = noDpTLDs.includes(TLD) ? '' : 'dp/';
  25. var URL = `${SLD}.${TLD}/${pre}${ASIN}`;
  26. var html =
  27. `<div class="a-spacing-large a-text-center" id="my-shortlink" title="click to copy">
  28. <a href="http://${URL}" onclick="return false">${URL}</a>
  29. </div>`;
  30. var pos = document.getElementById('tell-a-friend');
  31. pos.insertAdjacentHTML('afterend', html);
  32. var el = document.getElementById('my-shortlink');
  33. el.onclick = function() {
  34. GM_setClipboard('http://' + URL);
  35. };
  36. }
  37.  
  38. })(document);

QingJ © 2025

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