..
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 | const remote = require('electron').remote
const Menu = remote.Menu;
const MenuItem = remote.MenuItem;
const { ipcRenderer } = require('electron');
const chapterList = ['Chapterfl1'];
const currentActiveChapter = 0;
let chapterNameCount = 1;
$(document).ready(function () {
updateChapters();
setActiveChapter(currentActiveChapter);
});
function updateChapters() {
if (!chapterList.length) {
addChapter();
}
$('#chapters').empty();
chapterList.forEach(chapter => {
const chapterName = chapter.replace(/fl/g, ' ');
$('#chapters').append(`<span id="${chapter}" class="item chapter_navigation">${chapterName}</span>`)
});
setActiveChapter(currentActiveChapter);
}
function setActiveChapter(currentActiveChapter) {
const chapter = chapterList[currentActiveChapter];
$(`#${chapter}`).addClass('active');
}
function addChapter() {
const chapterCount = chapterList.length;
chapterList[chapterCount] = `Chapterfl${chapterNameCount+1}`;
chapterNameCount++;
updateChapters();
}
$('#addChapter').click(() => {
addChapter();
})
let currentSelectedChapterForContextAction = null;
let rightClickPosition = null;
const chapterMenu = new Menu()
const renameChapterMenuItem = new MenuItem({
label: 'Rename Chapter',
click: (e) => {
const currentChapter = currentSelectedChapterForContextAction.replace(/fl/g, ' ');
let child = new remote.BrowserWindow({
parent: remote.getCurrentWindow(),
modal: true,
width: 360,
height: 135,
frame: false,
show: false,
titleBarStyle: 'hidden',
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}
})
child.loadURL('file://' + __dirname + '/../../system/chapterRename.html')
child.once('show', function () {
child.webContents.send('currentChapterName', currentChapter);
});
child.once('ready-to-show', () => {
child.show()
});
ipcRenderer.on('renamedChapter', (event, message) => {
const newChapterName = message;
const index = chapterList.findIndex(chapter => chapter === currentSelectedChapterForContextAction);
const newChapterId = newChapterName.replace(/ /g, 'fl');
chapterList[index] = newChapterId;
currentSelectedChapterForContextAction = null;
updateChapters();
});
}
});
const deleteChapterMenuItem = new MenuItem({
label: 'Delete Chapter',
click: (e) => {
const index = chapterList.findIndex(chapter => chapter === currentSelectedChapterForContextAction);
chapterList.splice(index, 1);
updateChapters();
}
});
chapterMenu.append(renameChapterMenuItem);
chapterMenu.append(deleteChapterMenuItem);
$(document).on('contextmenu', '.chapter_navigation', (e) => {
e.preventDefault();
currentSelectedChapterForContextAction = e.target.id;
rightClickPosition = { x: e.x, y: e.y };
chapterMenu.popup(remote.getCurrentWindow());
});
|
|