forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
35 lines (31 loc) · 1.05 KB
/
popup.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
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function displayWords() {
chrome.storage.local.get(['words'], function(object) {
let pageList = document.getElementById('displayWords');
if (object.words) {
searchWords = object.words
for (var i = 0; i < searchWords.length; i++){
let listItem = document.createElement('li');
listItem.innerText = searchWords[i]
pageList.appendChild(listItem);
}
}
});
}
displayWords();
document.getElementById('wordSubmit').onclick = function() {
let userWords = document.getElementById('userWords').value.trim();
chrome.storage.local.get(['words'], function(object) {
let newWords = object.words || [];
newWords.push(userWords);
chrome.storage.local.set({words: newWords});
})
chrome.tabs.executeScript(null, {
file: 'content_script.js'
});
}
document.getElementById('clearList').onclick = function() {
chrome.storage.local.clear();
}