-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
136 lines (104 loc) · 3.71 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
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
// Wait until windows is loaded
document.addEventListener('DOMContentLoaded', function () {
let checkPageButton = document.getElementById('toggle-issues');
const validUrls = [
'https://issues.joomla.org/tracker/joomla-cms/',
'https://github.com/joomla/joomla-cms/pull/',
'https://github.com/joomla/joomla-cms/issues/'
];
chrome.tabs.query({
currentWindow: true,
active: true
}, function (tabs) {
let tablink = tabs[0].url;
let checkUrl = false;
validUrls.forEach((item, index)=>{
if (tablink.indexOf(item) !== -1) {
checkUrl = true
}
})
if (checkUrl == false) {
checkPageButton.classList.add('d-none');
document.getElementById('message').innerHTML = '<div class="alert alert-warning p-1 text-center" role="alert">No issue ID fount in URL</div>';
}
return;
})
checkPageButton.addEventListener('click', function () {
chrome.tabs.query({
currentWindow: true,
active: true
}, function (tabs) {
let tablink = tabs[0].url;
if (tablink.indexOf('https://issues.joomla.org/tracker/joomla-cms/') !== -1) {
let issueID = tablink.match('[0-9]+');
chrome.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
let tab = tabs[0];
chrome.tabs.update(tab.id, {
url: 'https://github.com/joomla/joomla-cms/pull/' + issueID
});
})
} else if (tablink.indexOf('https://github.com/joomla/joomla-cms/pull/') !== -1) {
let issueID = tablink.match('[0-9]+');
chrome.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
let tab = tabs[0];
chrome.tabs.update(tab.id, {
url: 'https://issues.joomla.org/tracker/joomla-cms/' + issueID
});
})
} else if (tablink.indexOf('https://github.com/joomla/joomla-cms/issues/') !== -1) {
let issueID = tablink.match('[0-9]+');
chrome.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
let tab = tabs[0];
chrome.tabs.update(tab.id, {
url: 'https://issues.joomla.org/tracker/joomla-cms/' + issueID
});
})
} else {
alert('No issue ID found! Please visit the Joomla issue tracker!');
}
});
window.close();
});
let imgWidth = document.getElementById('imgWidth');
let imgHeight = document.getElementById('imgHeight');
let searchTermValue = document.getElementById('searchTerm');
let presetSize = document.getElementById('presetSize');
let searchTerm = 'nature,woods';
function constructUrl() {
imgWidth.select();
imgWidth.setSelectionRange(0, 99999); /* For mobile devices */
imgHeight.select();
imgHeight.setSelectionRange(0, 99999); /* For mobile devices */
if (searchTermValue.value) {
searchTerm = searchTermValue.value;
searchTermValue.value = 'nature,woods';
}
return 'https://source.unsplash.com/' + imgWidth.value + 'x' + imgHeight.value + '?' + searchTerm;
}
presetSize.onchange = function(){
let whValues = this.value.split('x');
imgWidth.value = whValues[0];
imgHeight.value = whValues[1];
}
// On click #oggleOffcanvas do something
document.getElementById('selectUrlLink').onclick = function () {
/* Copy the text inside the text field */
navigator.clipboard.writeText(constructUrl());
document.getElementById("imgWidth").focus();
}
// On click #oggleOffcanvas do something
document.getElementById('gotoUrlLink').onclick = function () {
/* Goto URL */
window.open(constructUrl(), '_blank', 'toolbar=0,location=0,menubar=0');
window.close();
}
}, false);