NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Amazon Link Shortener // @namespace Crazycatz00 // @description Adds a tiny link on (most) Amazon product pages. Can also optionally calculate taxes on (most) prices. (Up to the user to decide where it's applicable.) // @match *://*.amazon.com/* // @match *://*.amazon.co.uk/* // @version 1.0.3 // @grant none // ==/UserScript== (function(){'use strict'; const TAX_RATE = 0.00; // --- Link Generator var asin = window.sitbAsin || window.ue_pti || (document.getElementById('ASIN') || {}).value, p; // Last-ditch, URL-sniffing effort if(typeof asin !== 'string' || asin.length < 10){ if(window.location.pathname.search(/\/([A-Z0-9]{10})\/?/)!==-1){asin = RegExp.$1;} else{asin = undefined;} } if(asin && (p = document.getElementById('brandByline_feature_div')) || (p = document.getElementById('title_feature_div')) || ((p = document.getElementById('btAsinTitle')) && (p = p.parentNode) && (p = p.parentNode)) || (p = document.getElementById('average-customer-reviews_feature_div')) ){ p = p.parentNode.insertBefore(document.createElement('a'), p.nextSibling); p.textContent = '[Tiny Link]'; p.href = '//amzn.com/' + asin; p.className = 'a-size-mini'; } // --- Tax calculator if(TAX_RATE > 0){ p = function(e){ if(!e.title && e.textContent.search(/^\s*\$(\d+(?:\.\d+)?)\s*$/) !== -1 && RegExp.$1 > 0){ e.title = 'Tax: $' + (RegExp.$1 * TAX_RATE).toFixed(2) + '\nAmazon.com only'; }else{ console.log(e); } }; Array.forEach(document.getElementsByClassName('a-color-price'), p); Array.forEach(document.getElementsByClassName('price'), p); Array.forEach(document.getElementsByClassName('priceLarge'), p); } }());