NYT Search MAM

Add "MAM" button to NYT best sellers list

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NYT Search MAM
// @namespace    https://greasyfork.org/en/users/78880
// @version      0.2.5
// @description  Add "MAM" button to NYT best sellers list
// @author       Slengpung
// @match        https://www.nytimes.com/books/best-sellers/*
// @grant        none
// ==/UserScript==

window.addEventListener("load", Greasemonkey_main, false);

function Greasemonkey_main() {

    // Grab the books
    var lis = document.getElementsByClassName("css-1mr03gh");
    for (var i = 0; i < lis.length; ++i) {
	    // Get current book title
	    var title = lis[i].querySelector('[itemprop=name]').textContent;

	    // Create new button which searches MAM for the given title
	    var a = document.createElement("a");
	    a.href = "https://www.myanonamouse.net/tor/browse.php?tor[text]=" + encodeURIComponent(title);
	    a.target = "_new";
	    var mambutton = document.createElement("div");
	    var button = document.createElement("button");
	    var text = document.createTextNode("MAM");
	    button.appendChild(text);
	    button.className += "css-80zux2";
	    mambutton.appendChild(button);
	    mambutton.className += "css-79elbk";
	    a.appendChild(mambutton);

	    // Insert new button
	    lis[i].appendChild(a);

    }
}