Amazon short link copy

Adds a "Copy" link to the share options on amazon product pages.

Click here to install Browse More Scripts
// ==UserScript==
// @name         Amazon short link copy
// @namespace    3833c0036cc0ea9c5f782d50c0c5e3ba9209bddd
// @version      0.3
// @description  Adds a "Copy" link to the share options on amazon product pages.
// @author       /u/AyrA_ch
// @include      /^https?:\/\/(\w+\.)?amazon(\.co)?\.\w+\//
// @grant        none
// ==/UserScript==

// Version History
// 0.3 - Made this work on products that are out of stock
// 0.2 - Updated URL include
// 0.1 - Initial version

(function () {
	const m = location.href.match(/\/dp\/[^\/\?]+/);
	if (m) {
		const shortlink = location.origin + m[0];
		const container = document.querySelector("#title_feature_div");
		const copy = document.createElement("a");
		const spacer = document.createElement("div");
		spacer.classList.add("a-spacing-small");

		copy.textContent = "Copy Shortlink";
		copy.href = m;
		copy.title = "Copies the current short URL to your clipboard";
		copy.addEventListener("click", function (e) {
			e.preventDefault();
			e.stopPropagation();
			var i = document.createElement("input");
			i.value = shortlink;
			container.appendChild(i);
			i.focus();
			i.select();
			document.execCommand("copy");
			i.remove();
			alert("Link copied to clipboard");
		});
		//Add the spacer
		container.insertBefore(spacer, container.childNodes[0]);
		//Add link in front of the spacer
		container.insertBefore(copy, spacer);
	}
})();

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 98.80.143.34