From b8fa90a560b3197c92729d51f61b9434aa7bf991 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 30 Sep 2016 15:33:02 +0200 Subject: [PATCH] Show info panel when posting to scuttle --- conkeror/.conkerorrc/site-js/scuttle.js | 117 ++++++++++-------------- 1 file changed, 46 insertions(+), 71 deletions(-) diff --git a/conkeror/.conkerorrc/site-js/scuttle.js b/conkeror/.conkerorrc/site-js/scuttle.js index 9b7373b..e6ab875 100644 --- a/conkeror/.conkerorrc/site-js/scuttle.js +++ b/conkeror/.conkerorrc/site-js/scuttle.js @@ -29,6 +29,49 @@ function scuttle_get_url(path) return url.spec + '/' + path; } +function scuttle_send_url(I, obj, default_name) { + var postlinkurl; + var uri_string = load_spec_uri_string(load_spec(obj)); + var panel = create_info_panel( + I.window, 'scuttle-panel', + [['scuttle-bookmarking', 'Sending URL to Scuttle: ', uri_string]] + ); + + try { + let description = yield I.minibuffer.read( + $prompt = "name (required): ", + $initial_value = default_name + ); + let tags = yield I.minibuffer.read( + $prompt = "tags (space delimited): " + ); + let extended = yield I.minibuffer.read( + $prompt = "extended description: " + ); + + postlinkurl = scuttle_get_url( + 'posts_add.php?&url=' + escape(uri_string) + + '&description=' + escape(description) + + '&tags=' + escape(tags) + + '&extended=' + escape(extended) + ); + } finally { + panel.destroy(); + } + + try { + var content = yield send_http_request( + load_spec({uri: postlinkurl})); + var dom = scuttle_parse_xml(content.responseText); + var result = dom.getElementsByTagName('result')[0]; + var code = result.getAttribute('code'); + I.window.minibuffer.message(code); + + if (code === 'done') + scuttle_bookmarked_hook.run(); + } catch (e) { } +} + function scuttle_bookmarked_widget(window) { this.class_name = 'scuttle-bookmark-widget'; @@ -72,81 +115,13 @@ interactive("scuttle-post", "bookmark the page via scuttle", function (I) { check_buffer(I.buffer, content_buffer); - let posturl = scuttle_get_url( - 'posts_add.php?&url=' + - escape(load_spec_uri_string(load_spec(I.buffer.top_frame))) + - '&description=' + - escape(( - yield I.minibuffer.read( - $prompt = "name (required): ", - $initial_value = I.buffer.title - ) - )) + - '&tags=' + - escape(( - yield I.minibuffer.read( - $prompt = "tags (space delimited): " - ) - )) + - '&extended=' + - escape(( - yield I.minibuffer.read( - $prompt = "extended description: " - ) - ))); - - try { - var content = yield send_http_request( - load_spec({uri: posturl})); - var dom = scuttle_parse_xml(content.responseText); - var result = dom.getElementsByTagName('result')[0]; - var code = result.getAttribute('code'); - I.window.minibuffer.message(code); - - if (code === 'done') - scuttle_bookmarked_hook.run(); - } catch (e) { } + co_call(scuttle_send_url(I, I.buffer.top_frame, I.buffer.title)); }); interactive("scuttle-post-link", "bookmark the link via scuttle", function (I) { - var bo = yield read_browser_object(I); - var mylink = load_spec_uri_string( - load_spec(encodeURIComponent(bo))); + let bo = yield read_browser_object(I); check_buffer(I.buffer, content_buffer); - let postlinkurl = scuttle_get_url( - 'posts_add.php?&url=' + - mylink + - '&description=' + - escape(( - yield I.minibuffer.read( - $prompt = "name (required): ", - $initial_value = bo.textContent - ) - )) + - '&tags=' + - escape(( - yield I.minibuffer.read( - $prompt = "tags (space delimited): " - ) - )) + - '&extended=' + - escape(( - yield I.minibuffer.read( - $prompt = "extended description: " - ) - ))); - - try { - var content = yield send_http_request( - load_spec({uri: postlinkurl})); - var dom = scuttle_parse_xml(content.responseText); - var result = dom.getElementsByTagName('result')[0]; - var code = result.getAttribute('code'); - I.window.minibuffer.message(code); - - if (code === 'done') - scuttle_bookmarked_hook.run(); - } catch (e) { } + co_call(scuttle_send_url(I, encodeURIComponent(bo), bo.textContent)); }, $browser_object = browser_object_links);