Add title capture

This commit is contained in:
Dima Gerasimov 2019-01-04 23:57:34 +00:00
parent 5f5fd0e132
commit 1d8a15acf6
4 changed files with 43 additions and 24 deletions

8
server Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
set -eux
cd "$(dirname "$0")"
PORT=8090
hug -p "$PORT" -f server.py >server.log 2>server.err

View file

@ -20,17 +20,24 @@ def log(*things):
@hug.post('/capture') @hug.post('/capture')
def capture( def capture(
url: T.text, url: T.text,
title: T.Nullable(T.text),
selection: T.Nullable(T.text), selection: T.Nullable(T.text),
comment: T.Nullable(T.text), comment: T.Nullable(T.text),
): ):
log("capturing", url, selection, comment) log("capturing", url, title, selection, comment)
heading = url
parts = [] parts = []
if not empty(title):
heading = title
parts.append(url)
# TODO not sure, maybe add as org quote? # TODO not sure, maybe add as org quote?
if not empty(selection): if not empty(selection):
parts.extend([ parts.extend([
'Selection:', 'Selection:',
selection, selection, # TODO tabulate?
]) ])
if not empty(comment): if not empty(comment):
parts.extend([ parts.extend([
@ -46,7 +53,7 @@ def capture(
try: try:
append_org_entry( append_org_entry(
CAPTURE_PATH, CAPTURE_PATH,
heading=url, heading=heading,
body=body, body=body,
tags=['grasp'], tags=['grasp'],
todo=False, todo=False,

View file

@ -4,22 +4,19 @@
import {CAPTURE_SELECTED_METHOD, showNotification} from './common'; import {CAPTURE_SELECTED_METHOD, showNotification} from './common';
import {capture_url} from './config'; import {capture_url} from './config';
function makeCaptureRequest(
url: string,
selection: ?string=null,
comment: ?string=null,
// TODO anything alse??
) {
if (url == null) {
showNotification('ERROR: trying to capture null');
return;
}
const data = JSON.stringify({ type Params = {
'url': url, url: string,
'selection': selection, title: ?string,
'comment': comment, selection: ?string,
}); comment: ?string,
}
function makeCaptureRequest(
params: Params,
) {
const data = JSON.stringify(params);
console.log(`[background] capturing ${data}`); console.log(`[background] capturing ${data}`);
@ -66,7 +63,12 @@ function makeCaptureRequest(
// TODO handle cannot access chrome:// url?? // TODO handle cannot access chrome:// url??
// TODO ok, need to add comment popup? // TODO ok, need to add comment popup?
chrome.browserAction.onClicked.addListener(tab => { chrome.browserAction.onClicked.addListener(tab => {
const url = tab.url; if (tab.url == null) {
showNotification('ERROR: trying to capture null');
return;
}
const url: string = tab.url;
const title: ?string = tab.title;
// console.log('action!'); // console.log('action!');
// ugh.. https://stackoverflow.com/a/19165930/706389 // ugh.. https://stackoverflow.com/a/19165930/706389
@ -74,9 +76,11 @@ chrome.browserAction.onClicked.addListener(tab => {
code: "window.getSelection().toString();" code: "window.getSelection().toString();"
}, selections => { }, selections => {
const selection = selections == null ? null : selections[0]; const selection = selections == null ? null : selections[0];
makeCaptureRequest( makeCaptureRequest({
url, url: url,
selection title: title,
); selection: selection,
comment: null,
});
}); });
}); });

View file

@ -2,7 +2,7 @@
// TODO configure port in options? // TODO configure port in options?
const capture_endpoint = 'capture'; const capture_endpoint = 'capture';
const port = 8000; const port = 8090;
export function capture_url (): string { export function capture_url (): string {
return `http://localhost:${port}/${capture_endpoint}`; return `http://localhost:${port}/${capture_endpoint}`;