Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Uyanide committed Aug 25, 2024
1 parent 2e7895f commit 4d4202c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/scripts/listeners/UniversalListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,24 @@ function universalSetupEventListeners() {
document.getElementById('sidebar').addEventListener('click', DecodeListeners.showSidebar);

document.getElementById('downloadHtmlLink').addEventListener('click', () => {
// 重置侧边栏
PrismProcessor.DecodeList.clear();

if (applicationState.sidebarVisible) {
DecodeListeners.hideSidebar();
}
// 生成新的 HTML 文档,复制head
const currentHtml = document.documentElement.outerHTML;
const parser = new DOMParser();
const doc = parser.parseFromString(currentHtml, 'text/html');
const sourceElement = doc.getElementById('bodyContent');
const newDoc = document.implementation.createHTMLDocument('Filtered Document');
newDoc.head.innerHTML = doc.head.innerHTML;

// 添加离线状态标记
const script = newDoc.head.appendChild(newDoc.createElement('script'));
script.innerHTML = 'applicationState.isOffline = true;';

// 添加body属性
doc.body.classList.forEach(cls => newDoc.body.classList.add(cls));

// 添加body内容,排除某些插件写入的元素
newDoc.body.appendChild(newDoc.importNode(sourceElement, true));

const a = document.createElement('a');
Expand Down

0 comments on commit 4d4202c

Please sign in to comment.