35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
javascript: (function () {
|
||
/* 保存知乎电子书 - 浏览器书签 */
|
||
/* 适用页面:https://www.zhihu.com/pub/reader/120208917 */
|
||
/* 编写时间:2023-07-13 */
|
||
let title = document.querySelector('.is-current').querySelector('.chapter-hover-title').childNodes[0].textContent;
|
||
let html = document.querySelector('.ZhihuEPub')?.innerHTML;
|
||
if (!html) {
|
||
html = document.querySelector('.PubHTML')?.childNodes[0]?.childNodes[0]?.innerHTML;
|
||
}
|
||
|
||
let cssPath = "main.css";
|
||
/* let level2 = document.querySelector('.is-current').classList.contains('level-2') */
|
||
const level = Number(document.querySelector('.is-current').classList[0].replace('level-', ''));
|
||
for (let i = 1; i < level; i++) {
|
||
cssPath = '../' + cssPath
|
||
}
|
||
|
||
let saveHTML = [
|
||
`<html>`,
|
||
`<head><meta charset="UTF-8"><title>${title}</title><link rel="stylesheet" href="${cssPath}"></head>`,
|
||
`<body class="ZhihuEPub">`,
|
||
html,
|
||
`</body>`,
|
||
`</html>`
|
||
].join('\n');
|
||
console.log({ title, html, saveHTML });
|
||
const blob = new Blob([saveHTML], { type: 'text/html' });
|
||
const objectURL = URL.createObjectURL(blob);
|
||
const aTag = document.createElement('a');
|
||
aTag.href = objectURL;
|
||
aTag.download = title + '.html';
|
||
aTag.click();
|
||
URL.revokeObjectURL(objectURL);
|
||
document.querySelector('.reader-buttons').innerText = '成功';
|
||
})() |