-
-
Save 7aman/57e50b9eef61e116186740b634a66704 to your computer and use it in GitHub Desktop.
Bare minimum Firefox extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is the background code... | |
// listen for our browerAction to be clicked | |
browser.browserAction.onClicked.addListener(function (tab) { | |
// for the current tab, inject the "inject.js" file & execute it | |
browser.tabs.executeScript(tab.id, { | |
file: 'inject.js' | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is the code which will be injected into a given page... | |
(function() { | |
// just place a div at top right | |
var div = document.createElement('div'); | |
div.style.position = 'fixed'; | |
div.style.top = 0; | |
div.style.right = 0; | |
div.textContent = 'Injected!'; | |
document.body.appendChild(div); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Injecta", | |
"version": "0.0.1", | |
"manifest_version": 2, | |
"description": "Injecting stuff", | |
"homepage_url": "http://danharper.me", | |
"background": { | |
"scripts": [ | |
"background.js" | |
], | |
"persistent": true | |
}, | |
"browser_action": { | |
"default_title": "Inject!", | |
"default_icon": "icon.png" | |
}, | |
"permissions": [ | |
"activeTab" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change to firefox