Amazon search MAM

Add "Search MAM" button to Amazon

目前為 2018-01-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 search MAM
// @namespace    https://greasyfork.org/en/users/78880
// @version      0.3
// @description  Add "Search MAM" button to Amazon
// @author       Slengpung
// @include      https://www.amazon.com/*
// @grant        none
// ==/UserScript==

var ul;

// If this is a book, inject search-button
try {
	var tmm = document.getElementById("tmmSwatches");
	ul = tmm.getElementsByTagName("ul")[0];
	console.log("MAM plugin: Looks like a book! Injecting MAM box...");
}
catch(err) {
	console.log("MAM plugin: This does not look like a book, won't inject search button!");
	return;
}

// Grab title
var title = document.getElementById("title").getElementsByTagName("span")[0].innerHTML;

// Grab author
var author = "";
var spans = document.getElementsByTagName("span");
for (var i = 0, len = spans.length; i < len; i++) {
	if(spans[i].innerHTML === "(Author)") {
		author = spans[i-2].innerText;
	}
}

// Create search-box
var li = document.createElement("li");
li.className += "swatchElement unselected resizedSwatchElement";

// Create search for title
var span = document.createElement("span");
//span.className += "a-button a-button-selected a-spacing-mini a-button-toggle format";
span.className += "a-spacing-mini format";
var a = document.createElement("a");
a.href = "https://www.myanonamouse.net/tor/browse.php?tor[srchIn][title]=true&tor[text]=" + title;
a.target = "_new";
var text = document.createTextNode("Search MAM for title");
a.appendChild(text);
span.style.cssText += "background: #EDB91F; text-align: left; border: none";
span.appendChild(a);

// Create search for title + author
var aauth = document.createElement("a");
aauth.href = "https://www.myanonamouse.net/tor/browse.php?tor[text]=" + title + "%20" + author;
aauth.target = "_new";
var textauth = document.createTextNode("Search MAM for title + author");
aauth.appendChild(textauth);
var br = document.createElement("br");
span.appendChild(br);
span.appendChild(aauth);

li.style.cssText += "height: 50px; padding: 5px 10px; background: #EDB91F; color: black;";
li.appendChild(span);

// Inject title-search on page
ul.appendChild(li);