Goodreads Search Many

Add "Search MAM" button to Goodreads

目前為 2022-06-27 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Goodreads Search Many
// @version      0.2
// @namespace    https://greasyfork.org/en/users/929273-eshuigugu
// @description  Add "Search MAM" button to Goodreads
// @author       Eshuigugu
// @match      https://www.goodreads.com/*
// @grant        none
// ==/UserScript==

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

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

if(page === 'list'){
	var bookTitle = getBooksQuery();
    var mam_url = new URL("https://www.myanonamouse.net/tor/browse.php");
    mam_url.searchParams.append('tor[text]', bookTitle);

	// Add 'Search MAM' button
    var buttonBar = document.getElementsByClassName("right")[1]
	var buttonUl = buttonBar.getElementsByTagName("a");
    let element = document.createElement("a");
    element.href = mam_url.href;
    element.innerHTML="Search MAM";
    element.className = 'tab';
    element.target="_blank";
    buttonBar.appendChild(element)
	console.log("[G+] 'Search MAM' button added!");
}

// Grab book title (and only title) from the element
function getBooksQuery(){
    var books_list = document.getElementById("all_votes")
    var joined_query="";
    for (const listed_book of books_list.getElementsByTagName("tr")
        ) {
        var book_title = listed_book.getElementsByClassName("bookTitle")[0].text.replace(/[\(;~].*/i,"").replace(/[/\\\"\@]/g, " ").trim()
        var book_author = listed_book.getElementsByClassName("authorName")[0].text.trim()
        undefined
        var query_str = `(${book_title} ${book_author })`;
        if (joined_query.length == 0){
            joined_query=query_str
        }
        else
        {
            joined_query+= "|"+query_str
        }
    }
    return joined_query
}