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 = [ ``, `${title}`, ``, 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 = '成功'; })()