Creating an On/Off switch for my extension

1,936 views
Skip to first unread message

Joshua Hicks

unread,
Dec 30, 2014, 2:25:51 AM12/30/14
to chromium-...@chromium.org
How would I go about doing this? I just want to add a simple switch in default_popup so the user can enable/disable my extension.

Thanks

PhistucK

unread,
Dec 30, 2014, 2:30:20 AM12/30/14
to Joshua Hicks, Chromium-extensions
You can disable extensions using the management API, but the user will have to re-enable the extension manually.


PhistucK

On Tue, Dec 30, 2014 at 9:25 AM, Joshua Hicks <josh...@gmail.com> wrote:
How would I go about doing this? I just want to add a simple switch in default_popup so the user can enable/disable my extension.

Thanks

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/69ac9ff1-284a-4eb7-8842-eb43861931c5%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Joshua Hicks

unread,
Dec 30, 2014, 5:15:40 AM12/30/14
to chromium-...@chromium.org
update: I added an on/off switch but it's just CSS and HTML right now. It goes on/off but doesn't do anything with the disable/enable the extension because there isn't any code for it. How would I link the two? What kind of code has to be written?

Wolf War

unread,
Dec 30, 2014, 5:29:01 AM12/30/14
to chromium-...@chromium.org
on button click (or whatever)
chrome.management.setEnabled(yourExtensionID, false);

PhistucK

unread,
Dec 30, 2014, 5:39:45 AM12/30/14
to Wolf War, Chromium-extensions
Yes, but if the extension is disabled, it cannot show a button to enable itself. Another extension must be used.


PhistucK

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Joshua Hicks

unread,
Dec 30, 2014, 5:55:46 AM12/30/14
to chromium-...@chromium.org, wolf...@gmail.com

I just want it to enable/disable the script, not the actual extension, sorry I worded it wrong 

here's what my default_popup looks like now 

when it's switched on, I want it to run. When switched off, I want the script to be disabled.

here's the button I used https://proto.io/freebies/onoff/

I assume I'd have to declare it as a variable or something to give it a function but I don't know how

here's my script.js file - http://jsfiddle.net/ex04a7t7/6/

sorry guys, I'm really new to this stuff




On Tuesday, December 30, 2014 5:39:45 AM UTC-5, PhistucK wrote:
Yes, but if the extension is disabled, it cannot show a button to enable itself. Another extension must be used.


PhistucK

On Tue, Dec 30, 2014 at 12:29 PM, Wolf War <wolf...@gmail.com> wrote:
on button click (or whatever)
chrome.management.setEnabled(yourExtensionID, false);



On Tuesday, December 30, 2014 11:15:40 AM UTC+1, Joshua Hicks wrote:
update: I added an on/off switch but it's just CSS and HTML right now. It goes on/off but doesn't do anything with the disable/enable the extension because there isn't any code for it. How would I link the two? What kind of code has to be written?



On Tuesday, December 30, 2014 2:25:51 AM UTC-5, Joshua Hicks wrote:
How would I go about doing this? I just want to add a simple switch in default_popup so the user can enable/disable my extension.

Thanks

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

PhistucK

unread,
Dec 30, 2014, 6:50:47 AM12/30/14
to Joshua Hicks, Chromium-extensions, Wolf War
Hm... is this script run within the popup? Within the page?
If it is run within the page, you should send a message to the page using chrome.tabs.sendMessage (and listen to the message using chrome.runtime.onMessage.addListener.


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Joshua Hicks

unread,
Dec 30, 2014, 8:52:59 AM12/30/14
to chromium-...@chromium.org, josh...@gmail.com, wolf...@gmail.com
A friend told me to change the code around and create two named functions instead of having anonymous ones. One to enable, and one to disable. Then attach event handlers to the button's "click" event to run the enable/disable function

that'd be cool and ultimately give me what I want, but I have no idea how to get started 

PhistucK

unread,
Dec 30, 2014, 9:45:52 AM12/30/14
to Joshua Hicks, Chromium-extensions, Wolf War
When you write "button", do you mean the browser action?
If so, you need a background script that will listen to the click event on the browser action.
Read the documentation for more details -


PhistucK

On Tue, Dec 30, 2014 at 3:52 PM, Joshua Hicks <josh...@gmail.com> wrote:
A friend told me to change the code around and create two named functions instead of having anonymous ones. One to enable, and one to disable. Then attach event handlers to the button's "click" event to run the enable/disable function

that'd be cool and ultimately give me what I want, but I have no idea how to get started 

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
Reply all
Reply to author
Forward
0 new messages