Welcome, guest | Sign In | My Account | Store | Cart

Submit the select text to pastebin and copy to clipboard the URL returned from service.

The programming language is auto-detected.

The statusbar will show the message about submission status.

Setting username

By default the post is submitted with 'anonymous' user, to change it set the nick variable to a different value

JavaScript, 139 lines
  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
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var pastebin = {
    post : function() {
        var selection = ko.views.manager.currentView.selection;
        
        if (selection == "") {
            ko.dialogs.alert("No selection found");
            return;
        }
        
        var lang = encodeURIComponent(this.ko2pastebinLanguage());
        var text = encodeURIComponent(selection);
        var nick = encodeURIComponent("anonymous");
        var expiry = encodeURIComponent("d");
        
        var httpReq = new XMLHttpRequest();
        httpReq.open("post", "http://pastebin.mozilla.org", false);
        httpReq.setRequestHeader("content-type",
                                 "application/x-www-form-urlencoded");

        var requestString = "parent_pid=&format={1}&code2={2}&poster={3}&paste=Send&expiry={4}";
        var sendString = requestString
                            .replace("{1}", lang)
                            .replace("{2}", text)
                            .replace("{3}", nick)
                            .replace("{4}", expiry);
        httpReq.send(sendString);

        var url = this.getReturnURL(httpReq);
        this.copyText(url);
        ko.statusBar.AddMessage("Url " + url
                                + " copied on clipboard using lang " + lang,
                                "pastebin_macro", 3000, true)
    },
    
    getReturnURL : function(httpReq) {
        return "http://pastebin.mozilla.org/"
            + httpReq.responseText.match('name="parent_pid" value="(.*)"')[1];
    },
    
    copyText : function(str) {
        Components.classes["@mozilla.org/widget/clipboardhelper;1"]
            .getService(Components.interfaces.nsIClipboardHelper)
            .copyString(str); 
    },
    
    ko2pastebinLanguage : function() {
        var langMap = {};

        langMap["Text"] = "text";
        langMap["ActionScript"] = "actionscript";
        langMap["Ada"] = "ada";
        langMap["Apache"] = "apache";
        //langMap[""] = "applescript";
        langMap["Assembler"] = "asm";
        //langMap[""] = "asp";
        langMap["Bash"] = "bash";
        langMap["C++"] = "c";
        //langMap[""] = "c_mac";
        //langMap[""] = "caddcl";
        //langMap[""] = "cadlisp";
        langMap["C++"] = "cpp";
        //langMap[""] = "csharp";
        //langMap[""] = "cfm";
        langMap["CSS"] = "css";
        //langMap[""] = "d";
        //langMap[""] = "delphi";
        langMap["Diff"] = "diff";
        //langMap[""] = "dos";
        langMap["Eiffel"] = "eiffel";
        langMap["Fortran"] = "fortran";
        langMap["FreeBasic"] = "freebasic";
        //langMap[""] = "gml";
        langMap["HTML"] = "html4strict";
        //langMap[""] = "ini";
        langMap["Java"] = "java";
        langMap["JavaScript"] = "javascript";
        langMap["Lisp"] = "lisp";
        langMap["Lua"] = "lua";
        langMap["Matlab"] = "matlab";
        //langMap[""] = "mpasm";
        langMap["SQL"] = "mysql";
        langMap["Nsis"] = "nsis";
        //langMap[""] = "objc";
        //langMap[""] = "ocaml";
        //langMap[""] = "oobas";
        langMap["PL-SQL"] = "oracle8";
        langMap["Pascal"] = "pascal";
        langMap["Perl"] = "perl";
        langMap["PHP"] = "php";
        langMap["Python"] = "python";
        //langMap[""] = "qbasic";
        //langMap[""] = "robots";
        langMap["Ruby"] = "ruby";
        langMap["Scheme"] = "scheme";
        langMap["Smarty"] = "smarty";
        langMap["SQL"] = "sql";
        langMap["Tcl"] = "tcl";
        langMap["VisualBasic"] = "vb";
        //langMap[""] = "vbnet";
        //langMap[""] = "visualfoxpro";
        langMap["XBL"] = "xml";
        langMap["XML"] = "xml";
        langMap["XSLT"] = "xml";
        langMap["XUL"] = "xml";

        language = langMap[ko.views.manager.currentView.document.language];
        if (language == undefined) {
            return "text";
        }
        return language;
    }

};

function printKomodoLanguages() {
    append_to_command_output_window("", true);
    function printLang(hierarchy) {
        var children = new Object();
        var count = new Object();
    
        if (hierarchy.container == true)  {
            hierarchy.getChildren(children, count);
            children = children.value;
    
            for (i = 0; i < children.length; i++)  {
                printLang(children[i]);
            }
        } else {
            append_to_command_output_window(hierarchy.name);
        }
    }

    var langService = Components.classes["@activestate.com/koLanguageRegistryService;1"]
                .getService(Components.interfaces.koILanguageRegistryService);
    printLang(langService.getLanguageHierarchy());

}

pastebin.post();
Created by Davide Ficano on Wed, 31 Mar 2010 (GPL)
JavaScript recipes (69)
Davide Ficano's recipes (4)
Komodo Macros (15)

Required Modules

  • (none specified)

Other Information and Tasks