Greasy Fork is available in English.

eBay short URL

Replaces long url by short url.

  1. // ==UserScript==
  2. // @name eBay short URL
  3. // @namespace graphen
  4. // @version 1.2.1
  5. // @description Replaces long url by short url.
  6. // @author Ariel Jannai, graphen
  7. // @include /^https:\/\/www\.(be(fr|nl)\.)?ebay\.(at|ca|cn|vn|ie|it|nl|ph|pl|es|ch|de|fr|be|co\.(uk|th)|com(\.(au|hk|my|sg|tw))?)\/itm\/.*/
  8. // @run-at document-end
  9. // @icon https://cdn4.iconfinder.com/data/icons/flat-brand-logo-2/512/ebay-128.png
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. /* jshint esversion: 6 */
  15. (function(){
  16. 'use strict';
  17.  
  18. function tryShortUrl(url) {
  19. var urlPattern = /(be(fr|nl)\.)?ebay\.(at|ca|cn|vn|ie|it|nl|ph|pl|es|ch|de|fr|be|co\.(uk|th)|com(\.(au|hk|my|sg|tw))?)\/itm\//;
  20.  
  21. if(urlPattern.test(url)) {
  22. var itmId = url.match(/\/(\d{12})(\?|$)/)[1];
  23. return 'https://www.' + urlPattern.exec(url)[0] + itmId;
  24. } else {
  25. return url;
  26. }
  27. }
  28.  
  29. var url = String(window.location.href);
  30. history.replaceState(null, 'Shortened Ebay URL', tryShortUrl(url));
  31.  
  32. })();