Created
January 27, 2009 20:55
-
-
Save ozten/53534 to your computer and use it in GitHub Desktop.
Ever find yourself doing View Source > Find <title> > Copy ? Not any more
This file contains hidden or 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
CmdUtils.CreateCommand({ | |
name: "copy-page-title-gist", | |
description: "Replaces View Source < Find >title< < Copy", | |
icon: "http://www.ozten.com/random/clipboard-16x16.png", | |
preview: function(pblock, input){ | |
pblock.innerHTML = "Copies '<code>" + this.pageTitle() + "'</code> into your copy/paste Clipboard."; | |
}, | |
execute: function(){ | |
// http://developer.mozilla.org/en/Using_the_Clipboard | |
var copytext = this.pageTitle(); | |
var str = Components.classes["@mozilla.org/supports-string;1"]. | |
createInstance(Components.interfaces.nsISupportsString); | |
str.data = copytext; | |
var trans = Components.classes["@mozilla.org/widget/transferable;1"]. | |
createInstance(Components.interfaces.nsITransferable); | |
trans.addDataFlavor("text/unicode"); | |
trans.setTransferData("text/unicode", str, copytext.length * 2); | |
var clipid = Components.interfaces.nsIClipboard; | |
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid); | |
clip.setData(trans, null, clipid.kGlobalClipboard); | |
}, | |
pageTitle: function(){ | |
return jQuery("title", Application.activeWindow.activeTab.document).text(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment