Skip to content

Commit 739a6e8

Browse files
committed
init
Signed-off-by: Fan Shangxiang <[email protected]>
0 parents  commit 739a6e8

File tree

17 files changed

+1671
-0
lines changed

17 files changed

+1671
-0
lines changed

.eslintrc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"webextensions": true
6+
},
7+
"extends": "standard",
8+
"parserOptions": {
9+
"ecmaVersion": "latest",
10+
"sourceType": "module"
11+
},
12+
"rules": {
13+
"semi": ["error", "always"],
14+
"quotes": ["error", "single"],
15+
"indent": ["error", 2],
16+
"no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
17+
"space-before-function-paren": ["error", {
18+
"anonymous": "always",
19+
"named": "never",
20+
"asyncArrow": "always"
21+
}],
22+
"comma-dangle": ["error", "never"],
23+
"no-console": "off"
24+
},
25+
"globals": {
26+
"chrome": "readonly",
27+
"browser": "readonly"
28+
}
29+
}

.github/workflows/release.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Release Extension
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build-and-release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '18'
23+
24+
- name: Install dependencies
25+
run: npm ci || npm install
26+
27+
- name: Build extension
28+
run: npm run build
29+
30+
- name: Create distribution package
31+
run: |
32+
cd dist
33+
zip -r ../douban-beijing-library-finder-${{ github.ref_name }}.zip *
34+
cd ..
35+
36+
- name: Generate changelog
37+
id: changelog
38+
run: |
39+
echo "## What's Changed" > CHANGELOG.md
40+
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:"- %s (%h)" >> CHANGELOG.md || echo "- Initial release" >> CHANGELOG.md
41+
42+
- name: Create GitHub Release
43+
uses: softprops/action-gh-release@v1
44+
with:
45+
files: |
46+
douban-beijing-library-finder-${{ github.ref_name }}.zip
47+
body_path: CHANGELOG.md
48+
draft: false
49+
prerelease: false
50+
generate_release_notes: true
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Upload artifact
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: extension-package
58+
path: douban-beijing-library-finder-${{ github.ref_name }}.zip
59+
retention-days: 30

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Dependencies
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Build output
8+
dist/
9+
*.zip
10+
11+
# IDE and Editor files
12+
.vscode/
13+
.idea/
14+
*.swp
15+
*.swo
16+
*~
17+
.DS_Store
18+
Thumbs.db
19+
20+
# Environment files
21+
.env
22+
.env.local
23+
.env.development.local
24+
.env.test.local
25+
.env.production.local
26+
27+
# Logs
28+
logs/
29+
*.log
30+
31+
# Testing
32+
coverage/
33+
.nyc_output
34+
35+
# Temporary files
36+
tmp/
37+
temp/
38+
*.tmp
39+
40+
# Package manager locks (optional - uncomment if you want to exclude)
41+
# package-lock.json
42+
# yarn.lock

.vscodeignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules/
2+
*.ts
3+
*.md
4+
.git/
5+
.gitignore
6+
.vscodeignore
7+
build.js
8+
package.json
9+
tsconfig.json
10+
docs/

ARCHITECTURE.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Douban Library Extension Architecture
2+
3+
## Overview
4+
This Edge extension enhances Douban book detail pages by adding library borrowing functionality. It checks if books are available in the Beijing Library (bjyth.jiatu.cloud) and adds a "Borrow" button when available.
5+
6+
## Extension Workflow
7+
8+
```mermaid
9+
flowchart TD
10+
A[User visits Douban book page] --> B[Content script activates]
11+
B --> C[Extract ISBN from page]
12+
C --> D{ISBN found?}
13+
D -->|No| E[Exit - No action]
14+
D -->|Yes| F[Send ISBN to background script]
15+
F --> G[Background script queries library]
16+
G --> H[Parse HTML response]
17+
H --> I{Book available?}
18+
I -->|No| J[No button added]
19+
I -->|Yes| K[Inject Borrow button]
20+
K --> L[User clicks button]
21+
L --> M[Open library page in new tab]
22+
```
23+
24+
## Component Structure
25+
26+
```
27+
ext/
28+
├── manifest.json # Extension configuration
29+
├── content.js # Runs on Douban pages
30+
├── background.js # Handles cross-origin requests
31+
├── styles.css # Button styling
32+
├── icons/ # Extension icons
33+
│ ├── icon-16.png
34+
│ ├── icon-48.png
35+
│ └── icon-128.png
36+
├── package.json # Development dependencies
37+
└── README.md # User documentation
38+
```
39+
40+
## Key Components
41+
42+
### 1. Content Script (content.js)
43+
- **Runs on**: `https://book.douban.com/subject/*`
44+
- **Responsibilities**:
45+
- Extract ISBN from book detail page
46+
- Send ISBN to background script
47+
- Inject "Borrow" button when book is available
48+
- Handle button click events
49+
50+
### 2. Background Script (background.js)
51+
- **Purpose**: Handle cross-origin requests (CORS bypass)
52+
- **Responsibilities**:
53+
- Receive ISBN from content script
54+
- Query library search API
55+
- Parse HTML response
56+
- Return availability status
57+
58+
### 3. Manifest Configuration
59+
- **Permissions needed**:
60+
- `https://book.douban.com/*` (content script injection)
61+
- `https://bjyth.jiatu.cloud/*` (library API access)
62+
- `activeTab` (interact with current tab)
63+
- `storage` (optional, for caching)
64+
65+
## Data Flow
66+
67+
1. **ISBN Extraction**:
68+
- Look for ISBN in book info section
69+
- Format: ISBN-10 or ISBN-13
70+
- Location: Usually under "书籍信息" section
71+
72+
2. **Library Query**:
73+
- URL: `https://bjyth.jiatu.cloud/yuntu-pc/home/search/index?word={ISBN}`
74+
- Method: GET request via background script
75+
- Response: HTML page with search results
76+
77+
3. **Availability Check**:
78+
- Parse HTML for book status
79+
- Look for availability indicators
80+
- Common patterns: "可借", "在架", "available"
81+
82+
4. **Button Injection**:
83+
- Location: Next to ISBN number
84+
- Style: Blue button (#2E7FBE)
85+
- Text: "图书馆借阅" or "Borrow"
86+
- Action: Opens library page in new tab
87+
88+
## Technical Considerations
89+
90+
1. **CORS Handling**:
91+
- Library site may block cross-origin requests
92+
- Solution: Use background script as proxy
93+
94+
2. **Page Structure Changes**:
95+
- Douban may update their HTML structure
96+
- Use robust selectors and fallbacks
97+
98+
3. **Performance**:
99+
- Cache library queries (optional enhancement)
100+
- Debounce multiple requests
101+
102+
4. **Error Handling**:
103+
- Network failures
104+
- ISBN not found
105+
- Library site changes
106+
107+
## Security Considerations
108+
109+
- Only inject scripts on trusted domains
110+
- Validate ISBN format before querying
111+
- Sanitize any HTML content from library response
112+
- Use Content Security Policy in manifest
113+
114+
## Testing Strategy
115+
116+
1. Test with various ISBN formats
117+
2. Test with books available/unavailable
118+
3. Test network error scenarios
119+
4. Test on different Douban page layouts
120+
5. Verify button styling consistency
121+
122+
## Future Enhancements (Out of scope for MVP)
123+
124+
- Support multiple library systems
125+
- Show real-time availability count
126+
- Add reservation functionality
127+
- Cache queries for performance
128+
- User preferences/settings page

0 commit comments

Comments
 (0)