Skip to content

Instantly share code, notes, and snippets.

@davist11
Created August 30, 2012 02:57
Show Gist options
  • Save davist11/369fe266176d45b488fd to your computer and use it in GitHub Desktop.
Save davist11/369fe266176d45b488fd to your computer and use it in GitHub Desktop.
Chrome Extension
var data;
chrome.extension.onMessage.addListener(function(details) {
data = details;
});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {
file: 'contentscript.js'
});
chrome.windows.create({
url: 'http://my_url_to_a_publish_form',
height: 800,
width: 800,
type: 'popup'
}, function() {
chrome.windows.getCurrent(function(window) {
chrome.tabs.getSelected(window.id, function (response){
chrome.tabs.executeScript(null, {
file: 'insertdata.js'
}, function() {
chrome.tabs.sendMessage(response.id, data);
});
});
});
});
});
// TODO: INCLUDE jQUERY SOURCE HERE
var title = $('meta[property="og:title"]').attr('content');
var source = window.location.href;
var img = $('meta[property="og:image"]').attr('content');
var content = window.getSelection().toString();
if(title === '') {
title = $('title').text();
}
var details = {
title: title,
source: source,
img: img,
content: content
};
chrome.extension.sendMessage(details);
// TODO: INCLUDE jQUERY SOURCE HERE
chrome.extension.onMessage.addListener(function(details) {
//TODO: how do i fire this stuff after jquery and the rest of the window is loaded
$('#publish-title').val(details.title).trigger('keyup');
$('input[name="page[yaml][source]"]').val(details.source);
$('#publish-content').val(details.content);
});
{
"name": "Add Recipe",
"version": "1.1",
"manifest_version": 2,
"description": "Add a recipe from a URL",
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"tabs", "http://*/", "https://*/"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment