This repository has been archived by the owner on Oct 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchList.js
157 lines (134 loc) · 5.01 KB
/
watchList.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Author : Thophile
* Project : Deskapp
*/
/** Watchlist **/
//Display the form
function displayWatchListForm() {
$("#form_row").load('./watchList_form.html');
}
//Display the button
function displayWatchListButton() {
$("#form_row").load('./watchList_button_new.html');
}
//Display the watchlist
function loadWatchList() {
if (details !== undefined) {
//Creating table
var tbody = document.getElementById('tbody')
tbody.innerHTML = ""
tbody.className = ''
for (let i = 0; i < details.watchList.length; i++) {
//Reminder
if (details.watchList[i].day != getDayName('en-GB')) {
details.watchList[i].remindMe = true
}
var row = document.createElement('tr')
var td = document.createElement('td')
td.innerHTML = details.watchList[i].name
td.className = 'truncate w-75 align-middle'
row.appendChild(td)
var td = document.createElement('td')
td.innerHTML = details.watchList[i].lastSeen
td.className = 'text-center align-middle'
row.appendChild(td)
var td = document.createElement('td')
td.className = 'btn-group'
//Action button
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.title = 'I\'ve seen one less !'
button.addEventListener('click', () => {
minusEpisode(i)
})
button.innerHTML = '<i class="fas fa-minus-square"></i>'
td.appendChild(button)
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.title = 'I\'ve seen one more !'
button.addEventListener('click', () => {
plusEpisode(i)
})
button.innerHTML = '<i class="fas fa-plus-square"></i>'
td.appendChild(button)
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.title = 'Follow link'
button.addEventListener('click', () => {
shell.openExternal(details.watchList[i].watchLink)
details.watchList[i].remindMe = false
})
button.innerHTML = '<i class="fas fa-external-link-alt"></i>'
td.appendChild(button)
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.title = 'Edit'
button.addEventListener('click', () => {
editElement(i)
})
button.innerHTML = '<i class="fas fa-edit"></i>'
td.appendChild(button)
var button = document.createElement('button')
button.className = 'btn btn-dark colored'
button.title = 'Remove'
button.addEventListener('click', () => {
removeElement(i)
})
button.innerHTML = '<i class="fas fa-trash"></i>'
td.appendChild(button)
row.appendChild(td)
if (details.watchList[i].remindMe == true && details.watchList[i].day == getDayName('en-GB')) {
row.className = 'remind'
} else {
row.className = ''
}
tbody.appendChild(row)
}
}
saveData()
}
//Remove and refresh the watchList
function removeElement(index) {
if(details.watchList.length === 1) details.watchList = [];
details.watchList.splice(index, 1)
loadWatchList()
}
//Add and refresh the watchList
function addElement() {
var element = {
name: document.getElementById('_name').value,
lastSeen: document.getElementById('_lastSeen').value,
watchLink: document.getElementById('_watchLink').value,
day: document.getElementById('_day').value,
remindMe: true,
}
details.watchList.splice(0, 0, element)
displayWatchListButton()
loadWatchList()
}
//Load in the form for editing
function editElement(index) {
$("#form_row").load('./watchList_form.html', function () {
var element = details.watchList[index]
document.getElementById('_name').setAttribute('value', element.name)
document.getElementById('_lastSeen').setAttribute('value', element.lastSeen)
document.getElementById('_watchLink').setAttribute('value', element.watchLink)
for (let i = 0; i < document.getElementById('_day').options.length; i++) {
if (document.getElementById('_day').options[i].value === element.day) {
document.getElementById('_day').options.selectedIndex = i
}
}
removeElement(index)
})
saveData()
}
function plusEpisode(index) {
details.watchList[index].lastSeen++
details.watchList[index].remindMe = false
loadWatchList()
}
function minusEpisode(index) {
details.watchList[index].lastSeen--
details.watchList[index].remindMe = false
loadWatchList()
}