基于油猴(Tampermonkey)插件
这个网上教程很多, 不多说
- 点击 油猴图标 ->管理面板->设置
- 通用->配置模式 选择
高级
- 下载BETA -> 下载模式选择
浏览器API
, 在下方文件扩展名白名单最后一行添加.pdf
扩展名
理论上没出问题的话, 就装好了, 可以去中文马克思主义文库看看是不是这样
// ==UserScript== | |
// @name Marxist downloader | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Downlaod PDF books from Marxists.org Chinese | |
// @author Mix <mnixry@users.noreply.github.com> | |
// @match https://www.marxists.org/chinese/pdf/* | |
// @grant GM_download | |
// @grant unsafeWindow | |
// ==/UserScript== | |
setInterval(() => { | |
const tables = document.querySelectorAll("td"); | |
for (const table of tables) { | |
if (table.id.trim() !== "") continue; | |
table.id = randomString(10); | |
table.innerHTML += /*html*/ ` | |
<button onclick="downloadPdf('${table.id}')">下载此部分</button> | |
`; | |
} | |
}, 2000); | |
/** | |
* @param {number} length | |
*/ | |
function randomString(length) { | |
const chars = | |
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
const result = new Array(length) | |
.fill(undefined) | |
.map(() => chars[Math.floor(Math.random() * chars.length)]); | |
return result.join(""); | |
} | |
/** | |
* @param {string} id | |
*/ | |
function downloadPdf(id) { | |
const table = document.getElementById(id); | |
for (const link of table.querySelectorAll("a")) { | |
const { href: path } = link; | |
if (typeof path !== "string" || !path.endsWith(".pdf")) continue; | |
const downloadUrl = new URL(path, location.href); | |
const filename = link.innerText.trim() + ".pdf"; | |
GM_download({ | |
url: downloadUrl.href, | |
name: filename, | |
onload: () => (link.innerText += "(已下载)"), | |
}); | |
} | |
} | |
unsafeWindow.downloadPdf = downloadPdf; |
基于油猴(Tampermonkey)插件
这个网上教程很多, 不多说
高级
浏览器API
, 在下方文件扩展名白名单最后一行添加.pdf
扩展名理论上没出问题的话, 就装好了, 可以去中文马克思主义文库看看是不是这样