-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
81 lines (77 loc) · 2.7 KB
/
popup.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
var port = chrome.runtime.connect()
var listBg = []
var temp = {}
chrome.storage.local.get('bgChat_HuynhNhon', function (obj) {
chrome.storage.local.get('tempBgChat', function (obj1) {
temp = obj1.tempBgChat
console.log(temp);
$('#uid').val(temp.uid)
$('#bgUrl').val(temp.bgUrl)
listBg = (obj.bgChat_HuynhNhon);
console.log(obj.bgChat_HuynhNhon);
if (listBg.length > 0) {
getList(listBg)
}
$('.btn-add').click(function () {
var uid = $('#uid').val();
var bgUrl = $('#bgUrl').val()
if (uid !== "" && bgUrl !== "") {
let ind = listBg.findIndex(x => x.uid == uid)
if (ind == -1) {
listBg.unshift({
uid: uid,
bgUrl: bgUrl
})
$('#uid').val("")
$('#bgUrl').val("")
chrome.storage.local.set({
bgChat_HuynhNhon: listBg
}, function () {
getList(listBg)
chrome.storage.local.set({
tempBgChat: {
uid: "",
bgUrl: ""
}
})
});
} else {
alert("Bạn đã thêm hình nền cho người dùng này rồi");
$('#uid').val("")
$('#bgUrl').val("")
}
}
})
$("input#uid").on("change paste keyup", function () {
temp.uid = $(this).val()
chrome.storage.local.set({
tempBgChat: temp
})
});
$("input#bgUrl").on("change paste keyup", function () {
temp.bgUrl = $(this).val()
chrome.storage.local.set({
tempBgChat: temp
})
});
$('span.delete').click(function () {
var uidDel = $(this).attr("id");
console.log(uidDel);
let ind = listBg.findIndex(x => x.uid == uidDel)
if (ind !== -1) {
listBg.splice(ind, 1)
chrome.storage.local.set({
bgChat_HuynhNhon: listBg
}, function () {
getList(listBg)
});
}
})
function getList(list) {
$('ul#list').html("");
list.forEach(function (val) {
$('ul#list').append("<li><b>" + val.uid + ":</b> <span>" + val.bgUrl + "</span> <span class='delete' id='" + val.uid + "'>x</span> </li>");
})
}
})
});