Skip to content

Commit

Permalink
plaintext converter
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Mar 18, 2017
1 parent aa481d8 commit d006ae6
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 16 deletions.
38 changes: 38 additions & 0 deletions dist/sntools.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,44 @@ var SNTools = function () {

return itemsData;
}
}, {
key: 'convertPlaintextFiles',
value: function convertPlaintextFiles(files, completion) {
var index = 0;
var processedData = [];

var readNext = function () {
var file = files[index];
index++;
var reader = new FileReader();

reader.onload = function (e) {

var data = e.target.result;
var note = {
created_at: new Date(),
updated_at: new Date(),
uuid: this.generateUUID(),
content_type: "Note",
content: {
title: file.name.split(".")[0],
text: data,
references: []
}
};
processedData.push(note);

if (index < files.length) {
readNext();
} else {
completion({ items: processedData });
}
}.bind(this);
reader.readAsText(file);
}.bind(this);

readNext();
}
}]);

return SNTools;
Expand Down
4 changes: 2 additions & 2 deletions dist/sntools.min.js

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions dist/transpiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,44 @@ var SNTools = function () {

return itemsData;
}
}, {
key: 'convertPlaintextFiles',
value: function convertPlaintextFiles(files, completion) {
var index = 0;
var processedData = [];

var readNext = function () {
var file = files[index];
index++;
var reader = new FileReader();

reader.onload = function (e) {

var data = e.target.result;
var note = {
created_at: new Date(),
updated_at: new Date(),
uuid: this.generateUUID(),
content_type: "Note",
content: {
title: file.name.split(".")[0],
text: data,
references: []
}
};
processedData.push(note);

if (index < files.length) {
readNext();
} else {
completion({ items: processedData });
}
}.bind(this);
reader.readAsText(file);
}.bind(this);

readNext();
}
}]);

return SNTools;
Expand Down
2 changes: 1 addition & 1 deletion dist/transpiled.js.map

Large diffs are not rendered by default.

37 changes: 25 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
<html style="background-color: black;">
<html style="background-color: black; color: white;">
<head>
<script src="dist/sntools.js"></script>
</head>

<input type="file" id="files" name="files[]" multiple />
Evernote:
<input type="file" id="evernote" name="files[]" multiple />

Plaintext:
<input type="file" id="plaintext" name="files[]" multiple />

<script>

function handleFileSelect(evt) {
var file = evt.target.files[0];
var reader = new FileReader();
function handleEvernoteSelect(evt) {
var file = evt.target.files[0];
var reader = new FileReader();

reader.onload = function(e) {
var data = e.target.result;
var result = SNTools.convertENEXDatatoSN(data);
SNTools.downloadSNData(result, "result.txt");
}.bind(this)

reader.onload = function(e) {
var data = e.target.result;
var result = SNTools.convertENEXDatatoSN(data);
SNTools.downloadSNData(result, "result.txt");
}.bind(this)
reader.readAsText(file);
}

reader.readAsText(file);
function handlePlaintextSelect(evt) {
var files = evt.target.files;
SNTools.convertPlaintextFiles(files, function(data){
SNTools.downloadSNData(data, "sn-import-file.txt");
})
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);

document.getElementById('evernote').addEventListener('change', handleEvernoteSelect, false);
document.getElementById('plaintext').addEventListener('change', handlePlaintextSelect, false);

</script>
</html>
37 changes: 37 additions & 0 deletions lib/sntools.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,43 @@ class SNTools {

return itemsData;
}

convertPlaintextFiles(files, completion) {
var index = 0;
var processedData = [];

var readNext = function() {
var file = files[index];
index++;
var reader = new FileReader();

reader.onload = function(e) {

var data = e.target.result;
var note = {
created_at: new Date(),
updated_at: new Date(),
uuid: this.generateUUID(),
content_type: "Note",
content: {
title: file.name.split(".")[0],
text: data,
references: [],
}
};
processedData.push(note);

if(index < files.length) {
readNext();
} else {
completion({items: processedData});
}
}.bind(this)
reader.readAsText(file);
}.bind(this);

readNext();
}
}

window.SNTools = new SNTools()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sntools",
"version": "0.0.3",
"version": "0.0.4",
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-preset-env": "^1.1.1",
Expand Down

0 comments on commit d006ae6

Please sign in to comment.