Skip to content

Instantly share code, notes, and snippets.

@ozten
Created January 27, 2009 20:55
Show Gist options
  • Save ozten/53534 to your computer and use it in GitHub Desktop.
Save ozten/53534 to your computer and use it in GitHub Desktop.
Ever find yourself doing View Source > Find <title> > Copy ? Not any more
CmdUtils.CreateCommand({
name: "copy-page-title-gist",
description: "Replaces View Source &lt; Find &gt;title&lt; &lt; 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