-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
76 lines (64 loc) · 2.23 KB
/
popup.js
File metadata and controls
76 lines (64 loc) · 2.23 KB
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
// Copyright (c) 2012 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.
'use strict';
var list = new Array();
var count;
function click(e) {
chrome.tabs.executeScript(null,
{code:"document.body.style.backgroundColor='" + e.target.id + "'"});
window.close();
}
let highlight = document.getElementById('highlight');
highlight.onclick = function(element){
highlight.style.background = '#FFFF00'
}
document.addEventListener('DOMContentLoaded', function () {
var divs = document.querySelectorAll('div');
for (var i = 0; i < divs.length; i++) {
divs[i].addEventListener('click', click);
}
});
//code not from the Chromium Authors
document.getElementById("save-btn").onclick = async () => {
const [tab] = await chrome.tabs.query({active: true, currentWindow: true});
let result;
try {
[{result}] = await chrome.scripting.executeScript({
target: {tabId: tab.id},
function: () => getSelection().toString(),
});
}
catch (e) {
return;
}
chrome.storage.local.get(['index'], function(num) {
count = num.index;
});
if(Number.isInteger(count) == false){
count = 0;
}
else{
chrome.storage.local.get({key: []}, function(total) {
list = total.key;
count = list.length;
//document.body.append("test");
});
}
//document.body.append(", list length:" + count);//printf, 0 or previous num
//document.body.append(", result: " + result); //printf, result
list[count]=result;
chrome.storage.local.set({key: list}, function() {
//document.body.append(", precount " + count);//printf, 0 or previous num
chrome.storage.local.get(["key"], function(total) {
list = total.key;
//document.body.append(", check:" + list[count] + ",");
});
});
chrome.storage.local.set({index: count + 1}, function() {
//document.body.append('Index is set to ' + count);
document.body.append("stored");
});
//document.body.append(", postcount " + count + ";");//printf whole number
document.body.append(document.createElement('br'));
};