Goodreads Plus

Add "Search MAM" button to Goodreads

目前為 2022-08-21 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Goodreads Plus
// @namespace    https://greasyfork.org/en/users/78880
// @version      0.3.9
// @description  Add "Search MAM" button to Goodreads
// @author       Slengpung
// @include      https://www.goodreads.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

console.log("[G+] Tweaking Goodreads...");

var page = window.location.pathname.split('/')[1];

if(page === 'book'){
    console.log("[G+] We got a book URL");
	var bookTitle = document.getElementsByClassName("Text__title1")[0].innerHTML;
	console.log("[G+] Book title: " + bookTitle);
	var mamSearchUrl = "https://www.myanonamouse.net/tor/browse.php?tor[text]=" + bookTitle;

	// Add 'Search MAM' button
	var buttonBar = document.getElementsByClassName("BookActions")[0];
	var mamButton  = document.getElementsByClassName("BookActions__button")[0].cloneNode(true);
	mamButton.innerHTML = '<div class="BookActions__button"><a href="' + mamSearchUrl + '">' + 
	    '<div class="Button__container Button__container--block">' + 
	    '<button type="button" class="Button Button--secondary Button--medium Button--block">' + 
	    '<span class="Button__labelItem">Search MAM</span></button></div></a></div>';
	
	buttonBar.appendChild(mamButton)
	console.log("[G+] 'Search MAM' button added!");
}else if(page === 'review'){
	var bookList = document.querySelectorAll('#booksBody .title div a');
	// Loop over all the books
	for(var i=0; i<bookList.length; i++){
		var mamSearchUrl = "https://www.myanonamouse.net/tor/browse.php?tor[text]=" + getBookTitle(bookList[i]);
		// Add 'Search MAM' button
		var newLink = document.createElement('a');
		var linkText = document.createTextNode('[Search MAM]');
		newLink.appendChild(linkText);
		newLink.setAttribute('href',mamSearchUrl);
		newLink.setAttribute('style','color:#b3b3b3;font-style:italic');
		bookList[i].parentNode.parentNode.appendChild(newLink);
	}
	console.log("[G+] 'Search MAM' buttons added!");
}