mirror of
https://github.com/Michatec/MiniFaceBook.git
synced 2026-04-01 07:56:28 +02:00
Files
This commit is contained in:
20
static/js/adstop.js
Normal file
20
static/js/adstop.js
Normal file
@@ -0,0 +1,20 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
var hash = window.location.hash;
|
||||
if (hash) {
|
||||
var tabTrigger = document.querySelector('#adminTab button[data-bs-target="' + hash + '"]');
|
||||
if (tabTrigger) {
|
||||
var tab = new bootstrap.Tab(tabTrigger);
|
||||
tab.show();
|
||||
}
|
||||
}
|
||||
|
||||
var triggerTabList = [].slice.call(document.querySelectorAll('#adminTab button'));
|
||||
triggerTabList.forEach(function (triggerEl) {
|
||||
triggerEl.addEventListener('shown.bs.tab', function (event) {
|
||||
var target = triggerEl.getAttribute('data-bs-target');
|
||||
if (target) {
|
||||
history.replaceState(null, null, target);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
16
static/js/events.js
Normal file
16
static/js/events.js
Normal file
@@ -0,0 +1,16 @@
|
||||
function reloadEvents() {
|
||||
fetch(apiEventsUrl)
|
||||
.then(r => r.json())
|
||||
.then(events => {
|
||||
let tbody = document.getElementById('events-tbody');
|
||||
tbody.innerHTML = "";
|
||||
for (let e of events) {
|
||||
let tr = document.createElement('tr');
|
||||
tr.innerHTML = `<td>${e.timestamp}</td><td>${e.message}</td>`;
|
||||
tbody.appendChild(tr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(reloadEvents, 10000);
|
||||
window.onload = reloadEvents;
|
||||
5
static/js/feed.js
Normal file
5
static/js/feed.js
Normal file
@@ -0,0 +1,5 @@
|
||||
function reload_feed() {
|
||||
setTimeout(function() {
|
||||
window.location.reload();
|
||||
}, 120000);
|
||||
}
|
||||
19
static/js/sw.js
Normal file
19
static/js/sw.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const CACHE_NAME = "minifb-v1";
|
||||
const urlsToCache = [
|
||||
"/",
|
||||
"/static/css/styles.css",
|
||||
"/static/js/theme.js",
|
||||
"/static/manifest.json"
|
||||
];
|
||||
|
||||
self.addEventListener("install", event => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then(cache => cache.addAll(urlsToCache))
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", event => {
|
||||
event.respondWith(
|
||||
caches.match(event.request).then(response => response || fetch(event.request))
|
||||
);
|
||||
});
|
||||
25
static/js/theme.js
Normal file
25
static/js/theme.js
Normal file
@@ -0,0 +1,25 @@
|
||||
function setTheme(mode, save=true) {
|
||||
document.body.classList.remove('light-mode', 'dark-mode');
|
||||
document.body.classList.add(mode + '-mode');
|
||||
document.getElementById('theme-icon').className = mode === 'dark' ? 'bi bi-moon-fill' : 'bi bi-sun-fill';
|
||||
document.getElementById('theme-label').textContent = mode === 'dark' ? 'Dark-Mode' : 'Light-Mode';
|
||||
if(save) document.cookie = "theme=" + mode + ";path=/;max-age=31536000";
|
||||
}
|
||||
function getCookie(name) {
|
||||
let v = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
|
||||
return v ? v[2] : null;
|
||||
}
|
||||
|
||||
function systemPrefersDark() {
|
||||
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
let theme = getCookie('theme');
|
||||
if(!theme) theme = systemPrefersDark() ? 'dark' : 'light';
|
||||
setTheme(theme, false);
|
||||
document.getElementById('toggle-theme').onclick = function() {
|
||||
let newTheme = document.body.classList.contains('dark-mode') ? 'light' : 'dark';
|
||||
setTheme(newTheme);
|
||||
};
|
||||
});
|
||||
9
static/js/translate.js
Normal file
9
static/js/translate.js
Normal file
@@ -0,0 +1,9 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.querySelectorAll('.lang-select').forEach(function(el) {
|
||||
el.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
document.cookie = "lang=" + this.dataset.lang + ";path=/";
|
||||
location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user