eBay easy item ID

Puts the item ID under the title with buttons for copying it and the cleaned URL

  1. // ==UserScript==
  2. // @name eBay easy item ID
  3. // @namespace pnppl
  4. // @match https://www.ebay.com/itm/*
  5. // @match https://www.ebay.at/itm/*
  6. // @match https://www.ebay.ca/itm/*
  7. // @match https://www.ebay.ch/itm/*
  8. // @match https://www.ebay.co.nz/itm/*
  9. // @match https://www.ebay.co.uk/itm/*
  10. // @match https://www.ebay.com.au/itm/*
  11. // @match https://www.ebay.com.hk/itm/*
  12. // @match https://www.ebay.com.my/itm/*
  13. // @match https://www.ebay.com.sg/itm/*
  14. // @match https://www.ebay.de/itm/*
  15. // @match https://www.ebay.es/itm/*
  16. // @match https://www.ebay.fr/itm/*
  17. // @match https://www.ebay.ie/itm/*
  18. // @match https://www.ebay.in/itm/*
  19. // @match https://www.ebay.it/itm/*
  20. // @match https://www.ebay.nl/itm/*
  21. // @match https://www.ebay.ph/itm/*
  22. // @match https://www.ebay.pl/itm/*
  23. // @grant none
  24. // @version 1.11
  25. // @author pnppl
  26. // @description Puts the item ID under the title with buttons for copying it and the cleaned URL
  27. // @license MIT
  28. // ==/UserScript==
  29.  
  30. const url = window.location.href;
  31. const reItm = /.*\/([0-9]{12})/;
  32. const itm = url.match(reItm)[1];
  33. const reTLD = /^https:\/\/(?:www.)?(ebay\.[a-z]{2,3}(?:\.[a-z]{2,3})?)/i;
  34. const tld = url.match(reTLD)[1];
  35. const cleanURL = `https://${tld}/itm/${itm}`;
  36. const titleMob = document.querySelector("#vi-frag-app-title");
  37. const titleDesk = document.querySelector(".x-item-title");
  38. const newHTML = ` \
  39. <style> \
  40. button:focus.userjs { \
  41. background:lime; \
  42. } \
  43. </style> \
  44. <div> \
  45. <p> \
  46. ${itm} <button class="userjs" onclick="navigator.clipboard.writeText('${itm}')">📋</button> <button class="userjs" onclick="navigator.clipboard.writeText('${cleanURL}')">🔗</button> \
  47. </p> \
  48. </div> \
  49. `;
  50.  
  51. if (titleMob == null) {
  52. titleDesk.insertAdjacentHTML("afterend", newHTML);
  53. } else {
  54. titleMob.insertAdjacentHTML("afterend", newHTML);
  55. }