-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.ts
70 lines (61 loc) · 1.64 KB
/
popup.ts
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
import { Minimal } from './minimal/minimalClass';
import { openMinimal } from './floatbutton/extension';
import { initShark } from './utils/shark';
initShark();
declare let componentHandler: any;
document.getElementsByTagName('head')[0].onclick = function (e) {
try {
componentHandler.upgradeDom();
} catch (e2) {
console.log(e2);
setTimeout(function () {
componentHandler.upgradeDom();
}, 500);
}
};
api.settings.init().then(() => {
const minimalObj = new Minimal($('html'));
checkFill(minimalObj);
$(window).focus(() => {
checkFill(minimalObj);
});
try {
const mode = $('html').attr('mode');
con.log('Mode', mode);
if (mode === 'popup' && api.settings.get('minimalWindow')) {
openMinimal(function (response) {
$('html').css('height', '0');
if (!isFirefox()) {
window.close();
}
});
}
} catch (e) {
con.error(e);
}
});
function isFirefox() {
if ($('#Mal-Sync-Popup').css('min-height') === '600px') return true;
return false;
}
function checkFill(minimalObj) {
con.log('CheckFill');
if (!chrome.tabs) {
con.error('Can not check for tabs');
return;
}
chrome.tabs.query({ active: true }, function (tabs) {
con.m('tabs').log(tabs);
tabs.forEach(el => {
chrome.tabs.sendMessage(el.id!, { action: 'TabMalUrl' }, function (response) {
setTimeout(() => {
if (typeof response !== 'undefined' && response.length) {
minimalObj.fillBase(response);
} else if ($('html').attr('mode') === 'popup') {
minimalObj.fillBase(null);
}
}, 500);
});
});
});
}