Skip to content

Instantly share code, notes, and snippets.

@jeantimex
Created June 10, 2020 06:58
Show Gist options
  • Save jeantimex/050d3a37a84ad8acf1b7a6a414643acc to your computer and use it in GitHub Desktop.
Save jeantimex/050d3a37a84ad8acf1b7a6a414643acc to your computer and use it in GitHub Desktop.
Simple Chrome extension
var toggle = false;
chrome.browserAction.onClicked.addListener(function (tab) {
toggle = !toggle;
if (toggle){
// chrome.browserAction.setIcon({path: "on.png", tabId:tab.id});
chrome.tabs.executeScript(tab.id, {file: "color-picker.js"});
} else {
//chrome.browserAction.setIcon({path: "off.png", tabId:tab.id});
//chrome.tabs.executeScript(tab.id, {code: "alert('hello')"});
chrome.tabs.executeScript(tab.id, {file: "quit.js"});
}
});
(function () {
const div = document.createElement('div');
div.id = 'jeantimex';
div.innerHTML = 'test';
document.body.appendChild(div);
})();
{
"name": "Append Test Text",
"description": "Add test123 to body",
"version": "1.0",
"permissions": [
"activeTab"
],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "Append Test Text"
},
"manifest_version": 2
}
(function () {
const div = document.querySelector('#jeantimex');
if (div) {
div.remove();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment