-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-cleaner.html
More file actions
156 lines (138 loc) · 4.33 KB
/
code-cleaner.html
File metadata and controls
156 lines (138 loc) · 4.33 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CSS Scrubber | tools.eliana.lol</title>
<link rel="stylesheet" href="global.css" />
<link rel="icon" type="image/x-icon" href="favicon.svg" />
<style>
/* Specific Tool Layout */
#input,
#output {
width: 100%;
margin-bottom: 10px;
}
#output {
background: var(--hover);
}
iframe#preview {
width: 100%;
height: 300px;
border: 1px solid var(--puny);
background: white;
margin-top: 5px;
}
.tool-actions {
margin: 15px 0;
display: flex;
gap: 8px;
}
label {
display: block;
margin-top: 15px;
font-weight: bold;
font-size: 0.8rem;
color: var(--puny);
}
</style>
</head>
<body>
<nav>
<div class="left">
<a href="index.html">home</a> | <a href="extra.html">extra</a> |
<a href="credits.html">credits</a> |
<a href="changelog.html">logs</a>
</div>
<div class="right">
<button id="theme-toggle">[theme]</button> |
<a href="https://eliana.lol">site</a>
</div>
</nav>
<main>
<h1>CSS Scrubber</h1>
<p class="puny">
Paste HTML to strip styles, then see the "naked" structure below.
</p>
<textarea
id="input"
rows="8"
placeholder="Paste messy HTML here..."
></textarea>
<div class="tool-actions">
<button
id="scrubBtn"
style="border-color: var(--accent); font-weight: bold"
>
✨ Scrub & Preview
</button>
<button id="copyBtn">Copy Code</button>
<button id="clearBtn">Clear</button>
</div>
<label>Clean HTML Code:</label>
<textarea id="output" rows="8" readonly></textarea>
<label>Live Naked Preview:</label>
<iframe id="preview"></iframe>
</main>
<script>
const htmlDoc = document.documentElement;
const toggle = document.getElementById('theme-toggle');
const saved =
localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light');
htmlDoc.setAttribute('data-theme', saved);
if (toggle) toggle.innerText = saved === 'dark' ? '[light]' : '[dark]';
if (toggle) {
toggle.onclick = () => {
const now = htmlDoc.getAttribute('data-theme');
const next = now === 'dark' ? 'light' : 'dark';
htmlDoc.setAttribute('data-theme', next);
localStorage.setItem('theme', next);
toggle.innerText = next === 'dark' ? '[light]' : '[dark]';
};
}
</script>
<script>
const input = document.getElementById('input');
const output = document.getElementById('output');
const preview = document.getElementById('preview');
document.getElementById('scrubBtn').onclick = () => {
let html = input.value;
// 1. Strip Styles & CSS links
html = html.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '');
html = html.replace(/<link[^>]+rel=["']stylesheet["'][^>]*>/gi, '');
html = html.replace(/\sstyle=(['"])(.*?)\1/gi, '');
// 2. Clean whitespace
html = html
.split('\n')
.filter((line) => line.trim() !== '')
.join('\n');
output.value = html;
// 3. Update Preview
const doc = preview.contentDocument || preview.contentWindow.document;
doc.open();
doc.write(html);
doc.close();
};
document.getElementById('copyBtn').onclick = () => {
if (!output.value) return;
navigator.clipboard.writeText(output.value);
const old = document.getElementById('copyBtn').innerText;
document.getElementById('copyBtn').innerText = 'Copied!';
setTimeout(() => {
document.getElementById('copyBtn').innerText = old;
}, 1500);
};
document.getElementById('clearBtn').onclick = () => {
input.value = '';
output.value = '';
const doc = preview.contentDocument || preview.contentWindow.document;
doc.open();
doc.write('');
doc.close();
};
</script>
</body>
</html>