-
Notifications
You must be signed in to change notification settings - Fork 0
/
save-complete.js
59 lines (53 loc) · 1.98 KB
/
save-complete.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
// adds item to metadata lists
var url = window.location.pathname;
const itemSlug = url.substring(url.lastIndexOf('/')+1);
console.log(itemSlug);
MemberStack.onReady.then(async function (member) {
if (member.loggedIn) {
const metadata = await member.getMetaData();
metadata.savedList = metadata.savedList || [];
const savedNum = metadata.savedList.length || 0;
$('.cc-saved-counter').text(savedNum);
metadata.completedList = metadata.completedList || [];
const completeNum = metadata.completedList.length || 0;
$('.cc-completed-counter').text(completeNum);
// show/hide saved buttons
if (metadata.savedList.indexOf(itemSlug) === -1) {
$('.cc-save-item.cc-checked').hide();
}
else {
console.log("in watchlist");
$('.cc-save-item.cc-unchecked').hide();
}
// show/hide watchlist buttons
if (metadata.completedList.indexOf(itemSlug) === -1) {
$('.cc-mark-as-complete.cc-checked').hide();
}
else {
console.log("completed");
$('.cc-mark-as-complete.cc-unchecked').hide();
}
$('.cc-save-item').click(function () {
if (metadata.savedList.indexOf(itemSlug) === -1) {
metadata.savedList.push(itemSlug);
const savedNum = metadata.savedList.length || 0;
metadata.savedItemsNum = savedNum;
member.updateMetaData(metadata);
$('.cc-saved-counter').text(savedNum);
$('.cc-save-item.cc-checked').show();
$('.cc-save-item.cc-unchecked').hide();
}
});
$('.cc-mark-as-complete').click(function () {
if (metadata.completedList.indexOf(itemSlug) === -1) {
metadata.completedList.push(itemSlug);
const completeNum = metadata.completedList.length || 0;
metadata.completedItemsNum = completeNum;
member.updateMetaData(metadata);
$('.cc-completed-counter').text(completeNum);
$('.cc-mark-as-complete.cc-checked').show();
$('.cc-mark-as-complete.cc-unchecked').hide();
}
});
}
});