Skip to content

Instantly share code, notes, and snippets.

@serian
Created April 18, 2010 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serian/370100 to your computer and use it in GitHub Desktop.
Save serian/370100 to your computer and use it in GitHub Desktop.
firefox,ldr,userChrome.js,userContent.js
// ==UserScript==
// @name ldrquote
// @description firefox、ldrで閲覧中の記事の選択範囲を、記事URLなどとともにクリップボードにコピーする。"q"で実行
// @version 0.1
// @include http://reader.livedoor.com/reader/
// @privilege true
// ==/UserScript==
//firefox,userChrome.js,userContent.jsでのみ動作確認
//ほんとはuserMenuでコンテキストメニューからやりたい。
(function(){
function copyText2Clipboard(text){
if(text == "") return false;
try{
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
str.data = text;
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
trans.addDataFlavor("text/unicode");
trans.setTransferData("text/unicode", str, text.length * 2);
var clipid = Components.interfaces.nsIClipboard;
Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid).setData(trans, null, clipid.kGlobalClipboard);
} catch (x) {
dump(x);
}
return true;
}
var copyf = function(){
var sel = '';
if( window.location != 'http://reader.livedoor.com/reader/')return;
if( sel = window.getSelection(),sel == '') return;
var feedtitle = unsafeWindow.get_active_feed().channel.title;
var itemtitle = unsafeWindow.get_active_item(true).title;
var link = unsafeWindow.get_active_item(true).link;
var text = sel + "\n" +itemtitle + " - " + feedtitle +"\n" + link;
copyText2Clipboard(text);
};
unsafeWindow.Keybind.add('q',copyf);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment