Created
April 18, 2010 08:07
-
-
Save serian/370100 to your computer and use it in GitHub Desktop.
firefox,ldr,userChrome.js,userContent.js
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
// ==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