-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathoptions_manage.js
84 lines (72 loc) · 2.65 KB
/
options_manage.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function bindColor(elementId, attributeName, targetId){
var element = document.getElementById(elementId);
var value = element.value;
var target = document.getElementById(targetId);
target.style[attributeName] = '#' + value;
saveOption(elementId, value);
}
function hide(elementId){
var element = document.getElementById(elementId);
element.style.display = 'none';
}
function show(elementId){
var element = document.getElementById(elementId);
element.style.display = '';
}
function colorRadioDefault(){
hide("background_color_row");
hide("text_color_row");
hide("links_color_row");
hide("visited_links_color_row");
saveOption("DefaultBrowserColor", true);
}
function colorRadioOverride(){
show("background_color_row");
show("text_color_row");
show("links_color_row");
show("visited_links_color_row");
saveOption("DefaultBrowserColor", false);
}
function saveOption(optionName, optionValue){
localStorage[optionName] = JSON.stringify(optionValue);
var backgroundPage = chrome.extension.getBackgroundPage();
backgroundPage.objCurrentPage.buildCssToInject();
}
function loadOption(optionName){
return JSON.parse(localStorage[optionName]);
}
function restoreOptionValue(elementId){
var value = loadOption(elementId);
var element = document.getElementById(elementId);
element.value = value;
}
function radioCheck(optionName, defaultElementId, overrideElementId){
if(loadOption(optionName)){
document.getElementById(defaultElementId).checked = true;
document.getElementById(defaultElementId).onclick();
}
else{
document.getElementById(overrideElementId).checked = true;
document.getElementById(overrideElementId).onclick();
}
}
function restoreOptions(){
setFontSize(loadOption("FontSize"));
setFont(loadOption("OverrideFontName"));
restoreOptionValue("text_color")
restoreOptionValue("background_color")
restoreOptionValue("links_color")
restoreOptionValue("visited_links_color")
radioCheck("DefaultBrowserFont", "browserFontDefault", "browserFontOverride");
radioCheck("DefaultBrowserColor", "browserColorDefault", "browserColorOverride");
radioCheck("ShowImage", "showImageDefault", "showImageOverride");
radioCheck("ShowFlash", "showFlashDefault", "showFlashOverride");
bindColor('background_color', 'backgroundColor', 'sampleBlock');
bindColor('text_color', 'color', 'sampleBlock');
bindColor('links_color', 'color', 'link');
bindColor('visited_links_color', 'color', 'visited_link');
}
function displayColoredMessage(element, message, colorCode){
element.style.color = colorCode;
element.innerHTML = message;
}