legacy-dotfiles/conkeror/.conkerorrc/site-js/scuttle.js

129 lines
5 KiB
JavaScript

// 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=' +
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) { }
});
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=' +
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) { }
}, $browser_object = browser_object_links);