Amazon Shortlinks

Adds a shortlink to Amazon product pages

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Amazon Shortlinks
// @namespace    https://github.com/felixfischer/show-amazon-shortlinks
// @version      1.5
// @description  Adds a shortlink to Amazon product pages
// @supportURL   https://github.com/felixfischer/show-amazon-shortlinks/issues
// @author       Felix Fischer
// @include      *www.amazon.*
// @include      *smile.amazon.*
// @grant        GM_setClipboard
// ==/UserScript==

(function(doc) {

    var ASIN = doc.getElementById("ASIN") || doc.getElementsByName("ASIN.0")[0];
    if (ASIN) {
        ASIN = ASIN.value;
        history.replaceState(null, "", "/dp/" + ASIN);
        var amznTLDs = ['com', 'co.uk', 'de', 'fr'];
        var noDpTLDs = ['com'];
        var domainParts = window.location.hostname.split('.');
        var TLD = domainParts.slice( domainParts.indexOf('amazon')+1 ).join('.');
        var SLD = amznTLDs.includes(TLD) ? 'amzn' : 'amazon';
        var pre = noDpTLDs.includes(TLD) ? '' : 'dp/';
        var URL = `${SLD}.${TLD}/${pre}${ASIN}`;
        var html =
            `<div class="a-spacing-large a-text-center" id="my-shortlink" title="click to copy">
                <a href="http://${URL}" onclick="return false">${URL}</a>
            </div>`;
        var pos = document.getElementById('tell-a-friend');
        pos.insertAdjacentHTML('afterend', html);
        var el = document.getElementById('my-shortlink');
        el.onclick = function() {
            GM_setClipboard('http://' + URL);
        };
    }

})(document);