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')
def capture(
url: T.text,
title: T.Nullable(T.text),
selection: T.Nullable(T.text),
comment: T.Nullable(T.text),
):
log("capturing", url, selection, comment)
log("capturing", url, title, selection, comment)
heading = url
parts = []
if not empty(title):
heading = title
parts.append(url)
# TODO not sure, maybe add as org quote?
if not empty(selection):
parts.extend([
'Selection:',
selection,
selection, # TODO tabulate?
])
if not empty(comment):
parts.extend([
@ -46,7 +53,7 @@ def capture(
try:
append_org_entry(
CAPTURE_PATH,
heading=url,
heading=heading,
body=body,
tags=['grasp'],
todo=False,

View file

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

View file

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