답변은 콘텐츠 스크립트를 만드는 방법에 따라 다릅니다. 아래 내용은 main.js
파일에 PageMod이라는 내용의 스크립트를 추가하는 파일입니다.
var buttons = require('sdk/ui/button/action'),
pageMod = require('sdk/page-mod'),
data = require('sdk/self').data;
// Map of messages keyed by tab id
var messages = {};
pageMod.PageMod({
include: 'http://www.example.com',
contentScriptFile: [
data.url('my-script.js')
],
onAttach: function(worker){
// Get the tab id from the worker
var tabId = worker.tab.id;
// Save the message
worker.port.on('message', function(message){
messages[tabId] = message;
});
// Delete the messages when the tab is closed
// to prevent a memory leak
worker.on('detach', function(){
delete messages[tabId];
});
}
});
var button = buttons.ActionButton({
id: 'my-extension',
label: 'Example',
icon: {
'16': './icon-16.png',
'32': './icon-32.png',
'64': './icon-64.png'
},
onClick: function(state){
// Retrieve the message associated with the
// currently active tab, if there is one
var message = messages[tabs.activeTab.id];
// Do something with the message
}
});
는 또한 진행 방법과 상황에 적응하는 기능에 대한 더 나은 이해를 위해 Content Scripts - Interacting with Page Scripts 및 Content Worker을 읽어 보시기 바랍니다.