Good2Dou - Goodreads Metadata Extractor for Douban
Overview of the Solution
This user script, named Good2Dou, acts as a bridge between the Goodreads book detail page and the Douban “Add New Book Subject” page. It works in two main phases:
- Goodreads Page: It extracts core book metadata (title, author, ISBN, description, publisher, etc.) from the Goodreads book page’s hidden
__NEXT_DATA__JSON structure and stores it locally using the UserScript storage API (GM_setValue). It then provides a button to redirect the user to Douban’s “Add New Subject” page. - Douban Page: On the various stages of the Douban “Add New Subject” process, the script provides buttons that read the stored Goodreads metadata (
GM_getValue) and automatically fill the corresponding form fields, saving the user significant manual input time. It also provides a button to trigger a download of the book’s cover image.
readme.md for the Script
A UserScript to simplify the process of adding new book subjects to Douban by automatically extracting and injecting metadata from Goodreads book detail pages.
Features
- Goodreads Metadata Extraction: Automatically parses hidden data on Goodreads book pages (using the
__NEXT_DATA__element) to extract:- Title and Subtitle
- Author(s)
- Description (cleaned up from HTML)
- ISBN-13
- Publisher and Publication Date (Year, Month, Day)
- Number of Pages
- Format (e.g., Paperback, Hardcover)
- Cover Image URL
- Seamless Workflow: Provides an “Add to Douban” button on Goodreads to extract data and open the Douban “Add New Subject” page in a new tab.
- Autofill Forms: Provides context-aware buttons on Douban’s new subject pages to automatically fill fields:
- Page 1 (ISBN & Title): Fills initial Title and ISBN.
- Page 2 (Autofill More): Fills Main Title, Subtitle, Author(s), Publisher, Publication Date, Pages, Format, and Description.
- Page 3 (Download Cover): Uses
GM_xmlhttpRequestto fetch and trigger a download of the cover image, bypassing potential CORS issues.
- Resilient Toolbar: The helper toolbar is injected robustly and is designed to reappear even if the site’s dynamic content (SPA-like behavior) removes it.
Installation
This is a UserScript and requires a browser extension like Tampermonkey (recommended) or Greasemonkey to run.
- Install Tampermonkey: Install the Tampermonkey extension for your browser (Chrome, Firefox, Edge, Safari, Opera).
- Install the Script: Visit Good2Dou on GreasyFork and click ‘Install’ button.
Usage
The script automatically detects whether you are on a Goodreads book page or a Douban new subject page and displays the appropriate actions in a toolbar inserted near the main title.
1. On a Goodreads Book Page (*.goodreads.com/book/show/*)
- Navigate to the page for the book you want to add to Douban.
- Locate the “Add to Douban” button added by the script.
- Click “Add to Douban”:
- The script will extract all available metadata.
- A new tab will open, navigating to the Douban “Add New Subject” page (
book.douban.com/new_subject).
2. On Douban “Add New Subject” Pages (*.book.douban.com/new_subject*)
Page 1: Initial Entry
- On the first page, locate the “ISBN & Title” button.
- Click “ISBN & Title” to automatically populate the initial Title and ISBN fields with the stored Goodreads data.
Page 2: Detailed Information
- After proceeding to the second page (or if starting directly here), locate the “Autofill More” button.
- Click “Autofill More” to fill the Main Title, Subtitle, Authors, Publisher, Publication Date, Pages, Format, and Description.
Page 3: Cover Upload
- On the final page, locate the “Download Cover” button.
- Click “Download Cover” to initiate a download of the book’s cover image extracted from Goodreads. This is done via a safe cross-origin request (
GM_xmlhttpRequest) to ensure the download works correctly, even if the image is on a different domain.
Technical Details
The script relies on the Tampermonkey API for persistent storage (GM_getValue, GM_setValue) and network requests (GM_xmlhttpRequest). The core logic for metadata retrieval on Goodreads is the reliable parsing of the hidden JSON object provided by the modern site structure:
const nextDataEl = document.querySelector('#__NEXT_DATA__');
const json = JSON.parse(nextDataEl.textContent);
const apollo = json?.props?.pageProps?.apolloState || {};
// ... then filters and extracts data from the Apollo state cache.
The data is saved globally under the key douban_book_meta_global to facilitate data transfer between the two websites.