Trapezoid
GPL
Social Bookmark direct add script
for Migemo search: require XUL/Migemo Extension
Parts
- http://d.hatena.ne.jp/fls/20080309/p1
- Pagerization (c) id:ofk
- AutoPagerize (c) id:swdyh
- direct_delb.js id:mattn
- JSDeferred id:cho45
Viriables
g:direct_sbm_use_services_by_tag
Use social bookmark services to extract tags
- h
- Hatena Bookmark
- d
- del.icio.us
- l
- livedoor clip
- g
- Google Bookmarks
- p
- Places (Firefox bookmarks)
- P
- pinboard.in
Usage: let g:direct_sbm_use_services_by_tag = "hdl"
g:direct_sbm_use_services_by_post
Use social bookmark services to post
- h
- Hatena Bookmark
- d
- del.icio.us
- l
- livedoor clip
- g
- Google Bookmarks
- P
- pinboard.in
Usage: let g:direct_sbm_use_services_by_post = "hdl"
g:direct_sbm_echo_type
Post message type
- simple
- single line, no posted services description
- multiline
- multi line, display services description
- none
- hide post message
g:direct_sbm_is_normalize
Use normalize permalink
g:direct_sbm_is_use_migemo
Use Migemo completion
g:direct_sbm_private
Private bookmark
-
:btags
:btags
Extract tags from social bookmarks for completion
-
:sbm
:sbm -service service
Post a current page to social bookmarks.
service: Specify target SBM services to post (default: "hdl")
-
:bentry
:bentry
Goto Bookmark Entry Page
-
:bicon
:bicon
Show Bookmark Count as Icon
`;
(function(){
var evalFunc = window.eval;
try {
var sandbox = new Components.utils.Sandbox(window);
if (Components.utils.evalInSandbox("true", sandbox) === true) {
evalFunc = function(text) {
return Components.utils.evalInSandbox(text, sandbox);
}
}
} catch(e) { liberator.log('warning: direct_bookmark.js is working with unsafe sandbox.'); }
var useServicesByPost = liberator.globalVariables.direct_sbm_use_services_by_post || 'hdl';
var useServicesByTag = liberator.globalVariables.direct_sbm_use_services_by_tag || 'hdl';
var echoType = liberator.globalVariables.direct_sbm_echo_type || 'multiline';
var isNormalize = typeof liberator.globalVariables.direct_sbm_is_normalize == 'undefined' ?
true : evalFunc(liberator.globalVariables.direct_sbm_is_normalize);
var isUseMigemo = typeof liberator.globalVariables.direct_sbm_is_use_migemo == 'undefined' ?
true : evalFunc(liberator.globalVariables.direct_sbm_is_use_migemo);
var isPrivate = typeof liberator.globalVariables.direct_sbm_private == 'undefined' ?
false : evalFunc(liberator.globalVariables.direct_sbm_private);
var XMigemoCore;
try{
XMigemoCore = Components.classes['@piro.sakura.ne.jp/xmigemo/factory;1']
.getService(Components.interfaces.pIXMigemoFactory)
.getService("ja");
}
catch(ex if ex instanceof TypeError){}
function Deferred () this instanceof Deferred ? this.init(this) : new Deferred();
Deferred.prototype = {
init : function () {
this._next = null;
this.callback = {
ok: function (x) x,
ng: function (x) { throw x }
};
return this;
},
next : function (fun) this._post("ok", fun),
error : function (fun) this._post("ng", fun),
call : function (val) this._fire("ok", val),
fail : function (err) this._fire("ng", err),
cancel : function () {
(this.canceller || function () {})();
return this.init();
},
_post : function (okng, fun) {
this._next = new Deferred();
this._next.callback[okng] = fun;
return this._next;
},
_fire : function (okng, value) {
var self = this, next = "ok";
try {
value = self.callback[okng].call(self, value);
} catch (e) {
next = "ng";
value = e;
}
if (value instanceof Deferred) {
value._next = self._next;
} else if (self._next) {
self._next._fire(next, value);
}
return this;
}
};
Deferred.next = function (fun) {
var d = new Deferred();
var id = setTimeout(function () { clearTimeout(id); d.call() }, 0);
if (fun) d.callback.ok = fun;
d.canceller = function () { try { clearTimeout(id) } catch (e) {} };
return d;
};
function http (opts) {
var d = Deferred();
var req = new XMLHttpRequest();
req.open(opts.method, opts.url, true, opts.user || null, opts.password || null);
if (opts.headers) {
for (var k in opts.headers) if (opts.headers.hasOwnProperty(k)) {
req.setRequestHeader(k, opts.headers[k]);
}
}
req.onreadystatechange = function () {
if (req.readyState == 4) d.call(req);
};
req.send(opts.data || null);
d.xhr = req;
return d;
}
Deferred.Deferred = Deferred;
Deferred.http = http;
function WSSEUtils(aUserName, aPassword){
this._init(aUserName, aPassword);
}
WSSEUtils.prototype = {
get userName() this._userName,
get noce() this._nonce,
get created() this._created,
get passwordDigest() this._passwordDigest,
getWSSEHeader: function(){
var result = [
'UsernameToken Username="' + this._userName + '", ',
'PasswordDigest="' + this._passwordDigest + '=", ',
'Nonce="' + this._nonce + '", ',
'Created="' + this._created + '"'
].join("");
return result;
},
_init: function(aUserName, aPassword){
var uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
var seed = (new Date()).toUTCString() + uuidGenerator.generateUUID().toString();
this._userName = aUserName;
this._nonce = this._getSha1Digest(seed, true);
this._created = this._getISO8601String((new Date()));
this._passwordDigest = this._getSha1Digest(this._getSha1Digest(seed, false) + this._created + aPassword, true);
},
_getSha1Digest: function(aString, aBase64){
var cryptoHash = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash);
cryptoHash.init(Ci.nsICryptoHash.SHA1);
var inputStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
inputStream.setData(aString, aString.length);
cryptoHash.updateFromStream(inputStream, -1);
return cryptoHash.finish(aBase64);
},
_getISO8601String: function(aDate){
var result = [
zeropad(aDate.getUTCFullYear(), 4), "-",
zeropad(aDate.getUTCMonth() + 1, 2), "-",
zeropad(aDate.getUTCDate(), 2), "T",
zeropad(aDate.getUTCHours(), 2), ":",
zeropad(aDate.getUTCMinutes(), 2), ":",
zeropad(aDate.getUTCSeconds(), 2), "Z"
].join("");
return result;
function zeropad(s, l){
s = String(s);
while(s.length < l){
s = "0" + s;
}
return s;
}
}
};
// copied from AutoPagerize (c) id:swdyh
function getElementsByXPath(xpath, node){
node = node || document;
var nodesSnapshot = (node.ownerDocument || node).evaluate(xpath, node, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var data = [];
for(var i = 0, l = nodesSnapshot.snapshotLength; i < l;
data.push(nodesSnapshot.snapshotItem(i++)));
return (data.length > 0) ? data : null;
}
function getFirstElementByXPath(xpath, node){
node = node || document;
var result = (node.ownerDocument || node).evaluate(xpath, node, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null);
return result.singleNodeValue ? result.singleNodeValue : null;
}
// copied from http://d.hatena.ne.jp/odz/20060901/1157165797 id:odz
function parseHTML(text) {
var createHTMLDocument = function() {
var xsl = (new DOMParser()).parseFromString(
['',
'