handle selection and url extraction properly
This commit is contained in:
parent
4115b6e003
commit
5b871fed90
|
@ -16,6 +16,10 @@ function makeCaptureRequest(
|
|||
'comment': comment,
|
||||
});
|
||||
|
||||
if (url == null) {
|
||||
showNotification('ERROR: trying to capture null');
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
console.log(`[background] capturing ${data}`);
|
||||
|
@ -33,17 +37,45 @@ function makeCaptureRequest(
|
|||
} else {
|
||||
// TODO more error context?
|
||||
console.log(`[background] ERROR: ${request.status}`);
|
||||
showNotification(`ERROR: ${request.status}`, 1);
|
||||
|
||||
var explain = "";
|
||||
if (request.status === 0) {
|
||||
explain = `Unavaiable: ${capture_url()}`;
|
||||
}
|
||||
showNotification(`ERROR: ${request.status}: ${explain}`, 1);
|
||||
// TODO crap, doesn't really seem to respect urgency...
|
||||
}
|
||||
};
|
||||
request.onerror = () => {
|
||||
console.log(request);
|
||||
};
|
||||
|
||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
request.send(data);
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener((message: any, sender: chrome$MessageSender, sendResponse) => {
|
||||
if (message.method === CAPTURE_SELECTED_METHOD) {
|
||||
makeCaptureRequest(message.url);
|
||||
}
|
||||
|
||||
// TODO mm. not sure if should do browserAction.onclicked instead?? I suppose it's more flexible??
|
||||
// TODO hmm. content script or js??
|
||||
// chrome.runtime.onMessage.addListener((message: any, sender: chrome$MessageSender, sendResponse) => {
|
||||
// if (message.method === CAPTURE_SELECTED_METHOD) {
|
||||
// }
|
||||
// });
|
||||
|
||||
// TODO handle cannot access chrome:// url??
|
||||
// TODO ok, need to add comment popup?
|
||||
chrome.browserAction.onClicked.addListener(tab => {
|
||||
const url = tab.url;
|
||||
|
||||
// console.log('action!');
|
||||
// ugh.. https://stackoverflow.com/a/19165930/706389
|
||||
chrome.tabs.executeScript( {
|
||||
code: "window.getSelection().toString();"
|
||||
}, selections => {
|
||||
const selection = selections == null ? null : selections[0];
|
||||
makeCaptureRequest(
|
||||
url,
|
||||
selection
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,11 +4,9 @@ import {CAPTURE_SELECTED_METHOD} from './common';
|
|||
|
||||
function captureSelected () {
|
||||
// TODO add command to run capture server as a hint??
|
||||
const url = "TODO FIXME";
|
||||
console.log(`[popup] capturing ${url}`);
|
||||
console.log('[popup] capturing!');
|
||||
chrome.runtime.sendMessage({
|
||||
'method': CAPTURE_SELECTED_METHOD,
|
||||
'url': url,
|
||||
}, resp => {
|
||||
console.log("[popup] captured!");
|
||||
});
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
"page": "background.html"
|
||||
},
|
||||
"browser_action": {
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
"permissions": [
|
||||
"notifications",
|
||||
"activeTab",
|
||||
"http://*/"
|
||||
],
|
||||
"commands": {
|
||||
|
|
Loading…
Reference in a new issue