86 lines
2.6 KiB
JavaScript
86 lines
2.6 KiB
JavaScript
var chk = document.getElementById('chk');
|
|
var row = document.getElementById('row');
|
|
var dbg = document.getElementById('dbg');
|
|
var ftxt = document.getElementById('ftxt');
|
|
var statusDot = document.getElementById('statusDot');
|
|
|
|
/* ── Liens ── */
|
|
document.getElementById('btnGithub').addEventListener('click', function() {
|
|
chrome.tabs.create({ url: 'https://git.nightcord.online/nightcord/nightcord' });
|
|
});
|
|
document.getElementById('btnDiscord').addEventListener('click', function() {
|
|
chrome.tabs.create({ url: 'https://discord.gg/nightcord' });
|
|
});
|
|
document.getElementById('btnWebsite').addEventListener('click', function() {
|
|
chrome.tabs.create({ url: 'https://nightcord.online' });
|
|
});
|
|
|
|
/* ── UI ── */
|
|
function setUI(val) {
|
|
chk.checked = val;
|
|
row.classList.toggle('on', val);
|
|
|
|
var dot = ftxt.querySelector('.status-dot');
|
|
if (val) {
|
|
if (dot) { dot.className = 'status-dot active'; }
|
|
ftxt.childNodes[ftxt.childNodes.length - 1].textContent = 'Auto-inject actif';
|
|
ftxt.classList.add('active');
|
|
statusDot.classList.add('live');
|
|
} else {
|
|
if (dot) { dot.className = 'status-dot'; }
|
|
ftxt.childNodes[ftxt.childNodes.length - 1].textContent = 'Désactivé';
|
|
ftxt.classList.remove('active');
|
|
statusDot.classList.remove('live');
|
|
}
|
|
}
|
|
|
|
function log(msg) { dbg.textContent = msg; }
|
|
|
|
/* ── Lecture ── */
|
|
function loadValue() {
|
|
try {
|
|
chrome.storage.local.get('nc_autoInject', function(result) {
|
|
if (chrome.runtime.lastError) { log(chrome.runtime.lastError.message); fallback(); return; }
|
|
var val = result['nc_autoInject'];
|
|
/* Si jamais défini → true par défaut */
|
|
setUI(val !== false);
|
|
if (val === undefined) saveValue(true);
|
|
});
|
|
} catch(e) { log(String(e)); fallback(); }
|
|
}
|
|
|
|
function fallback() {
|
|
try {
|
|
var v = localStorage.getItem('nc_autoInject');
|
|
setUI(v !== 'false');
|
|
if (v === null) saveValue(true);
|
|
} catch(e) { setUI(true); }
|
|
}
|
|
|
|
/* ── Sauvegarde ── */
|
|
function saveValue(val) {
|
|
try {
|
|
chrome.storage.local.set({ nc_autoInject: val }, function() {
|
|
if (chrome.runtime.lastError) log(chrome.runtime.lastError.message);
|
|
});
|
|
} catch(e) {}
|
|
try { localStorage.setItem('nc_autoInject', String(val)); } catch(e) {}
|
|
}
|
|
|
|
/* ── Toggle ── */
|
|
chk.addEventListener('change', function() {
|
|
saveValue(chk.checked);
|
|
setUI(chk.checked);
|
|
});
|
|
|
|
/* ── Texte du footer (nœuds) ── */
|
|
(function fixFooter() {
|
|
/* S'assure qu'il y a bien un TextNode après le span .status-dot */
|
|
var span = ftxt.querySelector('.status-dot');
|
|
if (span && !span.nextSibling) {
|
|
ftxt.appendChild(document.createTextNode('Prêt'));
|
|
}
|
|
})();
|
|
|
|
loadValue();
|