Skip to content

Instantly share code, notes, and snippets.

@rudiedirkx rudiedirkx/background.js
Last active Dec 26, 2017

Embed
What would you like to do?
const queue = [];
chrome.browserAction.onClicked.addListener(function(tab) {
var url = 'http://www.example.com/?x=' + String(Math.random()).substr(2);
queue.push(url);
console.log('queue', queue);
chrome.tabs.update({url});
});
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if (typeof msg.url == 'string') {
var i = queue.indexOf(msg.url);
sendResponse(i >= 0);
if (i >= 0) {
queue.splice(i, 1);
console.log('queue', queue);
}
}
});
chrome.runtime.sendMessage({url: location.href}, function(response) {
if (response === true) {
window.addEventListener('load', function(e) {
console.log('LOADED because opened, not always');
});
}
});
{
"name": "SO 47973057",
"description": "SO 47973057",
"version": "1.0",
"permissions": [ "tabs", "<all_urls>" ],
"background": {
"scripts": [ "background.js" ]
},
"content_scripts": [
{
"all_frames": true,
"js": [ "content.js" ],
"matches": [ "http://*/*", "https://*/*" ],
"run_at": "document_start"
}
],
"browser_action": {
"browser_style": false,
"default_title": "Open tab",
"default_icon": {
"38": "images/38x38.png",
"19": "images/19x19.png"
}
},
"icons": {
"128": "images/128x128.png",
"64": "images/64x64.png",
"48": "images/48x48.png",
"32": "images/32x32.png",
"16": "images/16x16.png"
},
"manifest_version": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.