-
Notifications
You must be signed in to change notification settings - Fork 0
/
myNotesFunctions.js
49 lines (46 loc) · 1.45 KB
/
myNotesFunctions.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
function clearContent(element) {
element.value = "";
}
function setCookie(element) {
var d = new Date();
var value = "";
for (var i = 0; i < element.value.length; i++) {
value += element.value.charCodeAt(i) + "@";
}
d.setTime(d.getTime() + (7*86400000)); //7 days 86400000 =24*60*60*1000
var expires = "expires="+ d.toUTCString();
document.cookie = "myNotes=" + value + ";" + expires + ";path=/";
}
function getCookie(name){
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value != null) ? unescape(value[1]) : null;
}
function writeTextArea(element){
var value = getCookie("myNotes");
var arrayValues = value.split("@");
var arrayValue = "";
var outputValue = "";
var stringTemp = "";
for (var i = 0; i < arrayValues.length - 1; i++) {
arrayValue = arrayValues[i];
outputValue += String.fromCharCode(arrayValues[i]);
}
element.value = outputValue;
element.focus();
}
function selectAll(element){
element.select();
}
function copyToClipboard(){
selectAll(myNotes);
document.execCommand("Copy");
window.getSelection.empty();
window.getSelection
return false;
}
function main(element){
writeTextArea(element);
element.addEventListener("mouseleave", function (event) {setCookie(element)}, false);
element.addEventListener("mouseout", function (event) {setCookie(element)}, false);
}