'use strict'; // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below import * as vscode from 'vscode'; import axios from 'axios'; import * as ncp from 'copy-paste'; import {Utils} from './utils'; import * as Crypto from 'crypto-js'; // this method is called when your extension is activated // your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { console.log('Congratulations, your extension "kopy-io-plugin" is now active!'); let olaCommand = vscode.commands.registerCommand('extension.kopyit', (data) => { // The code you place here will be executed every time your command is executed const editor = vscode.window.activeTextEditor; const document = editor.document; const supportedLanguageTypes = ["Auto-Detect", "Plain Text", "C", "C++", "CoffeeScript", "CSS", "diff", "Go", "HTML", "Java", "JavaScript", "JSON", "Markdown", "LESS", "Perl", "PHP", "Python", "Ruby", "Sass", "SCSS", "Shell", "SQL", "XML", "APL", "Asterisk", "Cobol", "C#", "Clojure", "Common Lisp", "Cypher", "D", "DTD", "Dylan", "ECL", "Eiffel", "Erlang", "Fortran", "F#", "Gas", "Gherkin", "GitHub Flavored Markdown", "Groovy", "HAML", "Haskell", "Haxe", "ASP.NET", "Embedded Javascript", "JavaServer Pages", "HTTP", "Jade", "JSON-LD", "TypeScript", "Jinja2", "Julia", "Kotlin", "LiveScript", "Lua", "mIRC", "Modelica", "Nginx", "NTriples", "OCaml", "Octave", "Pascal", "PEG.js", "Pig", "Properties files", "Puppet", "Cython", "R", "reStructuredText", "Rust", "Scala", "Scheme", "Sieve", "Slim", "Smalltalk", "Smarty", "SmartyMixed", "Solr", "SPARQL", "MariaDB", "sTeX", "LaTeX", "SystemVerilog", "Tcl", "TiddlyWiki", "Tiki wiki", "TOML", "Turtle", "VB.NET", "VBScript", "Velocity", "Verilog", "XQuery", "YAML", "Z80"]; let selectedText = document.getText(new vscode.Range(editor.selection.start, editor.selection.end)); let supportedTimes = { ten_min: 600, one_hr: 3600, one_day: 86400, three_days: 259200, one_week: 604800, one_month: 2592000 }; let randomKey = Utils.createKey(14); let encryptedData = Crypto.AES.encrypt(selectedText, randomKey).toString(); axios({ method: 'post', url: 'http://kopy.io/documents', data: `data=${encodeURIComponent(encryptedData)}&keep=${supportedTimes.one_hr}&language=-1&&security=encrypted&font=Source+Code+Pro&font-size=auto&line-spacing=-1&wrapping=Disabled` }).then((response) => { if(response.status===200){ let openUrl = "Open Url"; let copyUrl = "Copy Url to your clipboard (!!)"; let finalUrl = `https://kopy.io/${response.data.key}#${randomKey}`; vscode.window.showInformationMessage('Your data is Kopied', openUrl, copyUrl).then( (selectedOption)=>{ if(selectedOption==openUrl){ vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(finalUrl)) }else if(selectedOption==copyUrl){ ncp.copy(finalUrl, () => { vscode.window.showInformationMessage('Kopy.io url is on your Clipboard'); }); } } ); }else{ vscode.window.showErrorMessage('Cannot post the selected text to kopy.io'); } }).catch((error) => { console.log("kopy.io Error", error); vscode.window.showErrorMessage('Cannot post the selected text to kopy.io'); }) }); context.subscriptions.push(olaCommand); } // this method is called when your extension is deactivated export function deactivate() { }