-
-
Save mieko/a6a16d239d8179fd8b771322dfa4706f to your computer and use it in GitHub Desktop.
This file contains 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
<script src="./bg.js"></script> |
This file contains 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
(function() { | |
var spawn_url = null; | |
var menu = null; | |
var viewBackgroundImage = function() { | |
window.open(spawn_url); | |
}; | |
var toggleMenu = function(b) { | |
if (b) { | |
if (!menu) { | |
menu = chrome.contextMenus.create({ "title": "View Background Image", | |
"onclick": viewBackgroundImage, | |
"contexts": ['all']}); | |
} | |
} else { | |
if (menu) { | |
chrome.contextMenus.remove(menu); | |
menu = null; | |
} | |
} | |
}; | |
chrome.extension.onRequest.addListener( | |
function(req, sender, resp) { | |
if (req.url && req.url != 'none') { | |
var u = req.url.replace(/['"]/g, '').replace(/url\((.*)\);?/, '$1'); | |
spawn_url = u; | |
toggleMenu(true); | |
} else { | |
toggleMenu(false); | |
} | |
} | |
); | |
})(); |
This file contains 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
(function() { | |
document.addEventListener('mouseover', function(ev) { | |
var u = document.defaultView.getComputedStyle(ev.target, null).backgroundImage; | |
chrome.extension.sendRequest({"url": u || false }); | |
}, true); | |
})(); |
This file contains 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": "View Background Image", | |
"version": "1.0", | |
"description": "Add 'View Background Image' to the context menu", | |
"permissions": ["contextMenus", "tabs"], | |
"background_page": "background.html", | |
"content_scripts": [{"matches": ["<all_urls>"], | |
"run_at": "document_start", | |
"js": ["cs.js"]}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment