refactors

This commit is contained in:
lda committed 2025-12-24 01:01:47 +07:00
1 parent 218e0374d2
commit e61c34bc0d
1 file changed
+128 -48
+128 -48
View File
@@ -13,6 +13,7 @@
--error-color: #cf6679;
--success-color: #03dac6;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
@@ -20,11 +21,12 @@
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 20px;
box-sizing: border-box;
min-height: 100lvh;
}
.card {
background-color: var(--surface-color);
padding: 2rem;
@@ -35,11 +37,13 @@
text-align: center;
border: 1px solid #333;
}
h1 {
margin-top: 0;
color: var(--error-color);
font-size: 1.8rem;
}
p {
line-height: 1.5;
margin-bottom: 1.5rem;
@@ -56,6 +60,7 @@
box-sizing: border-box;
font-size: 1rem;
}
input:focus {
outline: 2px solid var(--primary-color);
border-color: transparent;
@@ -67,6 +72,7 @@
justify-content: center;
margin-top: 20px;
}
button {
padding: 12px 24px;
border: none;
@@ -76,22 +82,27 @@
font-size: 1rem;
transition: transform 0.1s, opacity 0.2s;
}
button:active {
transform: scale(0.98);
}
button.primary {
background-color: var(--error-color);
color: #000;
}
button.create-btn {
background-color: var(--primary-color);
color: #000;
}
button.secondary {
background-color: #333;
color: #fff;
border: 1px solid #444;
}
button:hover {
opacity: 0.9;
}
@@ -108,6 +119,7 @@
border: 1px solid #333;
text-align: left;
}
.link-display {
word-break: break-all;
color: var(--primary-color);
@@ -115,6 +127,7 @@
display: block;
font-family: monospace;
}
.copy-feedback {
display: none;
color: var(--success-color);
@@ -123,6 +136,7 @@
opacity: 0;
transition: opacity 0.3s;
}
.copy-feedback.show {
opacity: 1;
display: unset;
@@ -133,15 +147,53 @@
font-size: 0.8rem;
color: #666;
}
footer a {
color: #888;
text-decoration: none;
}
footer a:hover {
text-decoration: underline;
}
/* Utility Classes */
.text-primary {
color: var(--primary-color);
}
.text-muted {
color: #888;
font-size: 0.9em;
}
.mb-small {
margin: 0 0 5px 0;
}
.btn-full {
width: 100%;
padding: 8px;
}
.warning-box {
background: #252525;
padding: 10px;
border-radius: 4px;
margin-bottom: 20px;
text-align: left;
}
.destination-url {
color: white;
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<div class="card" id="app">
<!-- Content injected by JS -->
@@ -154,9 +206,8 @@
return btoa(
encodeURIComponent(str).replace(
/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode("0x" + p1);
}
/* toSolidBytes */ (match, p1) =>
String.fromCharCode(`0x${p1}`)
)
)
.replace(/\+/g, "-")
@@ -169,40 +220,54 @@
return decodeURIComponent(
atob(str)
.split("")
.map(function (c) {
return (
"%" +
("00" + c.charCodeAt(0).toString(16)).slice(
-2
)
);
})
.map(
(c) =>
`%${(
"00" + c.charCodeAt(0).toString(16)
).slice(-2)}`
)
.join("")
);
},
};
const html = (strings, ...values) =>
String.raw({ raw: strings }, ...values); // mdn
const app = document.getElementById("app");
const params = new URLSearchParams(location.search);
const redirectParam = params.get("redirect");
// --- Views ---
const renderCreator = () => {
app.innerHTML = /* html */ `
<h1 style="color: var(--primary-color)">Shield Generator</h1>
<p>Create a warning wrapper for NSFW or sensitive links.</p>
<input type="url" id="urlInput" placeholder="https://example.com/sensitive-content" autocomplete="off" />
<div class="buttons">
<button class="create-btn" onclick="generateLink()">Generate Shield</button>
</div>
<div id="result-area" class="hidden">
<p style="margin:0 0 5px 0; font-size:0.8em; color:#888;">Your Shielded Link:</p>
<a id="generatedLink" href="#" target="_blank" class="link-display"></a>
<button class="secondary" style="width:100%; padding: 8px;" onclick="copyLink()">
Copy to Clipboard <span id="copyMsg" class="copy-feedback">Copied!</span>
</button>
</div>
`;
app.innerHTML = html`
<h1 class="text-primary">Shield Generator</h1>
<p>Create a warning wrapper for NSFW or sensitive links.</p>
<input
type="url"
id="urlInput"
placeholder="https://example.com/sensitive-content"
autocomplete="off"
/>
<div class="buttons">
<button class="create-btn" onclick="generateLink()">
Generate Shield
</button>
</div>
<div id="result-area" class="hidden">
<p class="text-muted mb-small">Your Shielded Link:</p>
<a
id="generatedLink"
href="#"
target="_blank"
class="link-display"
></a>
<button class="secondary btn-full" onclick="copyLink()">
Copy to Clipboard
<span id="copyMsg" class="copy-feedback"
>Copied!</span
>
</button>
</div>
`;
setTimeout(
() => document.getElementById("urlInput").focus(),
@@ -222,21 +287,36 @@
domain = new URL(targetUrl).href;
} catch (e) {}
app.innerHTML = /* html */ `
<h1>NSFW Warning</h1>
<p>The link you are about to visit contains content marked as <strong>Not Safe For Work</strong>.</p>
<div style="background: #252525; padding: 10px; border-radius: 4px; margin-bottom: 20px; text-align: left;">
<span style="color: #888; font-size: 0.9em;">Destination:</span><br>
<strong style="color: white; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title="${domain}">${domain}</strong>
</div>
<div class="buttons">
<button class="secondary" onclick="goBack()">I'm out</button>
<button class="primary" onclick="proceed('${targetUrl}')">Proceed</button>
</div>
<footer>
<a href="${location.pathname}">Create your own shield</a>
</footer>
`;
app.innerHTML = html`
<h1>NSFW Warning</h1>
<p>
The link you are about to visit contains content marked
as
<strong>Not Safe For Work</strong>.
</p>
<div class="warning-box">
<span class="text-muted">Destination:</span><br />
<strong class="destination-url" title="${domain}"
>${domain}</strong
>
</div>
<div class="buttons">
<button class="secondary" onclick="goBack()">
I'm out
</button>
<button
class="primary"
onclick="proceed('${targetUrl}')"
>
Proceed
</button>
</div>
<footer>
<a href="${location.pathname}"
>Create your own shield</a
>
</footer>
`;
};
// --- Actions ---
@@ -256,7 +336,9 @@
new URL(rawUrl);
const encoded = Base64.encode(rawUrl);
const shieldUrl = `${location.origin}${location.pathname}?redirect=${encoded}`;
const shieldUrl = new URL(location);
shieldUrl.search = "";
shieldUrl.searchParams.append("redirect", encoded);
link.href = shieldUrl;
link.textContent = shieldUrl;
@@ -277,10 +359,8 @@
};
window.goBack = () => {
if (history.length > 1) history.back();
else {
window.close();
}
history.back();
if (history.length <= 1) window.close();
const newURL = new URL(window.location);
newURL.search = "";
window.location.replace(newURL);