Amazon Wish List Custom Items

Add custom items to your wish list. Links to eBay and external sites. Replaces idea list image with yellow lightbulb.

目前為 2021-07-31 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Amazon Wish List Custom Items
// @version      0.1
// @description  Add custom items to your wish list. Links to eBay and external sites. Replaces idea list image with yellow lightbulb.
// @author       asheroto
// @namespace    https://greasyfork.org/en/scripts/430176-amazon-wish-list-custom-items
// @match        https://www.amazon.com/gp/registry/wishlist/*
// @match        https://www.amazon.com/hz/wishlist/*
// ==/UserScript==

(function () {
	// Set length
	var g_length = 0;

	// Match maker
	function e_match(elem, ih_match, regexPattern, replaceThis, href_prepend, hrefText) {
		try {
			// If keyword matches
			if (elem.innerHTML.includes(ih_match)) {
				// Match regex pattern
				var e_matches = elem.innerHTML.match(regexPattern);

				// Get number of matches
				var e_length = e_matches.length;

				// If at least 1 match
				if (e_length > 0) {
					// Replace data
					var e_href = href_prepend + e_matches[0].replace(replaceThis, "");

					// Create link
					var e_result = '<a href="' + e_href + '" target="_blank">' + hrefText + "<a/>";

					// Replace data in DOM
					elem.innerHTML = e_result;
				}
			}
		} catch (e) {}

		return true;
	}

	// Checker
	function check() {
		// Get all comments box elements
		let wt = document.getElementsByClassName("wrap-text");
		let wt_length = wt.length;
		for (var i = 0; i <= wt_length - 1; i++) {
			// Get element
			var elem = document.getElementsByClassName("wrap-text")[i];

			// eBay
			e_match(elem, "ebay:", "\\bebay:(.*)\\S", "ebay:", "https://www.ebay.com/sch/i.html?_nkw=", '<img src="https://svgur.com/i/Zhh.svg" width="75x"></img>');

			// URL
			e_match(elem, "url:", "\\burl:(.*)\\S", "url:", "", "External Website");
		}

		// Get all idea images
		let ii = document.getElementsByTagName("img");
		let ii_length = ii.length;
		for (i = 0; i <= ii_length - 1; i++) {
			// Get element
			var elemI = ii[i];

			// Image
			var img = elemI.src;
			if (img.includes("wfa_idea")) {
				// Replace img src
				var i_result = "https://i.ibb.co/6vf3qNs/idea.png";

				// Replace data in DOM
				elemI.src = i_result;
				elemI.width = "135";
				elemI.height = "135";
			}
		}
	}

	// Check if page has changed by comparing length
	function runCheck() {
		let gil = document.getElementById("g-items").innerHTML.length;
		if (gil > g_length) {
			g_length = gil;
			check();
		}
	}

	// Run check every 2 seconds
	var repeat = setInterval(runCheck, 2000);

	// Initial run
	runCheck();
})();