-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathraw.js
96 lines (89 loc) · 3.43 KB
/
raw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(function () {
try {
var articles = document.querySelectorAll('article');
var timestamp = new Date().toLocaleString();
// HTML Template
var htmlContent = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Chat Export</title>
<link rel="stylesheet" href="https://unpkg.com/mvp.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/default.min.css">
<link rel="stylesheet" href="https://ulrischa.github.io/chat_pager/chat_pager_style.css">
</head>
<body>
<h1><a href="${window.location.href}" target="_blank">${window.location.href}</a></h1>
<div class="timestamp">Exported on: ${timestamp}</div>
<div class="chat-container">
`;
// Process articles and add messages
articles.forEach(function (article, index) {
var messageContent = article.querySelector('.whitespace-pre-wrap, .markdown');
var imagesHtml = '';
if (messageContent) {
var images = article.querySelectorAll('img[width][height]');
images.forEach(function (image) {
imagesHtml += image.outerHTML;
});
htmlContent += `
<div class="chat-message ${index % 2 === 0 ? 'right' : 'left'}">
<div class="chat-bubble ${index % 2 === 0 ? 'right' : 'left'}">
${imagesHtml}${messageContent.innerHTML}
</div>
</div>
`;
}
});
// Close HTML content
htmlContent += `
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script>
hljs.highlightAll();
document.querySelectorAll("button.flex.gap-1.items-center.select-none.py-1").forEach(btn => {
btn.addEventListener("click", function () {
var pre = btn.closest("pre");
if (pre) {
var code = pre.querySelector("code");
if (code) {
var textarea = document.createElement("textarea");
textarea.value = code.innerText;
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand("copy");
alert("Code copied to clipboard.");
} catch (e) {
alert("Failed to copy code.");
}
document.body.removeChild(textarea);
}
}
});
});
</script>
</body>
</html>
`;
// Copy to clipboard
var textarea = document.createElement('textarea');
textarea.value = htmlContent;
textarea.setAttribute('readonly', '');
textarea.style.position = 'absolute';
textarea.style.left = '-9999px';
document.body.appendChild(textarea);
textarea.select();
var success = document.execCommand('copy');
document.body.removeChild(textarea);
// Notify the user
if (success) {
alert('Complete HTML file with syntax highlighting and timestamp copied to clipboard.');
} else {
alert('Failed to copy the content.');
}
} catch (error) {
alert('Error: ' + error);
}
})();