ozten (owner)

Revisions

gist: 53534 Download_button fork
public
Description:
Ever find yourself doing View Source > Find <title> > Copy ? Not any more
Public Clone URL: git://gist.github.com/53534.git
Embed All Files: show embed
ubiquity-copy-page-title-gist.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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();
  }
});