FSFE Affiliate Programs + extras (auto-SSL...)

Modify Amazon links to support the FSFE, always use SSL and shorten links

  1. // ==UserScript==
  2. // @name FSFE Affiliate Programs + extras (auto-SSL...)
  3. // @namespace https://git.fsfe.org/FSFE/affiliate-script
  4. // @description Modify Amazon links to support the FSFE, always use SSL and shorten links
  5. // @version 0.5
  6.  
  7. // Contains the getASIN()-function from:
  8. // https://userscripts-mirror.org/scripts/review/3284 by Jim Biancolo
  9.  
  10. // @include http://*
  11. // @include https://*
  12.  
  13. // @license GPL-3.0-or-later
  14. // see https://www.gnu.org/licenses/gpl-3.0-standalone.html
  15. // @author Hannes Hauswedell (original author), Max Mehl (maintainer)
  16. // @homepage https://git.fsfe.org/FSFE/affiliate-script
  17. // ==/UserScript==
  18.  
  19.  
  20.  
  21. function getASIN(href) {
  22. var asinMatch;
  23. asinMatch = href.match(/\/exec\/obidos\/ASIN\/(\w{10})/i);
  24. if (!asinMatch) { asinMatch = href.match(/\/gp\/product\/(\w{10})/i); }
  25. if (!asinMatch) { asinMatch = href.match(/\/exec\/obidos\/tg\/detail\/\-\/(\w{10})/i); }
  26. if (!asinMatch) { asinMatch = href.match(/\/dp\/(\w{10})/i); }
  27. if (!asinMatch) { return null; }
  28. return asinMatch[1];
  29. }
  30.  
  31. (function()
  32. {
  33. var links = document.getElementsByTagName("a");
  34.  
  35. for (i = 0; i < links.length; i++)
  36. {
  37. var curLink = links[i].href;
  38.  
  39. // AMAZON
  40. if (curLink.match(/https?\:\/\/(www\.)?amazon\./i))
  41. {
  42. var affiliateID = '';
  43. var host = '';
  44. if (curLink.match(/amazon\.de/i))
  45. {
  46. host = 'amazon.de';
  47. affiliateID = 'fsfe-21';
  48. }
  49. else if (curLink.match(/amazon\.co\.uk/i))
  50. {
  51. host = 'amazon.co.uk';
  52. affiliateID = 'fsfe05-21';
  53. }
  54. else if (curLink.match(/amazon\.ca/i))
  55. {
  56. host = 'amazon.ca';
  57. affiliateID = 'fsfe-20';
  58. }
  59. else if (curLink.match(/amazon\.fr/i))
  60. {
  61. host = 'amazon.fr';
  62. affiliateID = 'fsfeurope-21';
  63. }
  64. else if (curLink.match(/amazon\.com/i))
  65. {
  66. host = 'amazon.com';
  67. affiliateID = 'freesoftfoune-20';
  68. }
  69.  
  70. var asin = getASIN(curLink);
  71. if (affiliateID != '')
  72. {
  73. if (asin != null)
  74. links[i].setAttribute("href", "https://www."+host+"/dp/" + asin + "/?tag="+affiliateID);
  75. // else
  76. // links[i].setAttribute("href", curLink + "?tag="+affiliateID);
  77. }
  78. }
  79. }
  80. })();