-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathview.html
More file actions
140 lines (129 loc) · 6.13 KB
/
view.html
File metadata and controls
140 lines (129 loc) · 6.13 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Slate - Viewer</title>
<link rel="icon" type="image/png" href="./icon.png" />
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500&display=swap" rel="stylesheet">
<script src="./dist/base64js.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/lzma@2.3.2/src/lzma_worker.min.js"></script>
</head>
<body>
<div class="container">
<div class="editor-header">
<div class="header-left">
<h1 id="headerTitle" class="view-title"></h1>
</div>
<div class="header-right">
<button onclick="handleEdit()">Edit</button>
<button onclick="window.location.href='index.html'">Create New</button>
</div>
</div>
<div id="viewer">
<div id="content" class="view-content" style="color: var(--text-color);"></div>
</div>
<div class="editor-footer">
<div class="footer-content">
<button id="themeButton" class="theme-switch" title="Toggle dark/light mode">
<svg class="light-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
<svg class="dark-icon" style="display: none;" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
</svg>
</button>
Made with ♥ by Shouvik Mitra
</div>
</div>
</div>
<script>
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
function Base64Decode(str) {
return new Promise((resolve, reject) => {
if (!str) resolve('');
try {
str = str.replace(/-/g, '+').replace(/_/g, '/');
while (str.length % 4) str += '=';
const bytes = base64js.toByteArray(str);
LZMA.decompress(Array.from(bytes), (result, error) => {
if (error) reject(error);
resolve(result);
});
} catch (e) {
console.error('Error decoding:', e);
reject(e);
}
});
}
function handleEdit() {
const title = document.getElementById('headerTitle').textContent;
const content = document.getElementById('content').textContent;
const encodedTitle = encodeURIComponent(title);
const encodedContent = encodeURIComponent(content);
window.location.href = `index.html?edit=true&t=${encodedTitle}&c=${encodedContent}`;
}
// Theme functions
function initTheme() {
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', savedTheme);
updateThemeIcons(savedTheme);
}
function toggleTheme() {
const currentTheme = document.documentElement.getAttribute('data-theme') || 'light';
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcons(newTheme);
}
function updateThemeIcons(theme) {
const lightIcon = document.querySelector('.light-icon');
const darkIcon = document.querySelector('.dark-icon');
if (theme === 'dark') {
lightIcon.style.display = 'none';
darkIcon.style.display = 'block';
} else {
lightIcon.style.display = 'block';
darkIcon.style.display = 'none';
}
}
document.addEventListener('DOMContentLoaded', async () => {
try {
const title = getParameterByName('t');
const content = getParameterByName('c');
const [decodedTitle, decodedContent] = await Promise.all([
Base64Decode(title),
Base64Decode(content)
]);
const headerTitle = document.getElementById('headerTitle');
headerTitle.textContent = decodedTitle || 'Untitled document';
document.getElementById('content').textContent = decodedContent;
document.title = `${decodedTitle || 'Untitled'} - Slate Viewer`;
// Initialize theme
initTheme();
document.getElementById('themeButton').addEventListener('click', toggleTheme);
} catch (e) {
console.error('Error displaying content:', e);
}
});
</script>
</body>
</html>