-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmassViewDeleteScript.js
62 lines (54 loc) · 2.05 KB
/
massViewDeleteScript.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
"use strict"
// Logic to add new inspiration that the user submits
document.addEventListener('DOMContentLoaded', function () {
const StorageArea = chrome.storage.sync;
StorageArea.get("maxKey", (obj) => {
const maxKeyInt = parseInt(obj["maxKey"]);
listContent(maxKeyInt);
});
// For overriding submitting the form
$("#deleteContent").submit(deletedSelectedContent);
});
function listContent() {
const StorageArea = chrome.storage.sync;
StorageArea.get("contentArray", (obj) => {
const contentArray = obj["contentArray"];
for (let i = 0; i < contentArray.length; i++) {
const insp = contentArray[i];
let html = "<input type='checkbox' name='box' id='delete" + i + "' value=" + i + " />";
html += "<label for= 'delete" + i + "'></label>";
if (insp.type === "image") {
html += "<img src=" + insp.content + " />";
} else {
html += "<span class='textInsp'>" + insp.content + "</span>";
}
html = "<div class='inspiration'>" + html + "</div>"
$("#inspirationContent").append(html);
}
});
}
function deletedSelectedContent(event) {
// stop form from submitting normally
event.preventDefault();
let checkedIndexes = [];
$("input:checkbox[name=box]:checked").each(function(){
checkedIndexes.push($(this).val());
});
deleteInsp(checkedIndexes);
}
// WARNING: this doesn't check if it's the right content. If the user deletes
// stuff from two different pages, it'll get messed up. I don't think that's
// super likely, so I guess I'm okay with it now.
function deleteInsp(indexList) {
const StorageArea = chrome.storage.sync;
StorageArea.get("contentArray", (obj) => {
const contentArray = obj["contentArray"];
indexList.sort();
indexList.reverse();
indexList.forEach(index => {
contentArray.splice(index, 1);
});
StorageArea.set({"contentArray": contentArray});
location.reload();
});
}