Files

68 lines
2.5 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function () {
chrome.storage.local.get(
[
'appsScriptUrl',
'appsScriptKey',
'loginEmail',
'ntfyServer',
'ntfyTopic',
'ntfyToken',
],
function (result) {
if (result.appsScriptUrl)
document.getElementById('appsScriptUrl').value = result.appsScriptUrl;
if (result.appsScriptKey)
document.getElementById('appsScriptKey').value = result.appsScriptKey;
if (result.loginEmail)
document.getElementById('loginEmail').value = result.loginEmail;
document.getElementById('ntfyServer').value =
result.ntfyServer || 'https://notify.tstitagency.com';
document.getElementById('ntfyTopic').value =
result.ntfyTopic || 'andela-jobs';
if (result.ntfyToken)
document.getElementById('ntfyToken').value = result.ntfyToken;
},
);
document.getElementById('saveBtn').addEventListener('click', function () {
var appsScriptUrl = document.getElementById('appsScriptUrl').value.trim();
var appsScriptKey = document.getElementById('appsScriptKey').value.trim();
var loginEmail = document.getElementById('loginEmail').value.trim();
var ntfyServer = document.getElementById('ntfyServer').value.trim();
var ntfyTopic = document.getElementById('ntfyTopic').value.trim();
var ntfyToken = document.getElementById('ntfyToken').value.trim();
if (!appsScriptUrl)
return showStatus('Please enter Apps Script URL', 'error');
if (!appsScriptUrl.startsWith('https://script.google.com/'))
return showStatus('Invalid Apps Script URL', 'error');
if (!appsScriptKey) return showStatus('Please enter Secret Key', 'error');
if (!loginEmail || !loginEmail.includes('@'))
return showStatus('Please enter a valid email', 'error');
chrome.storage.local.set(
{
appsScriptUrl: appsScriptUrl,
appsScriptKey: appsScriptKey,
loginEmail: loginEmail,
ntfyServer: ntfyServer || 'https://notify.tstitagency.com',
ntfyTopic: ntfyTopic || 'andela-jobs',
ntfyToken: ntfyToken,
},
function () {
showStatus('Settings saved successfully!', 'success');
},
);
});
});
function showStatus(message, type) {
var statusEl = document.getElementById('status');
statusEl.textContent = message;
statusEl.className = 'status ' + type;
statusEl.style.display = 'block';
setTimeout(function () {
statusEl.style.display = 'none';
}, 3000);
}