-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
69 lines (62 loc) · 1.98 KB
/
app.js
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
function copyText(textToCopy) {
var myTemporaryInputElement = document.createElement("input");
myTemporaryInputElement.type = "text";
myTemporaryInputElement.value = textToCopy;
document.body.appendChild(myTemporaryInputElement);
myTemporaryInputElement.select();
document.execCommand("Copy");
document.body.removeChild(myTemporaryInputElement);
};
var app = new Vue({
el: '#app',
data: {
current: '',
history: [],
historyString: ''
},
methods: {
onEnter: function() {
this.history.push(this.current);
this.current = '';
this.historyString = (this.history.map(
function (s) {
if (s == "") {
return "\n";
} else if (s.endsWith('.') || s.endsWith('!') || s.endsWith('?') || s.endsWith(':')) {
return s;
} else {
return s + ".";
}
}
).join(' '));
localStorage.history = JSON.stringify(this.history);
localStorage.current = this.current;
localStorage.historyString = this.historyString;
},
copy: function () {
copyText(this.historyString);
},
copyAndDelete: function () {
copyText(this.historyString);
this.current = '';
this.history = [];
this.historyString = '';
localStorage.history = JSON.stringify(this.history);
localStorage.current = this.current;
localStorage.historyString = this.historyString;
}
},
mounted() {
if (localStorage.current) {
this.current = localStorage.current;
}
if (localStorage.history) {
this.history = JSON.parse(localStorage.history);
}
},
watch: {
current(newCurrent) {
localStorage.current = newCurrent;
}
}
});