-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js~
83 lines (53 loc) · 2.58 KB
/
background.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
var i = 0;
var x = 0;
var iterations = 1;
var wordObject = [
{ word: 'peanut', definition:'The oval seed of a South American plant, eaten as a snack or used for making oil or animal feed.' }
, { word: 'piano', definition:'A large keyboard musical instrument with a wooden case enclosing a soundboard and metal strings, which are struck by hammers when the...' }
, { word: 'cigarette', definition:'A thin cylinder of finely cut tobacco rolled in paper for smoking.' }
];
var loadFunction = function(){
//chrome.storage.sync.set({"myValue": wordObject}); activate this to get the program running. The emply storage will throw an error
chrome.storage.sync.get("myValue", //// load saved data.
function(val) {
if (val.myValue === undefined){
chrome.storage.sync.set({"myValue": wordObject});
runArray();
} else {
wordObject=val.myValue;
runArray();
}
});
};
loadFunction();
////////////////right click menu
chrome.contextMenus.removeAll();
chrome.contextMenus.create({title: "Learn 2 Spell '%s' ",
contexts:["selection"],
onclick: function(info){
wordObject[wordObject.length]= { word: info.selectionText, definition: " 'add definition' " };
runArray();
chrome.storage.sync.set({"myValue": wordObject});
//chrome.contextMenus.removeAll();
//location.reload(); /////////// refreshes page ! probably not good
}
});
///////////////
var runArray = function (){
if (wordObject.length<=0) {
$('h2').text("");
} else {
$('h2').text(wordObject[i].word);
};
$(".wordlist-table tbody").empty();
for ( var z = i; z < wordObject.length; z=z+1 ){
$(".wordlist-table tbody").append("<tr><td>"+wordObject[z].word+"</td><td data-id='" + (z+1) + "'>"+wordObject[z].definition+"</td><td>"+"<i id=\"deleteLI" + (z+1) + "\" data-id='" + (z+1) + "' class=\"icon-remove\"></i>"+"</td></tr>" );
defineFunction();
}
for ( var z = 0; z < i; z=z+1 ){
$(".wordlist-table tbody").append("<tr><td>"+wordObject[z].word+"</td><td data-id='" + (z+1) + "'>"+wordObject[z].definition+"</td><td>"+"<i id=\"deleteLI" + (z+1) + "\" data-id='" + (z+1) + "' class=\"icon-remove\"></i>"+"</td></tr>" );
defineFunction();
}
};
defineFunction();
runArray();