Skip to content

Commit 9a48431

Browse files
committed
some fiddling with extension ui
1 parent 41672d9 commit 9a48431

File tree

10 files changed

+382
-46
lines changed

10 files changed

+382
-46
lines changed

extension/background.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// TODO: Move bg-test.js back here
2+
try {
3+
importScripts("bg-test.js");
4+
} catch (e) {
5+
console.error(e);
6+
}

extension/bg-test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
console.log("Background service worker up and running.");
2+
console.log(chrome);
3+
chrome.runtime.onStartup.addListener(initPlugin);
4+
chrome.runtime.onInstalled.addListener(initPlugin);
5+
chrome.runtime.onSuspend.addListener(cleanupPlugin);
6+
chrome.tabs.onUpdated.addListener(recheckPlugin);
7+
chrome.runtime.onMessage.addListener(function(req){
8+
if (req.message === "cs-dcr-enable") {
9+
if (!enabled)
10+
enablePlugin();
11+
if(req.limit)
12+
rowLimit = req.limit;
13+
}
14+
else if (req.message === "cs-dcr-disable") {
15+
if (enabled)
16+
disablePlugin();
17+
}
18+
});
19+
20+
let enabled = false;
21+
let rowLimit = 5000;
22+
23+
// On start/install... make init steps.
24+
function initPlugin() {
25+
chrome.storage.local.get('dcr-enabled', function (res) {
26+
enabled = res;
27+
if (enabled) enablePlugin();
28+
else disablePlugin();
29+
});
30+
chrome.storage.local.get('dcr-limit', function (res) {
31+
if (res) {
32+
rowLimit = res;
33+
if (enabled)
34+
enablePlugin();
35+
}
36+
});
37+
}
38+
39+
// On quit/suspend... save config and clean up.
40+
function cleanupPlugin() {
41+
chrome.storage.local.set('dcr-enabled', enabled);
42+
chrome.storage.local.set('dcr-limit', rowLimit);
43+
}
44+
45+
// Send disabling message
46+
function disablePlugin() {
47+
console.log("BG disablePlugin");
48+
enabled = false;
49+
chrome.runtime.sendMessage({message: "bg-dcr-disable"});
50+
}
51+
52+
// Send enabling message
53+
function enablePlugin() {
54+
console.log("BG enablePlugin");
55+
enabled = true;
56+
chrome.runtime.sendMessage({message:"bg-dcr-enable", limit: rowLimit });
57+
}
58+
59+
// On tab switch, resend the state info
60+
function recheckPlugin() {
61+
console.log("RECHEKC");
62+
if (enabled) enablePlugin();
63+
else disablePlugin();
64+
}

extension/content/main.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22
let enabled = true;
33
let limit = 5000;
44
chrome.runtime.onMessage.addListener(
5-
function (request, sender, sendResponse) {
6-
if (request.message === "start") {
7-
this.enabled = true;
5+
function (request) {
6+
if (request.message === "dcr-enable") {
7+
enabled = true;
8+
window.hardRowLimit = +request.limit;
9+
console.log("DCR Enabled with limit ", request.limit);
810
}
9-
else if (request.message === "stop") {
10-
this.enabled = false;
11-
}
12-
else if (request.message === "limit") {
13-
window.hardRowLimit = +request.value;
11+
else if (request.message === "dcr-disable") {
12+
enabled = false;
13+
console.log("DCR Stop");
1414
}
1515
}
1616
);
1717

18+
chrome.runtime.onMessage.addListener(function(req){
19+
if (req.message === "bg-dcr-enable") {
20+
enabled = true;
21+
if (req.limit)
22+
limit = req.limit;
23+
}
24+
else if (req.message === "bg-dcr-disable") {
25+
enabled = false;
26+
}
27+
})
28+
1829
let linkExceptions = [];
1930
$('body').on('mouseenter', 'a[href*=".csv"]', function (e) {
2031
if (!enabled)

extension/icon-off.png

2.34 KB
Loading

extension/icon-off.svg

Lines changed: 119 additions & 0 deletions
Loading

extension/icon-on.png

2.45 KB
Loading

extension/icon-on.svg

Lines changed: 119 additions & 0 deletions
Loading

extension/manifest.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"description": "This extension dynamically rendering potential chart representations of found CSV files in a popup.",
66
"icons": { "32": "favicon.ico"},
77
"action": {
8-
"default_popup": "popup.html"
8+
"default_popup": "popup/popup.html",
9+
"default_icon": "icon-on.png"
910
},
1011
"content_scripts": [
1112
{
@@ -24,5 +25,11 @@
2425
"css": ["content/main.css"],
2526
"run_at": "document_end"
2627
}
28+
],
29+
"permissions": [
30+
"activeTab",
31+
"scripting",
32+
"storage",
33+
"tabs"
2734
]
2835
}

extension/popup/popup.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<html>
33

44
<body>
5-
<div id="chart_div">
6-
</div>
75
<input id="on-off-btn" type="button" value="Disable"></input>
86
<br />
97
Maximal number of rows loaded:

0 commit comments

Comments
 (0)