Skip to content

Commit

Permalink
Add initial key-div element so applysettings can be called similarly …
Browse files Browse the repository at this point in the history
…to import
  • Loading branch information
zkharit committed Aug 27, 2024
1 parent 7b98614 commit ce44fcc
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions export/index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ <h2>Message log</h2>
>
</p>
<div id="message-log"></div>
<div id="key-div"></div>

<!-- Script containing ED25519 library -->
<script src="noble-hashes.js"></script>
Expand Down Expand Up @@ -768,6 +769,9 @@ <h2>Message log</h2>
*/
function applySettings(settings) {
const validSettings = {};
if (!settings) {
return JSON.stringify(validSettings);
}
const settingsObj = JSON.parse(settings);
if (settingsObj.styles) {
// Valid styles will be applied the "key-div" textarea HTML element.
Expand All @@ -778,10 +782,10 @@ <h2>Message log</h2>
);
}

// Validate, sanitize, and apply the styles to the "plaintext" textarea.
// Validate, sanitize, and apply the styles to the "key-div" textarea.
const validStyles = TKHQ.validateStyles(settingsObj.styles);
Object.entries(validStyles).forEach(([key, value]) => {
plaintextTextarea.style[key] = value;
keyDivTextarea.style[key] = value;
});

validSettings["styles"] = validStyles;
Expand Down Expand Up @@ -833,10 +837,10 @@ <h2>Message log</h2>
"DOMContentLoaded",
async () => {
// If styles are saved in local storage, sanitize and apply them.
// const styleSettings = TKHQ.getSettings();
// if (styleSettings) {
// TKHQ.applySettings(styleSettings);
// }
const styleSettings = TKHQ.getSettings();
if (styleSettings) {
TKHQ.applySettings(styleSettings);
}
await TKHQ.initEmbeddedKey();
const embeddedKeyJwk = await TKHQ.getEmbeddedKey();
const targetPubBuf = await TKHQ.p256JWKPrivateToPublic(
Expand Down Expand Up @@ -955,7 +959,7 @@ <h2>Message log</h2>
*/
function displayKey(key) {
Array.from(document.body.children).forEach((child) => {
if (child.tagName !== "SCRIPT") {
if (child.tagName !== "SCRIPT" && child.id !== "key-div") {
child.style.display = "none";
}
});
Expand All @@ -970,13 +974,13 @@ <h2>Message log</h2>
};

// Create a new div with the key material and append the new div to the body
const keyDiv = document.createElement("div");
keyDiv.id = "key-div";
const keyDiv = document.getElementById("key-div");
keyDiv.innerText = key;
for (let styleKey in style) {
keyDiv.style[styleKey] = style[styleKey];
}
document.body.appendChild(keyDiv);
TKHQ.applySettings(TKHQ.getSettings());
}

/**
Expand Down

0 comments on commit ce44fcc

Please sign in to comment.