123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- /*
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 3.0 of the License, or (at your option) any later version.
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with this library.
- */
- var http = require('http');
- var querystring = require('querystring');
- Hooks.addMenuItem("Text/Paste to Pamrel", "cmd-shift-p", function () {
- Recipe.run(function(recipe) {
- var options = {
- host: 'pamrel.lu',
- port: 80,
- method: 'POST',
- path: '/',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': recipe.text.length
- }
- }
- var request = http.request(options, function (response) {
- response.setEncoding('utf8');
- var buffer = '';
- response.on('data', function (chunk) {
- buffer += chunk;
- })
- if (response.statusCode != 200) {
- Alert.show('Error: ' + http.STATUS_CODES[response.statusCode] + ' (' + response.statusCode + ')');
- return;
- }
- response.on('end', function () {
- // There is a \n at the end for terminal outputs
- buffer = buffer.replace('\n', '')
- // Copy to paste buffer and tell user
- Clipboard.copy(buffer);
- Alert.beep();
- });
- });
- var requestBody = querystring.stringify({'content': recipe.text})
- request.write(requestBody);
- request.end();
- });
- });
|