-
Notifications
You must be signed in to change notification settings - Fork 0
/
tickerSet.html
88 lines (84 loc) · 3.31 KB
/
tickerSet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<html>
<head>
<title>Set the ticker!</title>
<link rel="stylesheet" href="styles.css">
<meta charset="UTF-8">
</head>
<body onload="loadMem()">
<label for="name">Custom header</label>
<input type="text" id="name" name="name" requiredminlength="4" maxlength="8" size="10">
<h1>One line = One ticker!</h1>
<div class="container1">
<textarea id="input"></textarea>
<a href="#saved" onclick="tickerSet()">
<div class="button">
Save text to ticker
</div>
</a>
<a href="ticker.html">
<div class="button">
Go to ticker
</div>
</a>
</div>
<script>
//when clicked
tickerSet = function () {
console.log("Saving text...");
//Short title
var title = document.getElementById("name");
if (title.value !== "") {
var titleArray = title.value;
console.log(titleArray);
if (!window.localStorage) alert("Sorry, you're using an ancient browser");
else {
localStorage.setItem("title", JSON.stringify(titleArray));
//localStorage.passArray = JSON.stringify(titleArray);
console.log(localStorage.getItem("title"));
}}
else {
//localStorage.clear("title");
var titleArray = "Latest";
console.log(titleArray);
if (!window.localStorage) alert("Sorry, you're using an ancient browser");
else {
localStorage.setItem("title", JSON.stringify(titleArray));
//localStorage.passArray = JSON.stringify(titleArray);
console.log(localStorage.getItem("title"));
}
}
console.log("Done");
//Main content
var area = document.getElementById("input");
if (area.value !== "") {
var linesArray = area.value.replace(/\r\n/g, "\n").split("\n");
console.log(linesArray);
if (!window.localStorage) alert("Sorry, you're using an ancient browser");
else {
localStorage.setItem("list", JSON.stringify(linesArray));
//localStorage.passArray = JSON.stringify(linesArray);
console.log(localStorage.getItem("list"));
}
//return linesArray;
} else {
localStorage.clear("list");
}
console.log("Done");
}
//Load previous content at start
loadMem = function () {
var title = document.getElementById("name");
var titleArray=[JSON.parse(localStorage.getItem("title"))]
title.value = titleArray[0];
var linesArray = localStorage.getItem("list");
var readingLines = JSON.parse(linesArray);
if (readingLines !== null) {
console.log(readingLines);
var area = document.getElementById("input");
area.value = readingLines.join("\n");
return linesArray;
}
}
</script>
</body>
</html>