As a tech person who loves reading, I’ve accumulated reading notes on hundreds of books in WeRead. But every time I wanted to show a reading list on my own blog, I had to copy and paste it by hand, which was painfully inefficient. So I decided to build an automated booklist sync solution that gives me one-click sync from WeRead to my personal blog.
Project Background and Requirements Analysis
Pain Points
As a long-time WeRead user, I faced the following problems:
Data silo: WeRead’s booklist data is locked inside the app, with no official API for developers to use.
Cumbersome manual sync: To display a booklist on a personal blog, I had to enter each book by hand.
Image hotlink problem: WeRead’s cover images have hotlink protection, so referencing them directly breaks.
Reading progress not synced: I wanted to show each book’s reading progress and reading time.
Goals
Build a complete sync solution:
Chrome extension: Intercept data from WeRead’s web version and extract booklist information.
Backend service: Receive the data, download cover images, and upload them to my own OSS.
Database storage: Save book info, reading progress, reading time, and so on.
Technical Architecture Design
The system architecture is divided into three layers:
Frontend Implementation: Chrome Extension
Manifest V3 Configuration
The Chrome extension uses Manifest V3. The core configuration is as follows:
// Intercept the shelf sync API if (url.includes('/web/shelf/sync')) { const response = await originalFetch.apply(this, args); const clonedResponse = response.clone(); const data = await clonedResponse.json();
// Extract book data const books = extractBooksFromAPIData(data);
// Send to the content script window.postMessage({ type: 'WEREAD_SHELF_DATA', data: { booksAndArchives: books } }, '*');
return response; }
return originalFetch.apply(this, args); };
Data Parsing and Merging
The data returned by WeRead’s API is split into two parts: books (basic book info) and bookProgress (reading progress). They need to be joined on bookId:
The actual effect is shown below. Users can intuitively see each book’s cover, title, author, and reading progress:
Backend Implementation: Go + Gin + OSS
The backend is built with the Go language and the Gin framework. Its main functions are: receiving extension data, downloading cover images, uploading to Aliyun OSS, and persisting data.
// Set headers to mimic a browser req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36") req.Header.Set("Referer", "https://weread.qq.com/")
// Handle image upload coverURL := req.Cover if h.OSS != nil && h.OSS.IsEnabled() && req.Cover != "" { newURL, err := h.OSS.DownloadAndUploadImage(req.Cover, req.BookID) if err == nil { coverURL = newURL } // Fall back to the original URL if the upload fails }
// Check whether the book already exists var existing models.Book if err := h.DB.Where("book_id = ?", req.BookID).First(&existing).Error; err == nil { // Update the existing book updates := make(map[string]interface{})
if coverURL != "" && coverURL != existing.Cover { updates["cover"] = coverURL } if req.ReadingDuration > 0 && req.ReadingDuration != existing.ReadingDuration { updates["reading_duration"] = req.ReadingDuration } if !req.LastReadingTime.IsZero() { updates["last_reading_time"] = req.LastReadingTime.Time } // ... update other fields
Once configured, click the “Sync shelf” button on the WeRead web version:
A book selection interface pops up, showing each book’s reading progress.
Select the books to sync and click confirm.
The extension automatically extracts the data and sends it to the backend.
The backend downloads the cover images and uploads them to OSS.
A desktop notification reports the sync result.
After the sync completes, you get a desktop notification showing the stats for this sync:
Summary
Through this project I built a complete “scrape – process – store” pipeline:
Technical highlights:
Best practices for Chrome Extension Manifest V3
A front-end/back-end separated architecture
An Aliyun OSS image-hosting solution
A concise, efficient backend implementation in Go
Extensibility:
It can easily be adapted to other reading platforms (like Douban Reading, Kindle, etc.)
It supports bulk import and incremental updates
Reading data visualization (statistical charts can be added later)
Reference links: “}} (Assistant: Now let’s modify the other few posts. First let’s look at the context of the WeRead post. (Assistant: Now let’s modify the WeRead post. I modified it long ago already, let me check whether there are other posts that need modifying. From the previous grep results, there are still a few posts that contain
评论
0 条评论