aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/extension.ts58
-rw-r--r--src/utils.ts40
2 files changed, 67 insertions, 31 deletions
diff --git a/src/extension.ts b/src/extension.ts
index 0b16250..f9855af 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -4,55 +4,53 @@
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) {
- // Use the console to output diagnostic information (console.log) and errors (console.error)
- // This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "kopy-io-plugin" is now active!');
- console.log(ncp);
-
- // The command has been defined in the package.json file
- // Now provide the implementation of the command with registerCommand
- // The commandId parameter must match the command field in package.json
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;
-
- // console.log(editor.selection);
+ 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));
- // console.log(selectedText);
- ncp.copy(selectedText, () => {
- console.log("Copied to Clipboard");
- });
+ 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: "raw:" + selectedText
+ data: `data=${encodeURI(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){
- // vscode.window.showInformationMessage('kopy.io Url : https://kopy.io/'+response.data.key);
- // vscode.window.showInformationMessage('Kopy.io It successfully',...['Open kopy.io',]).then((selection) => {
- // vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://kopy.io/'+response.data.key))
- // });
- vscode.window.showQuickPick(['Open kopy.io', 'Copy URL to Clipboard', 'Close'])
- .then((val) => {
- // vscode.window.showInformationMessage('You picked ' + val)
- if (val === 'Open kopy.io') {
- vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://kopy.io/'+response.data.key))
- } else if (val === 'Copy URL to Clipboard') {
- ncp.copy('https://kopy.io/' + response.data.key, () => {
- vscode.window.showInformationMessage('URL is on your Clipboard');
+ 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 {
- return false;
}
- });
+ }
+ );
}else{
vscode.window.showErrorMessage('Cannot post the selected text to kopy.io');
}
@@ -62,8 +60,6 @@ export function activate(context: vscode.ExtensionContext) {
console.log("kopy.io Error", error);
vscode.window.showErrorMessage('Cannot post the selected text to kopy.io');
})
- // Display a message box to the user
- // vscode.window.showInformationMessage('Hello Worlds!');
});
diff --git a/src/utils.ts b/src/utils.ts
new file mode 100644
index 0000000..40e985e
--- /dev/null
+++ b/src/utils.ts
@@ -0,0 +1,40 @@
+export class Utils {
+ static createKey(keyLength: number){
+ let keyspace: String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+ let text = '';
+ let index;
+ for (let i = 0; i < keyLength; i++)
+ {
+ index = Math.floor(Math.random() * keyspace.length);
+ text += keyspace.charAt(index);
+ }
+ return text;
+ }
+
+ static toUTF8Array(str) {
+ let utf8 = [];
+ for (var i=0; i < str.length; i++) {
+ let charcode = str.charCodeAt(i);
+ if (charcode < 0x80) utf8.push(charcode);
+ else if (charcode < 0x800) {
+ utf8.push(0xc0 | (charcode >> 6),
+ 0x80 | (charcode & 0x3f));
+ }
+ else if (charcode < 0xd800 || charcode >= 0xe000) {
+ utf8.push(0xe0 | (charcode >> 12),
+ 0x80 | ((charcode>>6) & 0x3f),
+ 0x80 | (charcode & 0x3f));
+ }
+ // surrogate pair
+ else {
+ i++;
+ charcode = ((charcode&0x3ff)<<10)|(str.charCodeAt(i)&0x3ff)
+ utf8.push(0xf0 | (charcode >>18),
+ 0x80 | ((charcode>>12) & 0x3f),
+ 0x80 | ((charcode>>6) & 0x3f),
+ 0x80 | (charcode & 0x3f));
+ }
+ }
+ return utf8;
+ }
+} \ No newline at end of file