-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
64 lines (52 loc) · 2.27 KB
/
script.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
var localStorage = ('localStorage' in window);
function saveData(key, value){
if(localStorage){
localStorage.setItem(key, value);
}
}
function localData(key){
if(localStorage) {
if (key in localData) {
return localStorage.getItem(key);
}
}
}
function setBackground(){
let file = document.getElementById('url').value;
saveData('imageURL', file);
document.body.style.backgroundImage = "url(" + file + ")";
}
function setOverlayColor() {
let color = document.getElementById('bg-color').value;
let RGBify = hexToRgb(color);
let opacity = document.getElementById("opacity").value;
let fullColor = `rgba(${RGBify.r}, ${RGBify.g}, ${RGBify.b}, ${opacity})`;
saveData('bg-color', color);
saveData("opacity", opacity);
document.getElementById('section').style.backgroundColor = fullColor;
}
function hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
function setTextColor() {
let color = document.getElementById('text-color').value;
saveData('text-color', color);
document.body.style.color = color;
}
function onLoad() {
localData("imageURL") && (document.getElementById("url").value = localData("imageURL"));
localData("bg-color") && (document.getElementById("bg-color").value = localData("bg-color"));
localData("opacity") && (document.getElementById("opacity").value = localData("opacity"));
localData("text-color") && (document.getElementById("text-color").value = localData("text-color"));
setBackground();
setOverlayColor();
setTextColor();
}
function deleteAll(){
localStorage.clear();
}