-
Notifications
You must be signed in to change notification settings - Fork 4
/
popup.js
68 lines (52 loc) · 1.85 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
$(function(){
chrome.storage.sync.get(['numProcessed'],function(store){
if (store.numProcessed == null) {
chrome.storage.sync.set({'numProcessed': 0}, function(){
console.log('numProcessed set to 0');
});
// set to 0 because not already set
$('#numProcessed').text(0);
} else {
$('#numProcessed').text(store.numProcessed);
}
});
$('#spendAmount').click(function(){
chrome.storage.sync.get(['total', 'limit'],function(budget){
var newTotal = 0;
if (budget.total){
newTotal += parseInt(budget.total);
}
var amount = $('#amount').val();
if (amount){
newTotal += parseInt(amount);
}
chrome.storage.sync.set({'total': newTotal}, function(){
if (amount && newTotal >= budget.limit){
var notifOptions = {
type: "basic",
iconUrl: "icon48.png",
title: "Limit reached!",
message: "Uh oh, look's like you've reached your alloted limit."
};
chrome.notifications.create('limitNotif', notifOptions);
}
});
$('#total').text(newTotal);
$('#amount').val('');
});
});
$("#link-field").on("click", function () {
$(this).select();
document.execCommand("copy");
});
});
function copyLink() {
/* Get the text field */
var copyText = document.getElementById("copy-btn");
/* Select the text field */
copyText.select();
/* Copy the text inside the text field */
document.execCommand("copy");
/* Alert the copied text */
alert("Copied the text: " + copyText.value);
}