2018-04-11 04:05:23 +02:00
|
|
|
require('./bar.scss');
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2018-04-14 04:54:28 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2018-01-13 16:46:39 +01:00
|
|
|
var i18n = {};
|
2020-01-22 14:10:35 +01:00
|
|
|
var lang = window.navigator.language;
|
2018-01-13 16:46:39 +01:00
|
|
|
if (typeof safari !== 'undefined') {
|
2018-01-13 21:09:05 +01:00
|
|
|
const responseCommand = 'notificationBarFrameDataResponse';
|
|
|
|
sendPlatformMessage({
|
|
|
|
command: 'bgGetDataForTab',
|
|
|
|
responseCommand: responseCommand
|
|
|
|
});
|
2018-04-14 04:54:28 +02:00
|
|
|
safari.self.addEventListener('message', (msgEvent) => {
|
2019-08-20 19:06:38 +02:00
|
|
|
const msg = JSON.parse(msgEvent.message.msg);
|
2018-01-13 21:09:05 +01:00
|
|
|
if (msg.command === responseCommand && msg.data) {
|
|
|
|
i18n = msg.data.i18n;
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
}, false);
|
2018-04-14 04:54:28 +02:00
|
|
|
} else {
|
2018-01-13 16:46:39 +01:00
|
|
|
i18n.appName = chrome.i18n.getMessage('appName');
|
|
|
|
i18n.close = chrome.i18n.getMessage('close');
|
|
|
|
i18n.yes = chrome.i18n.getMessage('yes');
|
|
|
|
i18n.never = chrome.i18n.getMessage('never');
|
|
|
|
i18n.notificationAddSave = chrome.i18n.getMessage('notificationAddSave');
|
|
|
|
i18n.notificationNeverSave = chrome.i18n.getMessage('notificationNeverSave');
|
|
|
|
i18n.notificationAddDesc = chrome.i18n.getMessage('notificationAddDesc');
|
2018-08-01 05:24:11 +02:00
|
|
|
i18n.notificationChangeSave = chrome.i18n.getMessage('notificationChangeSave');
|
|
|
|
i18n.notificationChangeDesc = chrome.i18n.getMessage('notificationChangeDesc');
|
2020-01-22 14:10:35 +01:00
|
|
|
lang = chrome.i18n.getUILanguage();
|
2018-01-13 16:46:39 +01:00
|
|
|
|
|
|
|
// delay 50ms so that we get proper body dimensions
|
|
|
|
setTimeout(load, 50);
|
|
|
|
}
|
2016-12-31 02:55:59 +01:00
|
|
|
|
2017-11-10 04:38:09 +01:00
|
|
|
function load() {
|
2017-11-20 19:21:14 +01:00
|
|
|
var closeButton = document.getElementById('close-button'),
|
2017-11-10 04:38:09 +01:00
|
|
|
body = document.querySelector('body'),
|
|
|
|
bodyRect = body.getBoundingClientRect();
|
2017-09-19 18:30:19 +02:00
|
|
|
|
2017-11-10 04:38:09 +01:00
|
|
|
// i18n
|
2020-01-22 14:10:35 +01:00
|
|
|
body.classList.add('lang-' + lang.slice(0, 2));
|
2017-09-07 16:12:34 +02:00
|
|
|
|
2018-01-13 16:46:39 +01:00
|
|
|
document.getElementById('logo-link').title = i18n.appName;
|
|
|
|
closeButton.title = i18n.close;
|
2019-10-09 16:12:06 +02:00
|
|
|
closeButton.setAttribute('aria-label', i18n.close);
|
2017-09-07 16:12:34 +02:00
|
|
|
|
2017-11-10 04:38:09 +01:00
|
|
|
if (bodyRect.width < 768) {
|
2018-01-13 16:46:39 +01:00
|
|
|
document.querySelector('#template-add .add-save').textContent = i18n.yes;
|
|
|
|
document.querySelector('#template-add .never-save').textContent = i18n.never;
|
2018-08-01 05:24:11 +02:00
|
|
|
document.querySelector('#template-change .change-save').textContent = i18n.yes;
|
2018-04-14 04:54:28 +02:00
|
|
|
} else {
|
2018-01-13 16:46:39 +01:00
|
|
|
document.querySelector('#template-add .add-save').textContent = i18n.notificationAddSave;
|
|
|
|
document.querySelector('#template-add .never-save').textContent = i18n.notificationNeverSave;
|
2018-08-01 05:24:11 +02:00
|
|
|
document.querySelector('#template-change .change-save').textContent = i18n.notificationChangeSave;
|
2017-11-10 04:38:09 +01:00
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
|
2018-01-13 16:46:39 +01:00
|
|
|
document.querySelector('#template-add .add-text').textContent = i18n.notificationAddDesc;
|
2018-08-01 05:24:11 +02:00
|
|
|
document.querySelector('#template-change .change-text').textContent = i18n.notificationChangeDesc;
|
2016-12-30 08:09:54 +01:00
|
|
|
|
2017-11-10 04:38:09 +01:00
|
|
|
if (getQueryVariable('add')) {
|
|
|
|
setContent(document.getElementById('template-add'));
|
2016-12-30 20:25:57 +01:00
|
|
|
|
2017-11-10 04:38:09 +01:00
|
|
|
var addButton = document.querySelector('#template-add-clone .add-save'),
|
|
|
|
neverButton = document.querySelector('#template-add-clone .never-save');
|
|
|
|
|
2018-04-14 04:54:28 +02:00
|
|
|
addButton.addEventListener('click', (e) => {
|
2017-11-10 04:38:09 +01:00
|
|
|
e.preventDefault();
|
2018-01-13 16:46:39 +01:00
|
|
|
sendPlatformMessage({
|
2017-11-10 04:38:09 +01:00
|
|
|
command: 'bgAddSave'
|
|
|
|
});
|
2017-06-13 19:59:16 +02:00
|
|
|
});
|
|
|
|
|
2018-04-14 04:54:28 +02:00
|
|
|
neverButton.addEventListener('click', (e) => {
|
2017-11-10 04:38:09 +01:00
|
|
|
e.preventDefault();
|
2018-01-13 16:46:39 +01:00
|
|
|
sendPlatformMessage({
|
2017-11-10 04:38:09 +01:00
|
|
|
command: 'bgNeverSave'
|
|
|
|
});
|
|
|
|
});
|
2018-08-01 05:24:11 +02:00
|
|
|
} else if (getQueryVariable('change')) {
|
|
|
|
setContent(document.getElementById('template-change'));
|
|
|
|
var changeButton = document.querySelector('#template-change-clone .change-save');
|
|
|
|
changeButton.addEventListener('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
sendPlatformMessage({
|
|
|
|
command: 'bgChangeSave'
|
|
|
|
});
|
|
|
|
});
|
2018-04-14 04:54:28 +02:00
|
|
|
} else if (getQueryVariable('info')) {
|
2017-11-10 04:38:09 +01:00
|
|
|
setContent(document.getElementById('template-alert'));
|
|
|
|
document.getElementById('template-alert-clone').textContent = getQueryVariable('info');
|
|
|
|
}
|
|
|
|
|
2018-04-14 04:54:28 +02:00
|
|
|
closeButton.addEventListener('click', (e) => {
|
2017-06-13 19:59:16 +02:00
|
|
|
e.preventDefault();
|
2018-01-13 16:46:39 +01:00
|
|
|
sendPlatformMessage({
|
2017-11-10 04:38:09 +01:00
|
|
|
command: 'bgCloseNotificationBar'
|
2016-12-30 20:25:57 +01:00
|
|
|
});
|
|
|
|
});
|
2016-12-30 08:09:54 +01:00
|
|
|
|
2018-01-13 16:46:39 +01:00
|
|
|
sendPlatformMessage({
|
2017-11-10 04:38:09 +01:00
|
|
|
command: 'bgAdjustNotificationBar',
|
|
|
|
data: {
|
|
|
|
height: body.scrollHeight
|
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
});
|
2017-11-10 04:38:09 +01:00
|
|
|
}
|
2017-09-07 16:12:34 +02:00
|
|
|
|
2016-12-30 08:09:54 +01:00
|
|
|
function getQueryVariable(variable) {
|
|
|
|
var query = window.location.search.substring(1);
|
|
|
|
var vars = query.split('&');
|
|
|
|
|
|
|
|
for (var i = 0; i < vars.length; i++) {
|
|
|
|
var pair = vars[i].split('=');
|
2016-12-30 20:25:57 +01:00
|
|
|
if (pair[0] === variable) {
|
2016-12-30 08:09:54 +01:00
|
|
|
return pair[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setContent(element) {
|
2017-11-20 19:21:14 +01:00
|
|
|
const content = document.getElementById('content');
|
2016-12-30 08:09:54 +01:00
|
|
|
while (content.firstChild) {
|
|
|
|
content.removeChild(content.firstChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
var newElement = element.cloneNode(true);
|
|
|
|
newElement.id = newElement.id + '-clone';
|
|
|
|
content.appendChild(newElement);
|
|
|
|
}
|
2018-01-13 16:46:39 +01:00
|
|
|
|
|
|
|
function sendPlatformMessage(msg) {
|
|
|
|
if (typeof safari !== 'undefined') {
|
2019-08-27 14:03:55 +02:00
|
|
|
safari.extension.dispatchMessage('bitwarden', msg);
|
2018-04-14 04:54:28 +02:00
|
|
|
} else {
|
2018-01-13 16:46:39 +01:00
|
|
|
chrome.runtime.sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
});
|