-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
141 lines (121 loc) · 3.01 KB
/
lib.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
/**
* Created by londreblocker on 10/16/16.
*/
/**
* Created by londreblocker on 10/7/16.
*/
/**
* Sends notification the the screen
*
* @param id: string
* @param title: string
* @param message: string
*/
function notify(id, title, message) {
var options = {
type: TemplateType.Basic,
title: title,
message: message,
priority: 2,
iconUrl: "icon.png",
buttons: [
{title: "Send"},
{title: "Cancel"}
]
};
chrome.notifications.create(id, options, function (notificationId) { });
}
/**
* Updates a notifications by its notificationId and changes its values
* based upon the options param passed into the function.
*
* @param notificationId: string
*/
function updateNotification(notificationId) {
chrome.notifications.update(notificationId, options, function (wasUpdated) {
});
}
/**
* Dismisses a active notification by its notificationId
*
* @param notificationId: string
*/
function clearNotification(notificationId) {
chrome.notifications.clear(notificationId, function (wasCleared) {
});
}
/**
* Sets the text of the badge that hows about the extension icon. To remove
* the badge set the text to an empty sting.
*
* @param text: string
*/
function setBadge(text) {
chrome.browserAction.setBadgeBackgroundColor({color: "#f00", tabId: secureTabId});
chrome.browserAction.setBadgeText({text: text.toString(), tabId: secureTabId});
}
/**
* Sends an email by opening a new tab and setting its url to a mailto location.
* All parts of the object param have default values. Its recommended to always
* set the value for body.
*
* @param mail: object {to: string, from:string, subject: string, body: string}
*/
function email(mail) {
mail.to = (mail.to != null) ? mail.to : "[email protected]";
mail.from = (mail.from != null) ? mail.from : "[email protected]";
mail.subject = (mail.subject != null) ? mail.subject : "Email Logs";
mail.body = (mail.body != null) ? mail.body : "";
var url = "mailto:" + mail.to + "?subject=" + mail.subject + "&body=" + encodeURIComponent(mail.body);
if (debug) console.log(url);
console.clear();
log.dump();
chrome.tabs.create({active: false, url: url}, function (tab) {
setTimeout(function () {
destroy([tab.id]);
}, 500)
})
}
/**
* Closes a tab or tabs.
*
* @param tabIds: [int]
*/
function destroy(tabIds) {
chrome.tabs.remove(tabIds, function () {
});
}
/**
* Reloads tab by tabId
*
* @param tabId: int
*/
function reload(tabId) {
chrome.tabs.reload(tabId, function () {
});
}
/**
* Selects a window by its windowId and brings it to the front.
*
* @param windowId: int
*/
function selectWindow(windowId) {
var updateInfo = {
focused: true,
drawAttention: true,
state: WindowState.Normal
};
chrome.windows.update(windowId, updateInfo, function (window) {
if (debug) console.log(window);
})
}
/**
* Produces a random true false value that can be used to
* insert random errors in a testing enviornment
*
* @returns {boolean}
*/
function isError() {
if (debug) return Math.random() < 0.3;
return false;
}