Open in Goodreads

Adds a button to Amazon book pages to redirect to Goodreads page based on ASIN/ISBN

当前为 2023-07-12 提交的版本,查看 最新版本

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Open in Goodreads
// @namespace    https://greasyfork.org/en/users/786838-sirgryphin
// @version      1.0
// @description  Adds a button to Amazon book pages to redirect to Goodreads page based on ASIN/ISBN
// @author       SirGryphin
// @match        *://*.amazon.*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function redirectToGoodreads() {
        var asin_elements, asin;
        asin_elements = document.getElementsByName('ASIN');
        if (asin_elements.length == 0) {
            asin_elements = document.getElementsByName('ASIN.0');
        }
        if (asin_elements.length == 0) {
            alert("No ASIN or ISBN Found.");
        } else {
            asin = asin_elements[0].value;
            if (asin.match(/\D/) === null) {
                var x = window.open('http://www.goodreads.com/review/isbn/' + asin, 'add_review');
            } else {
                var x = window.open('https://www.goodreads.com/book/isbn?isbn=' + asin);
            }
            x.focus();
        }
    }

    function addButton() {
        var ebookSample = document.getElementById('EbookSample');
        if (ebookSample) {
            var button = document.createElement('button');
            button.innerText = 'Open in Goodreads';
            button.style.marginTop = '10px';
            button.style.marginBottom = '10px';
            button.style.display = 'block';
            button.style.marginLeft = 'auto';
            button.style.marginRight = 'auto';
            button.style.color = '#ffffff';
            button.style.backgroundColor = '#377458';
            button.style.border = 'none';
            button.style.borderRadius = '4px';
            button.style.padding = '8px 12px';
            button.style.fontFamily = 'Arial, sans-serif';
            button.style.fontSize = '14px';
            button.style.fontWeight = 'bold';
            button.style.textDecoration = 'none';
            button.style.cursor = 'pointer';

            button.onclick = redirectToGoodreads;

            var centerDiv = document.createElement('div');
            centerDiv.style.textAlign = 'center';
            centerDiv.appendChild(button);

            ebookSample.parentNode.insertBefore(centerDiv, ebookSample.nextSibling);
        }
    }

    addButton();
})();