forked from ocodia/Hide-Twitter-Guff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
72 lines (53 loc) · 1.96 KB
/
options.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
// Hide Twitter Guff
// Paul Livingstone
// 2010
function loadOptions() {
// Load up the background page
var bkg = chrome.extension.getBackgroundPage();
// declare the SHOW variables and get their values from LocalStorage
var showWTF = bkg.getItem("showWTF");
var showTRENDS = bkg.getItem("showTRENDS");
// the default setting is to hide the elements
var defaultSetting = "hide";
// Set up the defaults if no values are present in LocalStorage
if (showWTF == undefined || showTRENDS == undefined) {
// if undefined, set to defaults
bkg.setItem("showWTF", defaultSetting);
bkg.setItem("showTRENDS", defaultSetting);
// retrieve them from the localstore
showWTF = bkg.getItem("showWTF");
showTRENDS = bkg.getItem("showTRENDS");
}
// get the options form elements
var wtf = document.getElementById("whotofollow");
var trends = document.getElementById("trends");
// Select the appropriate saved option for TRENDS
for (var i = 0; i < trends.children.length; i++) {
var trendschild = trends.children[i];
if (trendschild.value == showTRENDS) {
trendschild.selected = "true";
break;
}
}
// Select the appropriate saved option for WTF
for (var i = 0; i < wtf.children.length; i++) {
var wchild = wtf.children[i];
if (wchild.value == showWTF) {
wchild.selected = "true";
break;
}
}
}
function saveOptions() {
var bkg = chrome.extension.getBackgroundPage();
var wtf = document.getElementById("whotofollow");
var trends = document.getElementById("trends");
// Save selected options to localstore
bkg.setItem("showTRENDS", trends.children[trends.selectedIndex].value);
bkg.setItem("showWTF", wtf.children[wtf.selectedIndex].value);
document.getElementById("msg").style.visibility = "visible";
}
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('button').addEventListener('click', saveOptions);
});
window.addEventListener('load', loadOptions, false);