-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
74 lines (57 loc) · 2.18 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
let span_searchWithin = document.getElementById('search-within');
let form_search = document.getElementById('search');
let form_newTab = document.getElementById('newTab');
let button_settings = document.getElementById('settings');
let input_query = document.getElementById('query');
let openUrl;
chrome.storage.sync.get({ company: '', projectName: '', url: 'azure', customUrl: '' }, function (
{ company, projectName, url, customUrl }) {
openUrl = url == 'azure'
? `https://dev.azure.com/${company}/${projectName}`
: url == 'vsts'
? `https://${company}.visualstudio.com/${projectName}`
: customUrl;
});
// setup triggers
button_settings.onclick = function () { chrome.runtime.openOptionsPage(); }
form_search.onsubmit = function () {
let search = input_query.value;
if (parseInt(search)) { // assume workitem
openUrl += `/_workitems/edit/${search}`;
}
else {
openUrl += `/_search?text=${search}&type=workitem`
}
console.log('url:' + openUrl);
let tabProperties = {
url: openUrl,
};
if (form_newTab.checked) {
chrome.tabs.create(tabProperties); // auto-focuses as of Chrome 33
}
else {
chrome.tabs.getCurrent(tab => chrome.tabs.update(tabProperties));
}
}
// load the page data
chrome.storage.sync.get({ company: '', projectName: '', newTab: true, url: 'azure', customUrl: '' }, function (
{ company, projectName, newTab, url, customUrl }
) {
console.debug("items: " + JSON.stringify({ company, projectName, newTab, url, customUrl }));
form_newTab.checked = newTab;
if (url && url == 'custom') {
if (customUrl.length == 0) {
span_searchWithin.textContent = "[CUSTOM URL NOT SET]";
return;
}
span_searchWithin.textContent = customUrl;
return;
}
// make sure they're both present
if (!(company && company.length > 0)
|| !(projectName && projectName.length > 0)) {
span_searchWithin.textContent = "[OPTIONS NOT SET]";
return;
}
span_searchWithin.textContent = company + ", " + projectName;
})