261 lines
9.8 KiB
Go
261 lines
9.8 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
const SharedCSS = `
|
|
:root {
|
|
color-scheme: dark;
|
|
--tool-gap-sm: 8px;
|
|
--tool-gap-md: 12px;
|
|
--tool-gap-lg: 16px;
|
|
--tool-radius: 5px;
|
|
--tool-border: #333;
|
|
--tool-panel: #252526;
|
|
}
|
|
* { box-sizing: border-box; }
|
|
html { min-height: 100%; }
|
|
body {
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
background: #1e1e1e; color: #ddd;
|
|
margin: 0; padding: 0;
|
|
}
|
|
.topbar {
|
|
display: flex; align-items: center; gap: 8px;
|
|
padding: 8px 16px; background: #252526; border-bottom: 1px solid #333;
|
|
font-size: 13px;
|
|
}
|
|
.topbar .nav-link {
|
|
background: transparent;
|
|
color: #ddd;
|
|
border: 0;
|
|
padding: 5px 10px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font: inherit;
|
|
}
|
|
.topbar .nav-link:hover { background: #2a2d2e; }
|
|
.topbar .nav-link.active { background: #094771; color: #fff; }
|
|
.beta-pill { margin-left: 4px; padding: 1px 4px; border: 1px solid #555; border-radius: 3px; font-size: 10px; opacity: 0.7; text-transform: uppercase; }
|
|
.topbar-spacer { margin-left: auto; }
|
|
.content { flex: 1; width: 100%; padding: 18px; max-width: 1100px; margin: 0 auto; }
|
|
.app-footer {
|
|
width: 100%;
|
|
max-width: 1100px;
|
|
margin: auto auto 0;
|
|
padding: 8px 18px 14px;
|
|
display: grid;
|
|
grid-template-columns: 1fr auto 1fr;
|
|
align-items: center;
|
|
gap: 8px;
|
|
color: #a7a7a7;
|
|
font-size: 10px;
|
|
border-top: 1px solid #333;
|
|
}
|
|
.beta-tools-toggle {
|
|
justify-self: start;
|
|
padding: 0;
|
|
background: transparent;
|
|
color: #a7a7a7;
|
|
border: 0;
|
|
cursor: pointer;
|
|
font: inherit;
|
|
opacity: 0.72;
|
|
text-align: left;
|
|
}
|
|
.beta-tools-toggle:hover { background: transparent; opacity: 1; text-decoration: underline; }
|
|
.app-footer-version { opacity: 0.75; text-align: center; white-space: nowrap; }
|
|
.app-footer-link { justify-self: end; padding: 0; background: transparent; color: #a7a7a7; border: 0; cursor: pointer; font: inherit; opacity: 0.72; }
|
|
.app-footer-link:hover { background: transparent; opacity: 1; text-decoration: underline; }
|
|
h2 { margin: 0; font-size: 18px; line-height: 1.25; font-weight: 600; }
|
|
.tool-header { margin-bottom: var(--tool-gap-lg); }
|
|
.tool-title { margin: 0; font-size: 18px; line-height: 1.25; font-weight: 600; }
|
|
.tool-description, .section-description, .muted { color: #a7a7a7; }
|
|
.tool-description { margin: 5px 0 0; max-width: 780px; font-size: 12px; line-height: 1.45; }
|
|
.tool-panel { margin-bottom: var(--tool-gap-lg); border: 1px solid var(--tool-border); border-radius: var(--tool-radius); background: rgba(128,128,128,0.08); overflow: hidden; }
|
|
.panel-header { padding: 10px 12px; border-bottom: 1px solid var(--tool-border); background: var(--tool-panel); }
|
|
.panel-title { margin: 0; color: #ddd; font-size: 12px; font-weight: 700; letter-spacing: 0.45px; text-transform: uppercase; }
|
|
.panel-body { padding: 12px; }
|
|
.control-group + .control-group { margin-top: var(--tool-gap-md); }
|
|
.control-label { margin: 0 0 6px; color: #a7a7a7; font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; }
|
|
.file-row, .field-row, .action-row { display: flex; align-items: center; gap: var(--tool-gap-sm); flex-wrap: wrap; }
|
|
.action-row { margin-top: var(--tool-gap-md); }
|
|
input[type=text], input[type=date], select, textarea {
|
|
box-sizing: border-box; padding: 6px 8px;
|
|
background: #3c3c3c; color: #ddd;
|
|
border: 1px solid #3c3c3c; border-radius: 2px;
|
|
font-family: inherit; font-size: 13px;
|
|
}
|
|
input[type=text]:focus, input[type=date]:focus, select:focus, textarea:focus {
|
|
outline: 1px solid #007fd4; border-color: #007fd4;
|
|
}
|
|
button {
|
|
background: #0e639c; color: #fff;
|
|
border: none; padding: 6px 14px; border-radius: 2px; cursor: pointer; font-size: 13px;
|
|
}
|
|
button:hover { background: #1177bb; }
|
|
button.secondary { background: #3a3d41; color: #ddd; }
|
|
button.secondary:hover { background: #45494e; }
|
|
button.danger { background: transparent; color: #f48771; border: 1px solid #444; }
|
|
button.danger:hover { background: rgba(244,135,113,0.14); }
|
|
button:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
.status-panel, .results-panel, .result-card { border: 1px solid var(--tool-border); border-radius: var(--tool-radius); background: rgba(128,128,128,0.08); }
|
|
.status-panel { min-height: 30px; margin-top: var(--tool-gap-md); padding: 8px 10px; white-space: pre-wrap; }
|
|
.status-panel:empty { display: none; }
|
|
.results-panel { margin-top: var(--tool-gap-md); overflow: auto; }
|
|
.results-panel:empty { display: none; }
|
|
.result-card { padding: 10px; word-break: break-word; }
|
|
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
|
|
.data-table th, .data-table td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--tool-border); }
|
|
.data-table th { color: #a7a7a7; font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; background: var(--tool-panel); }
|
|
.data-table tr:last-child td { border-bottom: none; }
|
|
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
|
|
.wrap { overflow-wrap: anywhere; word-break: break-word; }
|
|
.file-name { color: #a7a7a7; font-size: 12px; overflow-wrap: anywhere; }
|
|
.selected-list, .selected-files { margin-top: 8px; }
|
|
.remove-selected, .remove-btn { min-width: 28px; width: 28px; padding: 3px 0; color: #f48771; font-size: 16px; line-height: 1; }
|
|
.pager { margin-top: 8px; display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
|
|
.badge { display: inline-flex; align-items: center; min-height: 18px; padding: 1px 6px; border-radius: 999px; border: 1px solid #444; font-size: 11px; line-height: 1.2; white-space: nowrap; }
|
|
.badge.ok { color: #89d185; background: rgba(137,209,133,0.12); }
|
|
.badge.err { color: #f48771; background: rgba(244,135,113,0.14); }
|
|
.badge.warn { color: #ffd580; background: rgba(210,153,34,0.16); }
|
|
.is-hidden { display: none !important; }
|
|
.err { color: #f48771; white-space: pre-wrap; }
|
|
.ok { color: #89d185; }
|
|
.hint { font-size: 12px; opacity: 0.7; }
|
|
`
|
|
|
|
type navItem struct {
|
|
Path string
|
|
Label string
|
|
Description string
|
|
Beta bool
|
|
}
|
|
|
|
var navItems = []navItem{
|
|
{Path: "/", Label: "Home"},
|
|
{Path: "/plec", Label: "PLEC Upload", Description: "Upload HTML to the internal PLEC server"},
|
|
{Path: "/applovin", Label: "AppLovin Playable Preview", Description: "Upload to p.applov.in (QR preview)"},
|
|
{Path: "/base64", Label: "Base64 Scanner", Description: "Find non-base64 assets in HTML"},
|
|
{Path: "/mraid", Label: "MRAID Checker", Description: "Check MRAID requirements and best practices", Beta: true},
|
|
{Path: "/mobile", Label: "Send To Mobile", Description: "Share HTML to a phone via LAN + QR"},
|
|
{Path: "/playworks", Label: "Playworks Converter", Description: "Convert Playworks HTML to per-network variants", Beta: true},
|
|
}
|
|
|
|
func visibleNavItems(betaToolsEnabled bool) []navItem {
|
|
out := make([]navItem, 0, len(navItems))
|
|
for _, n := range navItems {
|
|
if n.Beta && !betaToolsEnabled {
|
|
continue
|
|
}
|
|
out = append(out, n)
|
|
}
|
|
return sortNavItemsForDisplay(out)
|
|
}
|
|
|
|
func sortNavItemsForDisplay(items []navItem) []navItem {
|
|
out := append([]navItem(nil), items...)
|
|
for i := 0; i < len(out); i++ {
|
|
for j := i + 1; j < len(out); j++ {
|
|
if out[i].Beta && !out[j].Beta {
|
|
out[i], out[j] = out[j], out[i]
|
|
}
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func betaToolCount() int {
|
|
count := 0
|
|
for _, n := range navItems {
|
|
if n.Beta {
|
|
count++
|
|
}
|
|
}
|
|
return count
|
|
}
|
|
|
|
func Page(activePath, title, body string) string {
|
|
cfg := LoadConfig()
|
|
betaToolsEnabled := cfg.BetaToolsEnabled
|
|
var tabs strings.Builder
|
|
for _, n := range visibleNavItems(betaToolsEnabled) {
|
|
cls := ""
|
|
if n.Path == activePath {
|
|
cls = " active"
|
|
}
|
|
label := n.Label
|
|
if n.Beta {
|
|
label += `<span class="beta-pill">Beta</span>`
|
|
}
|
|
tabs.WriteString(`<button type="button" class="nav-link` + cls + `" data-path="` + n.Path + `">` + label + `</button>`)
|
|
}
|
|
|
|
betaButtonLabel := "Show beta"
|
|
if betaToolsEnabled {
|
|
betaButtonLabel = "Hide beta"
|
|
}
|
|
|
|
return `<!DOCTYPE html>
|
|
<html><head>
|
|
<meta charset="UTF-8" />
|
|
<title>` + title + ` — HPL Toolbox</title>
|
|
<style>` + SharedCSS + `</style>
|
|
</head><body>
|
|
<div class="topbar">` + tabs.String() + `<span class="topbar-spacer"></span></div>
|
|
<div class="content">` + body + `</div>
|
|
<div class="app-footer">
|
|
<button id="betaToolsToggle" class="beta-tools-toggle" data-enabled="` + boolAttr(betaToolsEnabled) + `">` + betaButtonLabel + `</button>
|
|
<span class="app-footer-version">` + AppVersion + ` - JJGC 00784</span>
|
|
<button type="button" class="app-footer-link" data-path="/changelog">Changelog</button>
|
|
</div>
|
|
<script>
|
|
document.querySelectorAll('[data-path]').forEach((element) => {
|
|
element.addEventListener('click', () => {
|
|
const path = element.dataset.path;
|
|
if (path) window.location.href = path;
|
|
});
|
|
});
|
|
document.getElementById('betaToolsToggle').addEventListener('click', async (event) => {
|
|
const enabled = event.currentTarget.dataset.enabled === 'true';
|
|
await fetch('/api/betaTools', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ enabled: !enabled }),
|
|
});
|
|
window.location.reload();
|
|
});
|
|
</script>
|
|
</body></html>`
|
|
}
|
|
|
|
func boolAttr(v bool) string {
|
|
if v {
|
|
return "true"
|
|
}
|
|
return "false"
|
|
}
|
|
|
|
func BetaToolsEndpoint(w http.ResponseWriter, r *http.Request) {
|
|
var req struct {
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeJSON(w, map[string]any{"ok": false, "error": err.Error()})
|
|
return
|
|
}
|
|
cfg := LoadConfig()
|
|
cfg.BetaToolsEnabled = req.Enabled
|
|
if err := SaveConfig(cfg); err != nil {
|
|
writeJSON(w, map[string]any{"ok": false, "error": err.Error()})
|
|
return
|
|
}
|
|
writeJSON(w, map[string]any{"ok": true})
|
|
}
|