-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f51eafb
commit 269c2c6
Showing
21 changed files
with
395 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Taiwan eBook Downloader | ||
|
||
Download PDF books from [Taiwan eBook database](https://taiwanebook.ncl.edu.tw). | ||
|
||
## Install | ||
For Chrome, Edge, etc: | ||
* Grab the latest version of package(.crx) in the [releases](https://github.com/elementdavv/taiwan_ebook_downloader/releases) page. | ||
* Drop the package from file manager to Extension Manager page of your browser(developer mode must be enabled). | ||
|
||
For Firefox: | ||
* Grab the latest version of package(.xpi) in the [releases](https://github.com/elementdavv/taiwan_ebook_downloader/releases) page. | ||
* Drop the package from file manager to Extensions page of your browser. | ||
* Grant Optional permissions from Permissions tab on the extension page. | ||
|
||
Alternatively, install automatically from browser extension repositories(not always up to date): | ||
|
||
[Chrome WebStore](https://chrome.google.com/webstore/detail/taiwan-ebook-downloader/ealhmnpgajakmajhcdplfnpppdjknpoe) / [Edge Addons](https://microsoftedge.microsoft.com/addons/detail/taiwan-ebook-downloader/ifbmiaibmbefelonkecidnemlcdbllkh) / [Mozilla Addons (Firefox)](https://addons.mozilla.org/en-US/firefox/addon/taiwan_ebook_downloader/)(Optional permissions must be granted as well) | ||
|
||
## Usage | ||
In [Taiwan eBook database](https://taiwanebook.ncl.edu.tw) pages, book download buttons will show up automatically. | ||
|
||
## License | ||
[GPL3](LICENSE) ©Element Davv | ||
|
||
Any questions and/or suggestions are appreciatiated. | ||
|
||
## Donation | ||
If you would like to support my development, you can donate some coins. [![donate](resources/pp-logo.png)](https://paypal.me/timelegend) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"description": { "message": "Download PDF ebooks from Taiwan eBook database"} | ||
, "title": { "message": "Taiwan eBook database Downloader" } | ||
, "download": { "message": "Download " } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"description": { "message": "从台湾华文电子书库下载 PDF 电子书"} | ||
, "title": { "message": "台湾华文电子书库下载器" } | ||
, "download": { "message": "下载 " } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"description": { "message": "從臺灣華文電子書庫下載 PDF 電子書"} | ||
, "title": { "message": "臺灣華文電子書庫下載器" } | ||
, "download": { "message": "下載 " } | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* bg.js | ||
* Copyright (C) 2023 Element Davv<[email protected]> | ||
* | ||
* Distributed under terms of the GPL3 license. | ||
*/ | ||
|
||
(function(){ | ||
'use strict'; | ||
|
||
chrome.action.onClicked.addListener(tab => { | ||
const url = "https://taiwanebook.ncl.edu.tw"; | ||
chrome.tabs.create({ url: url }) | ||
}); | ||
|
||
chrome.tabs.onUpdated.addListener((tabid, changeinfo, tab) => { | ||
const re = /https:\/\/taiwanebook.ncl.edu.tw\/(zh-tw|en)\/(category|time|collection|search|book)\/.+/; | ||
const re1 = /reader/; | ||
if (changeinfo.status == 'complete') { | ||
if (!tab.url.match(re) || tab.url.match(re1)) return; | ||
chrome.scripting.executeScript({ | ||
files: ['js/content.js'] | ||
, target: {tabId: tabid} | ||
}); | ||
} | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* content.js | ||
* Copyright (C) 2023 Element Davv<[email protected]> | ||
* | ||
* Distributed under terms of the GPL3 license. | ||
*/ | ||
|
||
(async () => { | ||
if (typeof window.content1ted === 'undefined' ) { | ||
const src = chrome.runtime.getURL('js/content1.js'); | ||
window.content1ted = await import(src); | ||
window.content1ted.default(); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* content1.js | ||
* Copyright (C) 2023 Element Davv<[email protected]> | ||
* | ||
* Distributed under terms of the GPL3 license. | ||
*/ | ||
|
||
export default function(){ | ||
'use strict'; | ||
|
||
function showDownload() { | ||
const items = document.getElementsByClassName('items'); | ||
if (items.length > 0) { | ||
const itemlist = items[0].children; | ||
for (var i = 0; i < itemlist.length; i++) { | ||
showForItem(itemlist[i]); | ||
} | ||
} | ||
else { | ||
showForBook(); | ||
} | ||
} | ||
|
||
async function showForBook() { | ||
const blues = document.getElementsByClassName('ui four column grid'); | ||
if (blues.length == 0) return; | ||
|
||
const blue = blues[0]; | ||
const links = await getDownloadLinks(document.URL); | ||
links.forEach((link, i) => { | ||
addButton(link, blue, 'afterend'); | ||
}); | ||
} | ||
|
||
async function showForItem(item) { | ||
const headers = item.getElementsByClassName('header'); | ||
const metas = item.getElementsByClassName('meta'); | ||
if (headers.length == 0) return; | ||
if (metas.length == 0) return; | ||
|
||
const header = headers[0]; | ||
const meta = metas[0]; | ||
const href = header.getAttribute('href'); | ||
const links = await getDownloadLinks(href); | ||
links.forEach((link, i) => { | ||
addButton(link, meta, 'beforeend'); | ||
}); | ||
} | ||
|
||
const base = 'https://taiwanebook.ncl.edu.tw/'; | ||
const classList = ['ui','blue', 'button'] | ||
|
||
function addButton(link, node, pos) { | ||
const a = document.createElement('a'); | ||
a.href = base + link; | ||
const fname = link.substring(link.lastIndexOf('/') + 1) | ||
a.download = fname; | ||
a.textContent = chrome.i18n.getMessage('download') + fname; | ||
classList.forEach((cls, j) => { | ||
a.classList.add(cls); | ||
}); | ||
node.insertAdjacentElement(pos, a); | ||
const br = document.createElement('br'); | ||
node.insertAdjacentElement(pos, br); | ||
} | ||
|
||
async function getDownloadLinks(url) { | ||
const response = await fetch(url+ '/reader'); | ||
if (response.ok) { | ||
const text = await response.text(); | ||
const re = /ebkFiles.*?PDF/g; | ||
const files = text.match(re); | ||
|
||
var links = []; | ||
if (files.length > 1) { | ||
for (var i = 0; i < files.length - 1; i++) { | ||
links.push(files[i]); | ||
} | ||
} | ||
else { | ||
links.push(files[0]); | ||
} | ||
} | ||
return links; | ||
} | ||
|
||
console.log('Taiwanebook Downloader v0.1.0 in action'); | ||
showDownload(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"manifest_version": 3 | ||
, "author": "Element Davv <[email protected]>" | ||
, "description": "__MSG_description__" | ||
, "homepage_url": "https://github.com/elementdavv/taiwan_ebook_downloader" | ||
, "name": "Taiwan eBook Downloader" | ||
, "version": "0.1.0" | ||
, "default_locale": "en" | ||
, "browser_specific_settings": { | ||
"gecko": { | ||
"id": "[email protected]" | ||
} | ||
} | ||
, "icons": { | ||
"128": "images/logo128.png" | ||
} | ||
, "action": { | ||
"default_icon": { | ||
"128": "images/logo128.png" | ||
} | ||
, "default_title": "__MSG_title__" | ||
} | ||
, "background": { | ||
"scripts": ["js/bg.js"] | ||
, "type": "module" | ||
} | ||
, "permissions": [ | ||
"scripting" | ||
, "tabs" | ||
] | ||
, "host_permissions": [ | ||
"https://taiwanebook.ncl.edu.tw/*" | ||
] | ||
, "web_accessible_resources": [{ | ||
"resources": [ | ||
"js/*" | ||
] | ||
, "matches": ["https://taiwanebook.ncl.edu.tw/*"] | ||
}] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"description": { "message": "Download PDF ebooks from Taiwan eBook database"} | ||
, "title": { "message": "Taiwan eBook database Downloader" } | ||
, "download": { "message": "Download " } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"description": { "message": "从台湾华文电子书库下载 PDF 电子书"} | ||
, "title": { "message": "台湾华文电子书库下载器" } | ||
, "download": { "message": "下载 " } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"description": { "message": "從臺灣華文電子書庫下載 PDF 電子書"} | ||
, "title": { "message": "臺灣華文電子書庫下載器" } | ||
, "download": { "message": "下載 " } | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* bg.js | ||
* Copyright (C) 2023 Element Davv<[email protected]> | ||
* | ||
* Distributed under terms of the GPL3 license. | ||
*/ | ||
|
||
(function(){ | ||
'use strict'; | ||
|
||
chrome.action.onClicked.addListener(tab => { | ||
const url = "https://taiwanebook.ncl.edu.tw"; | ||
chrome.tabs.create({ url: url }) | ||
}); | ||
|
||
chrome.tabs.onUpdated.addListener((tabid, changeinfo, tab) => { | ||
const re = /https:\/\/taiwanebook.ncl.edu.tw\/(zh-tw|en)\/(category|time|collection|search|book)\/.+/; | ||
const re1 = /reader/; | ||
if (changeinfo.status == 'complete') { | ||
if (!tab.url.match(re) || tab.url.match(re1)) return; | ||
chrome.scripting.executeScript({ | ||
files: ['js/content.js'] | ||
, target: {tabId: tabid} | ||
}); | ||
} | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* content.js | ||
* Copyright (C) 2023 Element Davv<[email protected]> | ||
* | ||
* Distributed under terms of the GPL3 license. | ||
*/ | ||
|
||
(async () => { | ||
if (typeof window.content1ted === 'undefined' ) { | ||
const src = chrome.runtime.getURL('js/content1.js'); | ||
window.content1ted = await import(src); | ||
window.content1ted.default(); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* content1.js | ||
* Copyright (C) 2023 Element Davv<[email protected]> | ||
* | ||
* Distributed under terms of the GPL3 license. | ||
*/ | ||
|
||
export default function(){ | ||
'use strict'; | ||
|
||
function showDownload() { | ||
const items = document.getElementsByClassName('items'); | ||
if (items.length > 0) { | ||
const itemlist = items[0].children; | ||
for (var i = 0; i < itemlist.length; i++) { | ||
showForItem(itemlist[i]); | ||
} | ||
} | ||
else { | ||
showForBook(); | ||
} | ||
} | ||
|
||
async function showForBook() { | ||
const blues = document.getElementsByClassName('ui four column grid'); | ||
if (blues.length == 0) return; | ||
|
||
const blue = blues[0]; | ||
const links = await getDownloadLinks(document.URL); | ||
links.forEach((link, i) => { | ||
addButton(link, blue, 'afterend'); | ||
}); | ||
} | ||
|
||
async function showForItem(item) { | ||
const headers = item.getElementsByClassName('header'); | ||
const metas = item.getElementsByClassName('meta'); | ||
if (headers.length == 0) return; | ||
if (metas.length == 0) return; | ||
|
||
const header = headers[0]; | ||
const meta = metas[0]; | ||
const href = header.getAttribute('href'); | ||
const links = await getDownloadLinks(href); | ||
links.forEach((link, i) => { | ||
addButton(link, meta, 'beforeend'); | ||
}); | ||
} | ||
|
||
const base = 'https://taiwanebook.ncl.edu.tw/'; | ||
const classList = ['ui','blue', 'button'] | ||
|
||
function addButton(link, node, pos) { | ||
const a = document.createElement('a'); | ||
a.href = base + link; | ||
const fname = link.substring(link.lastIndexOf('/') + 1) | ||
a.download = fname; | ||
a.textContent = chrome.i18n.getMessage('download') + fname; | ||
classList.forEach((cls, j) => { | ||
a.classList.add(cls); | ||
}); | ||
node.insertAdjacentElement(pos, a); | ||
const br = document.createElement('br'); | ||
node.insertAdjacentElement(pos, br); | ||
} | ||
|
||
async function getDownloadLinks(url) { | ||
const response = await fetch(url+ '/reader'); | ||
if (response.ok) { | ||
const text = await response.text(); | ||
const re = /ebkFiles.*?PDF/g; | ||
const files = text.match(re); | ||
|
||
var links = []; | ||
if (files.length > 1) { | ||
for (var i = 0; i < files.length - 1; i++) { | ||
links.push(files[i]); | ||
} | ||
} | ||
else { | ||
links.push(files[0]); | ||
} | ||
} | ||
return links; | ||
} | ||
|
||
console.log('Taiwanebook Downloader v0.1.0 in action'); | ||
showDownload(); | ||
}; |
Oops, something went wrong.