Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A small improvement #3

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lore-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2>Guide</h2>

<div id="lore-input" class="box">
<h2>Lore Input</h2>
<textarea id="lore-textarea" placeholder="Type your lore here..." autofocus></textarea>
<textarea id="lore-textarea" placeholder="Type your lore here..." autofocus autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
</div>

<div id="live-preview">
Expand Down
37 changes: 34 additions & 3 deletions lore-generator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ document.addEventListener("DOMContentLoaded", function () {
if (formatting.obfuscated) classes.push("obfuscated");
if (formatting.underline) classes.push("underline");
if (formatting.strikethrough) classes.push("strikethrough");
const classAttr = classes.length ? ` class="${classes.join(" ")}"` : "";
return `<span style="${style}"${classAttr}>${escapeHtml(content)}</span>`;
const classAttr = classes.length ? ` class='${classes.join(" ")}'` : "";
return `<span style='${style}'${classAttr}>${escapeHtml(content)}</span>`;
}

return result;
Expand Down Expand Up @@ -227,6 +227,7 @@ document.addEventListener("DOMContentLoaded", function () {

const buttonGroup = document.createElement("div");
buttonGroup.classList.add("button-group");
buttonGroup.classList.add("column");

const restoreButton = document.createElement("button");
restoreButton.textContent = "Restore";
Expand All @@ -242,8 +243,23 @@ document.addEventListener("DOMContentLoaded", function () {
navigator.clipboard.writeText(lore.code).then(showCopyNotification);
});

buttonGroup.appendChild(restoreButton);
const deleteButton = document.createElement("button");
deleteButton.textContent = "Delete";
deleteButton.addEventListener("click", function () {
savedLores = savedLores.filter((l) => l.code !== lore.code);
saveLoresToLocalStorage();
updateSavedLores();
});

const container = document.createElement("div");
container.classList.add("lore-container");
loreDiv.appendChild(container);

createLorePreview(container, lore.text);

buttonGroup.appendChild(copyButton);
buttonGroup.appendChild(restoreButton);
buttonGroup.appendChild(deleteButton);
loreDiv.appendChild(buttonGroup);
savedLoresContainer.appendChild(loreDiv);
});
Expand All @@ -261,5 +277,20 @@ document.addEventListener("DOMContentLoaded", function () {
}
}

function createLorePreview(parent, text) {
const previewContainer = document.createElement("div");
previewContainer.classList.add("preview-tooltip");
const preview = document.createElement("div");
previewContainer.appendChild(preview);
const lines = text.split("\n");
lines.forEach((line) => {
const lineElement = document.createElement("div");
lineElement.classList.add("preview-line");
lineElement.innerHTML = parseSkriptFormatting(line);
preview.appendChild(lineElement);
});
parent.appendChild(previewContainer);
}

updateOutput();
});
24 changes: 19 additions & 5 deletions lore-generator/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,13 @@ body.dark-mode {
display: inline-block;
}

#preview-content {
.preview-line {
font-family: "Minecraftia", monospace;
white-space: pre;
font-size: 14px;
line-height: 1.2;
}

.preview-line {
white-space: pre;
}

#generated-code {
margin-top: 20px;
}
Expand All @@ -131,6 +127,10 @@ body.dark-mode {
margin-top: 10px;
}

.column {
flex-direction: column;
}

.button-group button {
padding: 10px 20px;
background-color: var(--box-background-color);
Expand Down Expand Up @@ -204,6 +204,20 @@ body.dark-mode {
background-color: var(--hover-background-color);
}

.saved-lore pre {
background-color: var(--box-background-color);
color: var(--text-color);
padding: 5px;
border: 1px solid var(--box-border-color);
border-radius: 4px;
overflow-x: auto;
text-align: left;
min-height: calc(1.2em + 10px);
max-height: calc(1.2em * 3 + 10px);
box-sizing: border-box;
width: 90%;
}

.header-content {
max-width: 800px;
margin: 0 auto;
Expand Down