Add scuttle bookmarked widget

This widget shows whether or not the currently visited buffer is
bookmarked in scuttle. This function requires a patch to scuttle to
work.
This commit is contained in:
Tom Willemse 2014-12-10 17:10:17 +01:00
parent fe2f5bd66a
commit cbb7761b2a
2 changed files with 121 additions and 59 deletions

View file

@ -38,6 +38,7 @@ let (home = get_home_directory()) {
require("cdispass");
require("jira");
require('scuttle');
define_browser_object_class(
"history-url", null,
@ -218,6 +219,7 @@ add_hook("content_policy_hook", content_policy_bytype);
add_hook("mode_line_hook", mode_line_adder(buffer_count_widget));
add_hook("mode_line_hook", mode_line_adder(buffer_icon_widget), true);
add_hook("mode_line_hook", mode_line_adder(downloads_status_widget));
add_hook('mode_line_hook', mode_line_adder(scuttle_bookmarked_widget));
remove_hook("download_added_hook", open_download_buffer_automatically);
@ -324,65 +326,6 @@ register_user_stylesheet(
)
);
interactive("scuttle-post",
"bookmark the page via scuttle",
function (I) {
check_buffer(I.buffer, content_buffer);
let posturl = 'https://ryuslash.org/scuttle/api/posts_add.php?&url=' +
encodeURIComponent(
load_spec_uri_string(
load_spec(I.buffer.top_frame))) +
'&description=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "name (required): ",
$initial_value = I.buffer.title)) +
'&tags=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "tags (space delimited): ")) +
'&extended=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "extended description: "));
try {
var content = yield send_http_request(
load_spec({uri: posturl}));
I.window.minibuffer.message(content.responseText);
} catch (e) { }
});
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)));
check_buffer(I.buffer, content_buffer);
let postlinkurl = 'https://ryuslash.org/scuttle/api/posts_add.php?&url=' +
mylink +
'&description=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "name (required): ",
$initial_value = bo.textContent)) +
'&tags=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "tags (space delimited): ")) +
'&extended=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "extended description: "));
try {
var content = yield send_http_request(
load_spec({uri: postlinkurl}));
I.window.minibuffer.message(content.responseText);
} catch (e) { }
}, $browser_object = browser_object_links);
define_key(default_global_keymap, "p", "scuttle-post");
define_key(default_global_keymap, "P", "scuttle-post-link");

View file

@ -0,0 +1,119 @@
// define_hook('scuttle_bookmarked_hook');
function scuttle_parse_xml(text)
{
var parser = Components
.classes["@mozilla.org/xmlextras/domparser;1"]
.createInstance(Components.interfaces.nsIDOMParser);
return parser.parseFromString(text, 'text/xml');
}
function scuttle_bookmarked_widget(window)
{
this.class_name = 'scuttle-bookmark-widget';
text_widget.call(this, window);
this.add_hook('current_content_buffer_location_change_hook');
this.add_hook('select_buffer_hook');
// this.add_hook('scuttle_bookmarked_hook');
}
scuttle_bookmarked_widget.prototype = {
constructor: scuttle_bookmarked_widget,
__proto__: text_widget.prototype,
update: function () {
var obj = this;
function doit() {
check_buffer(obj.window.buffers.current, content_buffer);
let posturl = 'https://ryuslash.org/scuttle/api/is_bookmarked.php?url=' +
encodeURIComponent(
load_spec_uri_string(
load_spec(obj.window.buffers.current.top_frame)
)
);
try {
let content = yield send_http_request(
load_spec({uri: posturl})
);
var dom = scuttle_parse_xml(content.responseText);
var result = dom.getElementsByTagName('result')[0].innerHTML;
obj.view.text = result == 'true'
? "+" : "-";
}
catch (e) { }
}
co_call(doit());
}
};
interactive("scuttle-post",
"bookmark the page via scuttle",
function (I) {
check_buffer(I.buffer, content_buffer);
let posturl = 'https://ryuslash.org/scuttle/api/posts_add.php?&url=' +
encodeURIComponent(
load_spec_uri_string(
load_spec(I.buffer.top_frame))) +
'&description=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "name (required): ",
$initial_value = I.buffer.title)) +
'&tags=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "tags (space delimited): ")) +
'&extended=' +
encodeURIComponent(
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) { }
});
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)));
check_buffer(I.buffer, content_buffer);
let postlinkurl = 'https://ryuslash.org/scuttle/api/posts_add.php?&url=' +
mylink +
'&description=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "name (required): ",
$initial_value = bo.textContent)) +
'&tags=' +
encodeURIComponent(
yield I.minibuffer.read(
$prompt = "tags (space delimited): ")) +
'&extended=' +
encodeURIComponent(
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) { }
}, $browser_object = browser_object_links);