start on copying, fix saving
This commit is contained in:
parent
b664bb8d26
commit
14636b269e
@ -329,6 +329,9 @@ class PoemSaver extends HTMLFormElement {
|
||||
connectedCallback() {
|
||||
this.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
if (e.submitter.innerText == "copy") {
|
||||
// TODO
|
||||
} else {
|
||||
const saveType = this.querySelector("input[name=type]");
|
||||
const includeSources = this.querySelector("input[name=sources]").checked;
|
||||
if (saveType.value == "text") {
|
||||
@ -336,13 +339,14 @@ class PoemSaver extends HTMLFormElement {
|
||||
} else {
|
||||
this.saveImage(includeSources);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
saveText(includeSources) {
|
||||
var text = "";
|
||||
var sources = "";
|
||||
$$(".line").forEach((e) => {
|
||||
$$(".linetext").forEach((e) => {
|
||||
text += e.innerText + "\n";
|
||||
sources += e.dataset.source + "\n"
|
||||
})
|
||||
@ -350,12 +354,8 @@ class PoemSaver extends HTMLFormElement {
|
||||
text += "\n\nsources:\n" + sources;
|
||||
}
|
||||
|
||||
// TODO getting the line controls included
|
||||
// TODO timestamp has decimal place
|
||||
// TODO sources undefined
|
||||
|
||||
const blob = new Blob([text], {type: "text/plain"});
|
||||
const fname = `trunkless-poem-${Date.now()/1000}.txt`
|
||||
const fname = `trunkless-poem-${Math.trunc(Date.now()/1000)}.txt`
|
||||
const dlink = document.createElement("a");
|
||||
dlink.download = fname;
|
||||
dlink.href = window.URL.createObjectURL(blob);
|
||||
|
@ -63,6 +63,7 @@ span.linetext {
|
||||
<input name="type" value="text" type="radio" checked="true"/>as text
|
||||
<input name="type" value="image" type="radio"/>as image
|
||||
<input name="sources" type="checkbox"/>include sources
|
||||
<button type="submit">copy</button>
|
||||
<button type="submit">save</button>
|
||||
</form>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user