handle selection and url extraction properly
This commit is contained in:
parent
4115b6e003
commit
5b871fed90
|
@ -16,6 +16,10 @@ function makeCaptureRequest(
|
||||||
'comment': comment,
|
'comment': comment,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (url == null) {
|
||||||
|
showNotification('ERROR: trying to capture null');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
console.log(`[background] capturing ${data}`);
|
console.log(`[background] capturing ${data}`);
|
||||||
|
@ -33,17 +37,45 @@ function makeCaptureRequest(
|
||||||
} else {
|
} else {
|
||||||
// TODO more error context?
|
// TODO more error context?
|
||||||
console.log(`[background] ERROR: ${request.status}`);
|
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...
|
// TODO crap, doesn't really seem to respect urgency...
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
request.onerror = () => {
|
||||||
|
console.log(request);
|
||||||
|
};
|
||||||
|
|
||||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||||
request.send(data);
|
request.send(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener((message: any, sender: chrome$MessageSender, sendResponse) => {
|
|
||||||
if (message.method === CAPTURE_SELECTED_METHOD) {
|
// TODO mm. not sure if should do browserAction.onclicked instead?? I suppose it's more flexible??
|
||||||
makeCaptureRequest(message.url);
|
// 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 () {
|
function captureSelected () {
|
||||||
// TODO add command to run capture server as a hint??
|
// TODO add command to run capture server as a hint??
|
||||||
const url = "TODO FIXME";
|
console.log('[popup] capturing!');
|
||||||
console.log(`[popup] capturing ${url}`);
|
|
||||||
chrome.runtime.sendMessage({
|
chrome.runtime.sendMessage({
|
||||||
'method': CAPTURE_SELECTED_METHOD,
|
'method': CAPTURE_SELECTED_METHOD,
|
||||||
'url': url,
|
|
||||||
}, resp => {
|
}, resp => {
|
||||||
console.log("[popup] captured!");
|
console.log("[popup] captured!");
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
"page": "background.html"
|
"page": "background.html"
|
||||||
},
|
},
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_popup": "popup.html"
|
|
||||||
},
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"notifications",
|
"notifications",
|
||||||
|
"activeTab",
|
||||||
"http://*/"
|
"http://*/"
|
||||||
],
|
],
|
||||||
"commands": {
|
"commands": {
|
||||||
|
|
Loading…
Reference in a new issue