Created
August 28, 2009 04:22
-
-
Save Yasushi/176780 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Aliases = { | |
t: { | |
help: 'title', | |
get text() info().title, | |
}, | |
u: { | |
help: 'URL', | |
get text() info().url, | |
}, | |
a: { | |
help: 'title and URL as link tag', | |
get text(){ with(info()) return <a href={url}>{title}</a>.toXMLString() }, | |
}, | |
f: { | |
help: 'favicon as data:image/png', | |
get text() img2du(Utils.currentChromeWindow.gBrowser.selectedTab.image), | |
}, | |
s: { | |
help: 'selection as anchor text', | |
get text(){ | |
with(info()) | |
return ((<a href={url} title={title}><x/></a>+'') | |
.replace(/\s*<x\/>\s{0,}/, CmdUtils.getSelection())); | |
} | |
}, | |
h: { | |
help: 'selection as HTML', | |
get text() CmdUtils.getHtmlSelection(), | |
}, | |
q: { | |
help: 'selection as blockquote', | |
get text(){ | |
with(info()) | |
return ((<blockquote cite={url} title={title}><x/></blockquote>+'') | |
.replace(/\s*<x\/>\s{0,}/, CmdUtils.getHtmlSelection())); | |
} | |
}, | |
m: { | |
help: 'selection as markdown', | |
get text(){ | |
with(info()) | |
return ('['+CmdUtils.getSelection()+']('+url+' "'+title+'")'); | |
} | |
}, | |
i: { | |
help: 'selected image (or "1x1 transparent" if none) as data:image/png', | |
get text(){ | |
var doc = CmdUtils.getDocument(); | |
return img2du( | |
(/^image/.test(doc.contentType) | |
? doc.URL | |
: (/src=([\"\']?)(\S+?)\1/(CmdUtils.getHtmlSelection())||0)[2]), | |
('data:image/png;base64,'+ | |
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAA'+ | |
'AAC0lEQVQI12NgYAAAAAMAASDVlMcAAAAASUVORK5CYII=')); | |
} | |
}, | |
j: { | |
help: 'snapshot of current tab as data:image/jpeg', | |
get text() CmdUtils.getWindowSnapshot(CmdUtils.getWindow(), {width: 600}), | |
}, | |
M: { | |
help: 'selection as MD5 hash', | |
get text() Utils.computeCryptoHash('MD5', CmdUtils.getSelection()), | |
}, | |
S: { | |
help: 'selection as SHA1 hash', | |
get text() Utils.computeCryptoHash('SHA1', CmdUtils.getSelection()), | |
}, | |
d: { | |
help: 'current datetime in RFC3399 format', | |
get text() new Date().toString('yyyy-MM-ddThh:mm:ddZ'), | |
}, | |
J: { | |
help: 'URL as JSON', | |
get text(){ | |
var {url} = info(), o = {url: url}, | |
a = context.focusedWindow.document.createElement('a'); | |
a.href = url; | |
for each(var p in ['protocol', 'host', 'pathname', 'search', 'hash']) | |
o[p] = a[p]; | |
o.query = o.search ? Utils.urlToParams(o.search) : {}; | |
return Utils.encodeJson(o); | |
}, | |
}, | |
X: { | |
help: 'selection as hex', | |
get text(){ | |
return CmdUtils.getSelection() | |
.replace(/[^ -~]|\\/g, function(m0){ | |
var code = m0.charCodeAt(0); | |
return '\\u' + ((code < 0x10) ? '000' : | |
(code < 0x100) ? '00' : | |
(code < 0x1000) ? '0' : '') | |
+ code.toString(16); }); | |
} | |
}, | |
x: { | |
help: 'selected hex as unescaped', | |
get text(){ | |
return CmdUtils.getSelection() | |
.replace(/\\u([a-fA-F0-9]{4})/g, function(m0, m1){ | |
return String.fromCharCode(parseInt(m1, 16)); }); | |
} | |
}, | |
P: { | |
help: 'selection as EncodeURIComponent (UTF-8)', | |
get text(){ | |
return encodeURIComponent(CmdUtils.getSelection()); | |
} | |
}, | |
p: { | |
help: 'selection as DecodeURIComponent (UTF-8)', | |
get text(){ | |
return decodeURIComponent(CmdUtils.getSelection()); | |
} | |
}, | |
n: { | |
help: 'line feed character', | |
text: '\n', | |
}, | |
T: { | |
help: 'tab character', | |
text: '\t', | |
}, | |
/* | |
_: { | |
help: '', | |
get text(){}, | |
}, | |
*/ | |
}, | |
REA = RegExp('['+ [k for(k in Aliases)] +']', 'g'), | |
Help = ('<ul style="list-style:none; margin:0.2em; padding:0">'+ | |
[<li><tt><b>{k}</b>:</tt>{v.help}</li> | |
for([k, v] in Iterator(Aliases))].join('') + | |
'</ul>'), | |
DUCache = {'': 'data:,...'}; | |
function img2du(src, ph)( | |
DUCache[src] || | |
(CmdUtils.getImageSnapshot(src, function(du){ DUCache[src] = du }), | |
DUCache[src] = ph || DUCache[''])); | |
function info(){ | |
var t, u, {top, document: {title, URL}} = CmdUtils.getWindow(); | |
(/^https?:\/\/www\.google\.\w+\/reader\/view/.test(URL) | |
? ({title: t, url: u}) = top.wrappedJSObject.getPermalink() : | |
/^https?:\/\/(?:reader\.livedoo|fastladde)r\.com\/reader/.test(URL) | |
? ({title: t, link: u}) = top.wrappedJSObject.get_active_item(1) : 0); | |
return {title: t || title, url: u || URL}; | |
} | |
function parse(txt) txt.replace(REA, replr); | |
function replr(m) Aliases[m].text; | |
CmdUtils.CreateCommand({ | |
names: ['copy'], | |
icon: 'chrome://ubiquity/skin/icons/convert.png', | |
arguments: [{role: 'object', nountype: { | |
label: '?', | |
suggest: function(txt, htm, cb, sx){ | |
if(sx || !txt) return []; | |
var s = {text: txt, summary: txt.replace(REA, this.mark)}; | |
this.default = function() s; | |
return [s]; | |
}, | |
mark: function($) '<u>'+ $ +'</u>', | |
}}], | |
description: ('Collects various informations into a text'+ | |
' and sends it to your clipboard.'), | |
help: (<>Try "copy tnu" to copy the page title and url | |
separated by a new line.<br/><br/> | |
[ Aliases ]</> + Help), | |
execute: function({object: {text}}){ | |
if(!text) return; | |
Utils.clipboard.text = parse(text); | |
displayMessage({icon: this.icon, title: this.name, text: text}); | |
}, | |
preview: function(pbl, {object: {text}}){ | |
pbl.innerHTML = | |
<pre>{parse(text) || <em>empty</em>}</pre>.toXMLString() + Help; | |
}, | |
previewDelay: 222, | |
author: 'satyr'.link('http://ubigist.appjet.net/?o=satyr'), | |
contributors: ['powchin'.link('http://friendfeed.com/powchin')], | |
license: 'MIT', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment