summaryrefslogtreecommitdiff
path: root/.vimperator/plugin/paste.js
blob: cfe78264230d92c90df09fa431e225f65aecef0d (plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/**
 **
 ** paste.js
 ** 
 ** description :
 **  pastebin is a script to paste clipboard's content
 **  in a new pastebin. Its URL is yanked.
 **
 **
 **
 * @author Yoann Lamouroux (spamonsophia@gmail.com) (legreffier@freenode)
 * @version 1.0 now exhaustive.
 *
 **/
var INFO =
<plugin name="paste" version="1.0"
		href="http://www.overthewire.org/"
		summary="Pastebin wrapper"
		xmlns="http://vimperator.org/namespaces/liberator">
	<author email="spamonsophia@gmail.com">Yoann Lamouroux</author>
	<license href="http://www.opensource.org/licenses/mit-license.html">MIT</license>
	<project name="Vimperator" minVersion="2.0" />
	<p>
		This plugin allow you to fill pastebins with clipboard's content.
	</p>
	<item>
		<tags>:past :pastebin</tags>
		<spec>:past[ebin] <oa>-name=author</oa> <oa>-language=language</oa> <oa>-private</oa> <oa>-mail=you@lolcat.org</oa> <oa>-subdomain=subdom</oa></spec>
		<description>
			<p>Paste the clipboard's content in a new pastebin, yanks its URL.</p>
			<p>You can use several options : </p>
			<ul>
				<li>-name your_name (or -n) : to give your pastes an author</li>
				<li>-language syntax_hilight (or -l) : to enable syntax hilighting</li>
				<li>-private (or -p) : to make your pastebin private (sort of)</li>
				<li>-mail login@mail.tld (or -m) : add a mail address</li>
				<li>-subdomain subdom (or -s) : send the buffer to subdom.pastebin.com</li>
			</ul>
		</description>
	</item>
</plugin>;

function pasteBin(arg) {
	var url = "http://pastebin.com/api_public.php";
	var http = new XMLHttpRequest();
	var params = arg + "paste_code=";
	var paste = util.readFromClipboard();
	if(!paste) {
		liberator.echoerr("The clipboard is empty.\n"); 
		return;
	} else {
		params += paste;
	}
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.send(params);
	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) {
			util.copyToClipboard(http.responseText);
			liberator.echo("Yanked " + http.responseText);
		} 		
	}
}

var expilist = [['N', 'Never'], ['10M', 'Ten minutes'], ['1H', 'One hour'], ['1D', 'One day'], ['1M', 'One month']];

var langlist = [    // looooooongcat, he's rather long.
	['abap', 'ABAP'], 
	['actionscript', 'ActionScript'], 
	['actionscript3', 'ActionScript3'], 
	['ada', 'Ada'],
	['apache', 'Apache'], 
	['applescript', 'AppleScript'], 
	['apt_sources', 'APT Sources'], 
	['asm', 'Assembler'], 
	['asp', 'ASP'], 
	['autoit', 'AutoIt'], 
	['avisynth', 'Avisynth'], 
	['bash', 'Bash script'], 
	['basic4gl', 'Basic4GL'], 
	['bibtex', 'BibTeXgi'], 
	['blitzbasic', 'Blitz Basic'], 
	['bnf', 'BNF'], 
	['boo', 'Boo'], 
	['bf', 'BrainFuck'], 
	['c', 'C'], 
	['c_mac', 'C for Macs'], 
	['cill', 'C Intermediate Language'], 
	['csharp', 'C#'], 
	['cpp', 'C++'], 
	['caddcl', 'CAD DCL'], 
	['cadlisp', 'CAD Lisp'], 
	['cfdg', 'CFDG'], 
	['klonec', 'Clone C'], 
	['klonecpp', 'Clone C++'], 
	['cmake', 'CMake'], 
	['cobol', 'Cobol'], 
	['cfm', 'ColdFusion'], 
	['css', 'CSS'], 
	['d', 'D'], 
	['dcs', 'DCS'], 
	['delphi', 'Delphi'], 
	['dff', 'Diff'], 
	['div', 'DIV'], 
	['dos', 'DOS'], 
	['dot', 'DOT'], 
	['eiffel', 'Eiffel'], 
	['email', 'E-mail'], 
	['erlang', 'Erlang'], 
	['fo', 'FO Language'], 
	['fortran', 'Fortran'], 
	['freebasic', 'FreeBasic'], 
	['gml', 'Game Maker'], 
	['genero', 'Genero'], 
	['gettext', 'GetText'], 
	['groovy', 'Groovy'], 
	['haskell', 'Haskell'], 
	['hq9plus', 'HQ9 Plus'], 
	['html4strict', 'HTML4 strict'], 
	['idl', 'IDL'], 
	['ini', 'INI configuration file'], 
	['inno', 'Inno script'], 
	['intercal', 'INTERCAL'], 
	['io', 'IO'], 
	['java', 'Java'], 
	['java5', 'Java5'], 
	['javascript', 'JavaScript'], 
	['kixtart', 'KiXtart'], 
	['latex', 'Latex'], 
	['lsl2', 'Linden Scripting'], 
	['lisp', 'Lisp'], 
	['locobasic', 'Loco Basic'], 
	['lolcode', 'LOL Code'], 
	['lotusformulas', 'Lotus Formulas'], 
	['lotusscript', 'Lotus Script'], 
	['lscript', 'LScript'], 
	['lua', 'Lua'], 
	['m68k', 'M68000 Assembler'], 
	['make', 'Makefile'],  
	['matlab', 'MatLab'], 
	['matlab', 'MatLab'], 
	['mirc', 'mIRC'], 
	['modula3', 'Modula 3'], 
	['mpasm', 'MPASM'], 
	['mxml', 'MXML'], 
	['mysql', 'MySQL'], 
	['nsis', 'NullSoft Installer'], 
	['oberon2', 'Oberon 2'], 
	['objc', 'Objective C'], 
	['ocaml-brief', 'OCaml Brief'], 
	['ocaml', 'OCaml'], 
	['glsl', 'OpenGL Shading'], 
	['oobas', 'OpenOffice Basic'], 
	['oracle11', 'Oracle 11'], 
	['oracle8', 'Oracle 8'], 
	['pascal', 'Pascal'], 
	['pawn', 'PAWN'], 
	['per', 'Per'], 
	['perl', 'Perl'], 
	['php', 'PHP'], 
	['php-brief', 'PHP Brief'], 
	['pic16', 'Pic 16'], 
	['pixelbender', 'Pixel Bender'], 
	['plsql', 'PL/SQL'], 
	['povray', 'POV-Ray'], 
	['powershell', 'PowerShell'], 
	['progress', 'Progress'], 
	['prolog', 'Prolog'], 
	['properties', 'Properties'], 
	['providex', 'ProvideX'], 
	['python', 'Python'], 
	['qbasic', 'Quick Basic'], 
	['rails', 'Rails'], 
	['rebol', 'REBOL'], 
	['reg', 'REG'], 
	['robots', 'Robots'], 
	['ruby', 'Ruby'], 
	['gnuplot', 'Ruby Gnuplot'], 
	['sas', 'SAS'], 
	['scala', 'Scala'], 
	['scheme', 'Scheme'], 
	['scilab', 'Scilab'], 
	['sdlbasic', 'SDL Basic'], 
	['smalltalk', 'SmallTalk'], 
	['smarty', 'Smarty'], 
	['sql', 'SQL'], 
	['tsql', 'T-SQL'], 
	['tcl', 'TCL'], 
	['tcl', 'tcl'], 
	['teraterm', 'Tera Term'], 
	['thinbasic', 'thinBasic'], 
	['typoscript', 'TypoScript'], 
	['unreal', 'unrealScript'], 
	['vbnet', 'VB.NET'], 
	['verilog', 'VeriLog'], 
	['vhdl', 'VHDL'], 
	['vim', 'Vim'], 
	['visualprolog', 'Visual Pro Log'], 
	['vb', 'Visual Basic'], 
	['visualfoxpro', 'VisualFoxPro'], 
	['whitespace', 'WhiteSpace'], 
	['whois', 'WHOIS'], 
	['winbatch', 'Win Batch'], 
	['xml', 'XML'], 
	['xorg_conf', 'xorg.conf'], 
	['xpp', 'XPP'], 
	['z80', 'z80 Assembler']];

commands.addUserCommand(
	"past[ebin]", 
	"pastebin the clipboard, store the address in clipboard",
	function(args) { 
		var prefix = "";
		if(args["-name"]) {
			prefix += "paste_name=" + args["-name"] + "&";
		}
		if(args["-language"]) {
			var ok = 0;
			for each (l in langlist) {
				if(args["-language"] === l[0]) {
					prefix += "paste_format=" + args["-language"] + "&";
					ok++;
					break;
				}
			}
			if(ok == 0) liberator.echo("language argument not recognized, defaulting to none");
		}
		if(args["-expire"]) {
			var ok = 0;
			for each (l in expilist) {
				if(args["-expire"] === l[0]) {
					prefix += "paste_expire_date=" + args["-expire"] + "&";
					ok++;
					break;
				}
			}
			if(ok == 0) { 
				liberator.echo("expire argument not recognized, defaulting to minutes");
				prefix += "paste_expire_date=10M&";
			}
		}
		if(args["-mail"]) {
			prefix += "paste_email=" + args["-mail"] + "&";
		}
		if(args["-subdomain"]) {
			prefix += "paste_subdomain=" + args["-subdomain"] + "&";
		}
		if(args["-private"]) {
			prefix += "paste_private=1&"
		}
		pasteBin(prefix); 
	}, {
		options: [ 
			[["-name", "-n"], commands.OPTION_STRING, function(arg) /\w+/.test(arg)],
			[["-language", "-l"], commands.OPTION_STRING, null, langlist],
			[["-expire", "-e"], commands.OPTION_STRING , null, expilist],
			[["-mail", "-m"], commands.OPTION_STRING, function(arg) /^.+\@.+\.\w+$/.test(arg)],
			[["-subdomain", "-s"], commands.OPTION_STRING, function(arg) /\w+/.test(arg)],
			[["-private", "-p"], commands.OPTION_NOARG]
		] }
);