Firefox-addon-sdk: launching pageMod when a button is clicked?

I am doing a Firefox add-on using the toolbar from Eric Wold, and I would like to know how to start and stop pageMod when the user clicks a button on the toolbar. Is it possible? I tried using Javascript using this method and it did not work. Moreover, I could not introduce CSS.

Below is my current code if this helps to understand the problem:

var tbb = require('toolbarbutton').ToolbarButton({ id: 'button', label: 'us-button', image: self.data.url('img/on.png'), onCommand: function () { tabs.activeTab.attach ({ contentScriptFile: [ self.data.url('jquery/jquery.min.js'), self.data.url('jquery/jquery-ui.js'), self.data.url('recuperation.js'), self.data.url('dialog.js') ] }); } }); 
+4
source share
1 answer

What do you mean by

It didn’t work well?

Did it even work? While onCommand() is being called, I do not see any problems with the code.

Regarding CSS

You may be the one who filed the contentStyleFile error (beat me up on it), but for reference it was put here and they seem to be working on a fix.

I am using javascript / jQuery at the same time.

Main.js

 var worker = tabs.activeTab.attach({ contentScriptFile: [data.url('jquery.js'), data.url('annotate.js')] contentScriptOptions: data.url('annotate.css') }); 

annotate.js

 $('head').append("<link href='"+self.options+"' type='text/css' rel='stylesheet' />"); 

It can also be done in plain javascript, but I also use jQuery elsewhere.

0
source

Source: https://habr.com/ru/post/1485075/


All Articles