aboutsummaryrefslogtreecommitdiff
path: root/static/js/userconf.js
diff options
context:
space:
mode:
authorLibravatar Choom 2023-01-20 00:36:43 -0300
committerLibravatar Choom 2023-01-22 07:57:56 -0300
commit8e519f17d144165b6de31bf3ebabdab5eb13bf0d (patch)
tree10b3bd7affd037d198fc6ec54af6862cb0ce85b0 /static/js/userconf.js
parent649a2e5f4fa0b13a58068772ec72605dba6624d2 (diff)
downloadweabot-8e519f17d144165b6de31bf3ebabdab5eb13bf0d.tar.gz
weabot-8e519f17d144165b6de31bf3ebabdab5eb13bf0d.tar.xz
weabot-8e519f17d144165b6de31bf3ebabdab5eb13bf0d.zip
Config para el usuario
Diffstat (limited to 'static/js/userconf.js')
-rw-r--r--static/js/userconf.js164
1 files changed, 138 insertions, 26 deletions
diff --git a/static/js/userconf.js b/static/js/userconf.js
index 985090a..0118e88 100644
--- a/static/js/userconf.js
+++ b/static/js/userconf.js
@@ -7,25 +7,25 @@ function cargarEstilos() {
}
function listarEstilos(id, estilos, def) {
- var select = document.getElementById(id);
-
- for (var i=0; i < estilos.length; i++) {
- var opt = document.createElement('option');
- opt.value = estilos[i];
- opt.textContent = estilos[i];
- if (i == def) {
- opt.selected = true;
- }
- select.appendChild(opt);
- }
+ var select = document.getElementById(id);
+
+ for (var i=0; i < estilos.length; i++) {
+ var opt = document.createElement('option');
+ opt.value = estilos[i];
+ opt.textContent = estilos[i];
+ if (i == def) {
+ opt.selected = true;
+ }
+ select.appendChild(opt);
+ }
}
request.onreadystatechange = function() {
if (request.readyState == 4) {
var json = JSON.parse(request.responseText);
if (json.state == "success") {
- listarEstilos('stylebbs', json.bbs_styles, json.bbs_styles_default);
- listarEstilos('styleib', json.ib_styles, json.ib_styles_default);
+ listarEstilos('stylebbs', json.bbs_styles, json.bbs_styles_default);
+ listarEstilos('styleib', json.ib_styles, json.ib_styles_default);
}
}
};
@@ -37,11 +37,11 @@ function cambiarModo(e) {
if (this.dataset.view == '1') {
iframe.addEventListener('load', mostrarEstilo);
iframe.src = '/static/example/bbs2.html';
- this.value = 'Ver modo frontal';
+ this.value = 'Previsualizar board';
this.dataset.view = '2';
} else {
iframe.src = '/static/example/bbs1.html';
- this.value = 'Ver modo respuesta';
+ this.value = 'Previsualizar respuesta';
this.dataset.view = '1';
}
}
@@ -64,6 +64,10 @@ function mostrarEstilo(e) {
}
css.href = loc + estilo.toLowerCase() + ".css";
+
+ var key = 'weabot_style_' + tipo;
+ var estilo = document.getElementById(('style'+tipo)).value;
+ localStorage.setItem(key, estilo);
}
function cargariframe(tipo) {
@@ -73,7 +77,6 @@ function cargariframe(tipo) {
iframe.addEventListener('load', cargarDatos);
iframe.src = '/static/example/' + tipo + '1.html';
var div = document.getElementById("desc" + tipo);
- div.appendChild(document.createElement("br"));
div.appendChild(iframe);
}
@@ -89,26 +92,135 @@ function cargarDatos(e) {
this.removeEventListener('load', cargarDatos);
}
-function establecerEstilo(e) {
- var key = e.target.dataset.key;
-}
-
function init(tipo) {
cargariframe(tipo);
document.getElementById('style'+tipo).addEventListener('change', mostrarEstilo);
- document.getElementById('set'+tipo).addEventListener('click', function() {
- var key = 'weabot_style_' + tipo;
- var estilo = document.getElementById(('style'+tipo)).value;
- localStorage.setItem(key, estilo);
- });
+}
+
+function checkboxes() {
+ var chk = document.getElementsByClassName("weabot-obj");
+ for (var i=0; i < chk.length; i++) {
+ chk[i].addEventListener("change", saveInput);
+ }
+}
+
+function saveInput(e) {
+ var key = e.target.id;
+ weabot[key] = e.target.checked;
+ localStorage.setItem("weabot", JSON.stringify(weabot));
+}
+
+function setInputs() {
+ for (key in weabot) {
+ var chk = document.getElementById(key);
+ if (chk) {
+ document.getElementById(key).checked = weabot[key];
+ }
+ }
+}
+
+function cargarFiltros() {
+ var del = document.getElementsByClassName("f-remove");
+ for (var i=0; i < del.length; i++) {
+ del[i].addEventListener('click', quitarFiltro);
+ }
+
+ if (localStorage.hasOwnProperty("weabot-filtros")) {
+ var lista = document.getElementById("filterlist");
+ var filtros = JSON.parse(localStorage.getItem("weabot-filtros"));
+
+ for (var i=0; i < filtros.length; i++) {
+ nuevoFiltro(filtros[i].usar, filtros[i].patron, filtros[i].tipo);
+ }
+ } else {
+ nuevoFiltro();
+ }
+
+ document.getElementById('newfilter').addEventListener('click', function(){ nuevoFiltro(); });
+ document.getElementById('savefilters').addEventListener('click', guardarFiltros);
+}
+
+function nuevoFiltro(usar, patron, tipo) {
+ if (arguments.length == 0) {
+ var usar = true;
+ var patron = '';
+ var tipo = 0;
+ } else {
+ tipo = parseInt(tipo);
+ }
+
+ var lista = document.getElementById("filterlist");
+ var fila = document.createElement("tr");
+ var selected = ['', '', '', ''];
+ selected[tipo] = ' selected="selected"';
+ var html = '<td><input type="checkbox" name="f-enabled"'
+ + (usar ? ' checked="checked"></td>' : '></td>');
+ html += '<td><input type="text" name="f-pattern" value="' + patron + '"></td>';
+ html += '<td><select class="f-type">'
+ + '<option value="0"' + selected[0] + '>Mensaje</option>'
+ + '<option value="1"' + selected[1] + '>ID</option>'
+ + '<option value="2"' + selected[2] + '>Tripcode</option>'
+ + '<option value="3"' + selected[3] + '>Nombre</option>'
+ + '</select></td>';
+ html += '<td><input type="button" name="f-remove" class="f-remove" value="x"></td>';
+ fila.innerHTML = html;
+ fila.children[3].firstChild.addEventListener('click', quitarFiltro);
+ lista.appendChild(fila);
+}
+
+function quitarFiltro(e) {
+ var lista = document.getElementById("filterlist");
+ var delme = e.target.parentElement.parentElement;
+ if (lista.children.length == 1) {
+ nuevoFiltro();
+ }
+ delme.parentNode.removeChild(delme);
+}
+
+function guardarFiltros() {
+ var f;
+ var filtros = [];
+ var tr = document.getElementById("filterlist").getElementsByTagName("tr");
+
+ for (var i=0; i < tr.length; i++) {
+ var pat = tr[i].children[1].firstChild.value.trim();
+ if (pat != '') {
+ f = {
+ usar: tr[i].children[0].firstChild.checked,
+ patron: pat,
+ tipo: parseInt(tr[i].children[2].firstChild.value)
+ }
+ filtros.push(f);
+ }
+ }
+
+ if (filtros.length > 0) {
+ localStorage.setItem("weabot-filtros", JSON.stringify(filtros));
+ } else {
+ localStorage.removeItem("weabot-filtros");
+ }
}
document.addEventListener("DOMContentLoaded", function() {
- document.getElementById("escondeme").style.display = 'none';
+ if (localStorage.hasOwnProperty("weabot")) {
+ weabot = JSON.parse(localStorage.getItem("weabot"));
+ } else {
+ weabot = {
+ localtime: false,
+ qpreview: true,
+ backlink: true,
+ filters: false
+ };
+ localStorage.setItem("weabot", JSON.stringify(weabot));
+ }
+ setInputs();
cargarEstilos();
+ checkboxes();
+ cargarFiltros();
document.getElementById('switchview').addEventListener('click', cambiarModo);
+
init('bbs');
init('ib');
});