Skip to content

Commit abfb87f

Browse files
committed
toggle extension version
1 parent e2f68bc commit abfb87f

File tree

9 files changed

+67
-133
lines changed

9 files changed

+67
-133
lines changed

extension/background.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
chrome.runtime.onStartup.addListener(initPlugin);
2+
chrome.runtime.onInstalled.addListener(initPlugin);
3+
chrome.tabs.onActivated.addListener(recheckPlugin);
4+
let enabled = true;
5+
6+
function onClick() {
7+
if (enabled) {
8+
disable();
9+
}
10+
else {
11+
enable();
12+
}
13+
}
14+
15+
function initPlugin() {
16+
chrome.storage.local.get('dcr-enabled', function(res) {
17+
enabled = res;
18+
chrome.action.onClicked.addListener(onClick);
19+
chrome.runtime.onSuspend.addListener(cleanupPlugin);
20+
});
21+
}
22+
23+
function cleanupPlugin() {
24+
chrome.storage.local.set({'dcr-enabled': enabled});
25+
}
26+
27+
function recheckPlugin() {
28+
if (enabled)
29+
enable();
30+
else
31+
disable();
32+
}
33+
34+
function enable() {
35+
console.log("bg enable");
36+
enabled = true;
37+
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
38+
chrome.tabs.sendMessage(tabs[0].id, {message: 'dcr-enable'});
39+
});
40+
chrome.action.setIcon({path: 'icon-on.png'});
41+
chrome.action.setTitle({title: 'DataChartRenderer - enabled'});
42+
}
43+
44+
function disable() {
45+
console.log("bg disable");
46+
enabled = false;
47+
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
48+
chrome.tabs.sendMessage(tabs[0].id, {message: 'dcr-disable'});
49+
});
50+
chrome.action.setIcon({path: 'icon-off.png'});
51+
chrome.action.setTitle({title: 'DataChartRenderer - disabled'});
52+
}

extension/bckp.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

extension/content/main.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ let enabled = true;
33
let limit = 5000;
44
chrome.runtime.onMessage.addListener(
55
function (request, sender, sendResponse) {
6-
if (request.message === "start") {
7-
this.enabled = true;
6+
if (request.message === "dcr-enable") {
7+
enabled = true;
88
}
9-
else if (request.message === "stop") {
10-
this.enabled = false;
11-
}
12-
else if (request.message === "limit") {
13-
window.hardRowLimit = +request.value;
9+
else if (request.message === "dcr-disable") {
10+
enabled = false;
1411
}
1512
}
1613
);

extension/favicon.ico

-2.64 KB
Binary file not shown.

extension/icon-off.png

2.34 KB
Loading

extension/icon-on.png

2.45 KB
Loading

extension/manifest.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
"version": "0.0.1",
44
"manifest_version": 3,
55
"description": "This extension dynamically rendering potential chart representations of found CSV files in a popup.",
6-
"icons": { "32": "favicon.ico"},
7-
"action": {
8-
"default_popup": "popup.html"
9-
},
6+
"icons": { "32": "icon-on.png"},
7+
"action": {},
108
"content_scripts": [
119
{
1210
"matches": [
@@ -24,5 +22,14 @@
2422
"css": ["content/main.css"],
2523
"run_at": "document_end"
2624
}
25+
],
26+
"background": {
27+
"service_worker": "background.js"
28+
},
29+
"permissions": [
30+
"activeTab",
31+
"scripting",
32+
"storage",
33+
"tabs"
2734
]
2835
}

extension/popup/popup.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

extension/popup/popup.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)