MAM search on Goodreads

Add "Search Goodreads" button to MAM

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MAM search on Goodreads
// @namespace    https://github.com/Alistair1231/my-userscripts/
// @version      0.7.9
// @description  Add "Search Goodreads" button to MAM
// @author       Alistair1231
// @include      https://www.myanonamouse.net/t/*
// ==/UserScript==

// Thanks for https://greasyfork.org/en/users/78880-slengpung for the inspiration
// https://greasyfork.org/en/scripts/24678-goodreads-plus

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

if(page === 't'){
	var bookTitle = document.getElementsByClassName("TorrentTitle")[0].innerHTML.trim();
    var author = document.getElementsByClassName("torDetRight torAuthors")[0].textContent;

    // this new regex matches names like 'A B Name', they have to be changed to 'AB Name'
    // https://regex101.com/r/MtDzfo/1 for more info on how it works
    var regex = /(\s|^)(.*\s)(\w)\s(\w)(\s.*)/gm;
    author = author.replace(regex,"$1$2$3$4$5");

    // thanks for @GardenShade for letting me know these symbols break names. I couldn't find an example so it wasn't tested.
    bookTitle = bookTitle.replace('%', '').replace("'", '%27');

      var mamSearchUrl = "https://www.goodreads.com/search?q=" + bookTitle + " " + author;
//    var dereferedUrl = "http://www.dereferer.org/?"+encodeURIComponent(mamSearchUrl);
//    var dereferedUrl = "http://de-ref.com/?"+mamSearchUrl;
//    var dereferedUrl = "https://url.rw/?"+encodeURIComponent(mamSearchUrl);
      var dereferedUrl = "https://r.mrd.ninja/"+encodeURIComponent(mamSearchUrl);


	// Add 'Search MAM' button
	var buttonUl  = document.getElementById("fInfo").childNodes;
	var mamButton = document.createElement("div");
	mamButton.innerHTML = '<div id="size" class="torDetInnerCon ">'+
        '<div class="torDetInnerTop ">Goodreads </div>'+
        '<div class="torDetInnerBottomSpan "><span>'+
        '<a id="mamLink" href="' + dereferedUrl + '" target="_blank" class="buttonBar"><input type="button" value="Search Goodreads" /></a>'+
        '</span></div>';
	buttonUl[0].appendChild(mamButton);
}