aboutsummaryrefslogtreecommitdiffstats
path: root/conkeror
diff options
context:
space:
mode:
authorGravatar Tom Willemse2016-09-28 14:39:42 +0200
committerGravatar Tom Willemse2016-09-28 14:39:42 +0200
commitf17ca04d079f13e6bb4b30553183157bafa1a017 (patch)
tree6afbcf93ad70df323a6808c770dd4471dafc533d /conkeror
parentc6f43c514b4b5afe3bd156f7522fc23589cc77d1 (diff)
downloadnew-dotfiles-f17ca04d079f13e6bb4b30553183157bafa1a017.tar.gz
new-dotfiles-f17ca04d079f13e6bb4b30553183157bafa1a017.zip
Add scuttle config
Diffstat (limited to 'conkeror')
-rw-r--r--conkeror/.conkerorrc/.gitignore1
-rw-r--r--conkeror/.conkerorrc/init.org48
-rw-r--r--conkeror/.conkerorrc/site-js/scuttle.js152
3 files changed, 201 insertions, 0 deletions
diff --git a/conkeror/.conkerorrc/.gitignore b/conkeror/.conkerorrc/.gitignore
index bac1726..ee15bbb 100644
--- a/conkeror/.conkerorrc/.gitignore
+++ b/conkeror/.conkerorrc/.gitignore
@@ -1 +1,2 @@
init.js
+private.js
diff --git a/conkeror/.conkerorrc/init.org b/conkeror/.conkerorrc/init.org
index ab07b92..dc2b81c 100644
--- a/conkeror/.conkerorrc/init.org
+++ b/conkeror/.conkerorrc/init.org
@@ -58,3 +58,51 @@ description.
#+BEGIN_SRC js
define_opensearch_webjump("mdn", "mozilla-developer-network.xml");
#+END_SRC
+
+
+Add the ~site-js/~ directory to the load path.
+
+#+BEGIN_SRC js
+ function add_to_load_path(new_path) {
+ if (new_path.startsWith('/')) {
+ load_paths.push("file://" + new_path);
+ } else {
+ let path = get_home_directory();
+ path.append('.conkerorrc');
+ path.append(new_path);
+
+ load_paths.push(path);
+ }
+ }
+
+ add_to_load_path('site-js');
+#+END_SRC
+
+* Scuttle
+
+ Load the scuttle module.
+
+ #+BEGIN_SRC js
+ require('scuttle');
+ #+END_SRC
+
+ Set the URL of my scuttle installation.
+
+ #+BEGIN_SRC js
+ scuttle_url = 'https://ryuslash.org/scuttle/';
+ #+END_SRC
+
+ Add the bookmarked widget to the mode line. This requires my
+ customized version of Scuttle to be able to check if a buffer has
+ been bookmarked or not.
+
+ #+BEGIN_SRC js
+ add_hook('mode_line_hook', mode_line_adder(scuttle_bookmarked_widget));
+ #+END_SRC
+
+ Set-up keybindings for posting to scuttle.
+
+ #+BEGIN_SRC js
+ define_key(default_global_keymap, 'p', 'scuttle-post');
+ define_key(default_global_keymap, 'P', 'scuttle-post-link');
+ #+END_SRC
diff --git a/conkeror/.conkerorrc/site-js/scuttle.js b/conkeror/.conkerorrc/site-js/scuttle.js
new file mode 100644
index 0000000..9b7373b
--- /dev/null
+++ b/conkeror/.conkerorrc/site-js/scuttle.js
@@ -0,0 +1,152 @@
+define_hook('scuttle_bookmarked_hook');
+
+define_variable("scuttle_username", null,
+ "Username of te scuttle account.");
+define_variable("scuttle_password", null,
+ "Password of the scuttle account.");
+define_variable("scuttle_url", null,
+ "The URL where scuttle can be found.");
+
+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_get_url(path)
+{
+ let url = make_uri(scuttle_url);
+
+ if (scuttle_username != null)
+ url.username = scuttle_username;
+ if (scuttle_password != null)
+ url.password = scuttle_password;
+
+ url.path += '/api';
+
+ return url.spec + '/' + path;
+}
+
+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 = scuttle_get_url('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 = 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) { }
+ });
+
+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 = 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) { }
+ }, $browser_object = browser_object_links);