-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
142 lines (118 loc) · 3.35 KB
/
app.js
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
var Quill = require('quill')
const customTitlebar = require('custom-electron-titlebar');
var titleBar = new customTitlebar.Titlebar({
backgroundColor: customTitlebar.Color.fromHex('#1d2233'),
});
var editor = new Quill('#editor', {
modules: {
toolbar: [
[{ header: [1, 2, 3, 4, false] }],
['bold'],
['italic'],
['underline'],
['strike'],
['image'],
['code-block']
]
},
placeholder: 'Start writing here...',
theme: 'snow' // or 'bubble'
});
// Save and Load files
var fs = require('fs');
var remote = require('electron').remote;
var dialog = remote.require('electron').dialog;
var loadedfs;
function saveFile() {
if (!loadedfs) {
dialog.showSaveDialog({
filters: [
{ name: 'txt', extensions: ['txt'] },
{ name: 'html', extensions: ['html'] },
]
}, function (filename) {
if (filename === undefined) return;
writeToFile(editor, filename);
});
}
else {
writeToFile(editor, loadedfs);
}
}
function loadFile() {
dialog.showOpenDialog({
filters: [
{ name: 'txt', extensions: ['txt', 'html'] },
{ name: 'html', extensions: ['html', 'txt'] },
]
}, function (filenames) {
if (filenames === undefined) return;
var filename = filenames[0];
readFromFile(editor, filename);
loadedfs = filename;
})
}
function writeToFile(editor, filename) {
var html = editor.getText();
fs.writeFile(filename, html, function (err) {
if (err) {
return console.log(err);
}
});
}
function readFromFile(editor, filename) {
fs.readFile(filename, "utf-8", function (err, data) {
if (err) {
console.log(err);
}
editor.getContents(data);
});
}
var Delta = Quill.import('delta');
var startTime = Date.now();
var interval = Math.floor((Date.now() - startTime) / 1000);;
var socket = require("./socket");
var s = new socket();
var change = new Delta();
editor.on('text-change', function (delta, oldDelta, source) {
if (source == 'user') {
start = Date.now();
var pos = editor.getLength();
var content = editor.getContents();
content = String(content["ops"][0]["insert"]);
// console.log(content[content.length-2]);
if (content[content.length - 2] === ".") {
var text = [... new Set(content.split("."))];
var index = text.length - 1;
// console.log(text[index - 1]);
s.send(text[index - 1])
}
// $.post('/socket-endpoint', {
// partial: JSON.stringify(change)
//});
//console.log(Date.now());
}
});
$(".specefic-search").click(function () {
var range = editor.getSelection();
if (range) {
if(range.length != 0) {
var text = editor.getText(range.index, range.length);
s.send(text);
}
} else {
console.log('User cursor is not in editor');
}
});
$(".stop-search").click(function(){
if(s.contSend){
$(".stop-search img").css("opacity",".5")
}
else{
$(".stop-search img").css("opacity","1")
}
s.contSend = !s.contSend;
});
$(document).on('click', '.save-button', function () {
saveFile()
});