Compare commits

..

2 commits

Author SHA1 Message Date
alexture
5d822caf97 Add books.google.fr support
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X4uRGZZ4EpYHA4PNK3x5JY
2026-09-20 16:47:54 +02:00
alexture
ac9c35b06d Add Google Books support
Match books.google.com and google.com/books/edition pages, extract the ISBN
from page text with a title/author fallback, and bump version to 1.2 so
userscript auto-update picks it up.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X4uRGZZ4EpYHA4PNK3x5JY
2026-09-20 16:47:45 +02:00
2 changed files with 24 additions and 2 deletions

View file

@ -11,7 +11,7 @@ The script auto-updates itself from this repo (via `@updateURL`), so you don't n
## What it does ## What it does
On a book page on Bookshop.org, Amazon (`.fr`/`.com`), or Waterstones, it: On a book page on Bookshop.org, Amazon (`.fr`/`.com`), Waterstones, or Google Books, it:
1. Extracts the book's ISBN (from the URL or page content) and, as a fallback, title/author. 1. Extracts the book's ISBN (from the URL or page content) and, as a fallback, title/author.
2. Checks whether the book is available on: 2. Checks whether the book is available on:
@ -24,6 +24,7 @@ On a book page on Bookshop.org, Amazon (`.fr`/`.com`), or Waterstones, it:
- `bookshop.org/p/books/*` - `bookshop.org/p/books/*`
- `waterstones.com/book/*` - `waterstones.com/book/*`
- `amazon.fr` and `amazon.com` product pages (`/dp/*`) - `amazon.fr` and `amazon.com` product pages (`/dp/*`)
- Google Books (`books.google.com/books?id=…`, `google.com/books/edition/…`, and the `.fr` equivalents)
## Notes ## Notes

View file

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Book Links // @name Book Links
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 1.1 // @version 1.3
// @description Show Anna's Archive and Waterstones links when browsing books // @description Show Anna's Archive and Waterstones links when browsing books
// @license MIT // @license MIT
// @match https://bookshop.org/p/books/* // @match https://bookshop.org/p/books/*
@ -10,6 +10,10 @@
// @match https://www.amazon.fr/*/dp/* // @match https://www.amazon.fr/*/dp/*
// @match https://www.amazon.com/dp/* // @match https://www.amazon.com/dp/*
// @match https://www.amazon.com/*/dp/* // @match https://www.amazon.com/*/dp/*
// @match https://books.google.com/books?*
// @match https://www.google.com/books/edition/*
// @match https://books.google.fr/books?*
// @match https://www.google.fr/books/edition/*
// @connect annas-archive.gl // @connect annas-archive.gl
// @connect www.waterstones.com // @connect www.waterstones.com
// @connect www.chez-mon-libraire.fr // @connect www.chez-mon-libraire.fr
@ -62,6 +66,17 @@
return null; return null;
} }
if (host.includes('google.')) {
const text = document.body?.innerText || '';
const m13 = text.match(/\b(97[89][-\d ]{9,14}\d)\b/);
if (m13) {
const cleaned = m13[1].replace(/[-\s]/g, '');
if (/^97[89]\d{10}$/.test(cleaned)) return cleaned;
}
const m10 = text.match(/ISBN[\s:]+(?:[\d-]+,\s*)?(\d{9}[\dX])\b/);
return m10 ? isbn10to13(m10[1]) : null;
}
if (host.includes('bookshop.org')) { if (host.includes('bookshop.org')) {
const el = document.querySelector('[itemprop="isbn"]'); const el = document.querySelector('[itemprop="isbn"]');
if (el && /^97[89]\d{10}$/.test(el.textContent.trim())) return el.textContent.trim(); if (el && /^97[89]\d{10}$/.test(el.textContent.trim())) return el.textContent.trim();
@ -106,6 +121,12 @@
return { title, author }; return { title, author };
} }
if (host.includes('google.')) {
const title = document.querySelector('h1')?.textContent?.trim();
const author = document.querySelector('a[href*="inauthor"]')?.textContent?.trim();
return { title, author };
}
if (host.includes('waterstones.com')) { if (host.includes('waterstones.com')) {
const title = ( const title = (
document.querySelector('[itemprop="name"]') || document.querySelector('[itemprop="name"]') ||