NYT Search MAM

Add "MAM" button to NYT best sellers list

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);

    }
}