Completed
Push — master ( a00cdd...6ad87d )
by Dongxin
01:02
created

options.js (5 issues)

1
//////////////////////////////////////////////////////////////////////////////////////
2
// Copyright © 2017 TangDongxin
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining
5
// a copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
//////////////////////////////////////////////////////////////////////////////////////
22
23
function setPreviewColor(result) {
24
    console.log("load Color");
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
25
    document.querySelector("#bgColorLabel").style.backgroundColor = result.bgColor      || "#FDF6E3";
26
    document.querySelector("#intColorLabel").style.color          = result.intColor     || "#657A81";
27
    document.querySelector("#strColorLabel").style.color          = result.strColor     || "#2AA198";
28
    document.querySelector("#keyColorLabel").style.color          = result.keyColor     || "#B58900";
29
    document.querySelector("#defaultColorLabel").style.color      = result.defaultColor || "#586E75";
30
}
31
32
function onError(error) {
33
    console.log(`Error: ${error}`);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
34
}
35
36
function saveOptions(e) {
37
    e.preventDefault();
38
    browser.storage.local.set({
0 ignored issues
show
The variable browser seems to be never declared. If this is a global, consider adding a /** global: browser */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
39
        bgColor:      document.querySelector("#bgColor").value,
40
        intColor:     document.querySelector("#intColor").value,
41
        strColor:     document.querySelector("#strColor").value,
42
        keyColor:     document.querySelector("#keyColor").value,
43
        defaultColor: document.querySelector("#defaultColor").value
44
    });
45
    alert("Success");
46
    browser.storage.local.get().then(setCurrentChoice, onError);
47
}
48
49
function setCurrentChoice(result) {
50
    console.log(result);
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
51
    document.querySelector("#bgColor").value      = result.bgColor      || "#FDF6E3";
52
    document.querySelector("#intColor").value     = result.intColor     || "#657A81";
53
    document.querySelector("#strColor").value     = result.strColor     || "#2AA198";
54
    document.querySelector("#keyColor").value     = result.keyColor     || "#B58900";
55
    document.querySelector("#defaultColor").value = result.defaultColor || "#586E75";
56
57
    setPreviewColor(result);
58
}
59
60
function restoreOptions() {
61
    browser.storage.local.get().then(setCurrentChoice, onError);
0 ignored issues
show
The variable browser seems to be never declared. If this is a global, consider adding a /** global: browser */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
62
}
63
64
document.addEventListener("DOMContentLoaded", restoreOptions);
65
document.querySelector("form").addEventListener("submit", saveOptions);
66