aboutsummaryrefslogtreecommitdiff
path: root/static/js/userconf.js
diff options
context:
space:
mode:
authorLibravatar Choom 2023-01-28 00:52:56 -0300
committerLibravatar Choom 2023-02-02 00:39:27 -0300
commit081ddc03aef7becc3b084a9079a2574fd3e3b49b (patch)
treea6ca793a0c21917d3774778c0a14f65a8c678113 /static/js/userconf.js
parentd0d6b8ebff31d2306a040dc9c53f9e5e7a0ec7a0 (diff)
downloadweabot-081ddc03aef7becc3b084a9079a2574fd3e3b49b.tar.gz
weabot-081ddc03aef7becc3b084a9079a2574fd3e3b49b.tar.xz
weabot-081ddc03aef7becc3b084a9079a2574fd3e3b49b.zip
userconf
Diffstat (limited to 'static/js/userconf.js')
-rw-r--r--static/js/userconf.js116
1 files changed, 66 insertions, 50 deletions
diff --git a/static/js/userconf.js b/static/js/userconf.js
index 0118e88..399878e 100644
--- a/static/js/userconf.js
+++ b/static/js/userconf.js
@@ -1,35 +1,3 @@
-var request = new XMLHttpRequest();
-
-function cargarEstilos() {
- var api = '/cgi/api/styles';
- request.open("GET", api, true);
- request.send();
-}
-
-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);
- }
-}
-
-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);
- }
- }
-};
-
function cambiarModo(e) {
var iframe = document.getElementById('examplebbs');
var estilo = document.getElementById('stylebbs').value;
@@ -63,7 +31,7 @@ function mostrarEstilo(e) {
loc += 'txt/';
}
- css.href = loc + estilo.toLowerCase() + ".css";
+ css.href = loc + estilo.trim().toLowerCase() + ".css";
var key = 'weabot_style_' + tipo;
var estilo = document.getElementById(('style'+tipo)).value;
@@ -74,32 +42,41 @@ function cargariframe(tipo) {
var iframe = document.createElement('iframe');
iframe.id = 'example' + tipo;
iframe.dataset.type = tipo;
- iframe.addEventListener('load', cargarDatos);
+ iframe.addEventListener('load', cargarEstilo);
iframe.src = '/static/example/' + tipo + '1.html';
var div = document.getElementById("desc" + tipo);
div.appendChild(iframe);
}
-function cargarDatos(e) {
+function cargarEstilo(e) {
var tipo = this.dataset.type;
var key = 'weabot_style_' + tipo;
+
if (localStorage.hasOwnProperty(key)) {
- var estilo = localStorage.getItem(key);
- document.getElementById(('style'+tipo)).value = estilo;
+ var estilo = localStorage.getItem(key).trim();
+
+ if (estilo != '') {
+ document.getElementById(('style'+tipo)).value = estilo;
+ } else {
+ localStorage.removeItem(key);
+ return;
+ }
+
mostrarEstilo(e);
this.tabIndex = -1;
}
- this.removeEventListener('load', cargarDatos);
+
+ this.removeEventListener('load', cargarEstilo);
}
function init(tipo) {
- cargariframe(tipo);
document.getElementById('style'+tipo).addEventListener('change', mostrarEstilo);
+ cargariframe(tipo);
}
function checkboxes() {
var chk = document.getElementsByClassName("weabot-obj");
- for (var i=0; i < chk.length; i++) {
+ for (var i=0; i < chk.length; i++) {
chk[i].addEventListener("change", saveInput);
}
}
@@ -151,19 +128,19 @@ function nuevoFiltro(usar, patron, tipo) {
var lista = document.getElementById("filterlist");
var fila = document.createElement("tr");
- var selected = ['', '', '', ''];
- selected[tipo] = ' selected="selected"';
+ 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;
+ + '<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);
}
@@ -201,7 +178,46 @@ function guardarFiltros() {
}
}
+function importar() {
+ var url = location.href;
+ if (url.includes('#import=')) {
+ var data = location.href.split('#import=')[1];
+ var conf = JSON.parse( decodeURIComponent(data) );
+ for (var c in conf) {
+ localStorage.setItem(c, conf[c]);
+ }
+ }
+}
+
+function exportar(e) {
+ var keys = Object.keys(localStorage);
+ var conf = {};
+ for (var i=0; i < keys.length; i++) {
+ var value = localStorage.getItem(keys[i]);
+ if (value.trim() != '') {
+ conf[keys[i]] = value;
+ }
+ }
+ var data = encodeURIComponent( JSON.stringify(conf) );
+ var box = document.getElementById('config-url');
+ if (!box) {
+ var box = document.createElement('input');
+ box.id = 'config-url';
+ box.type = 'text';
+ box.readOnly = true;
+ e.target.parentElement.appendChild(box);
+ var div = document.createElement('div');
+ div.textContent = 'Copia y pega el enlace generado en un navegador para importar tu configuraciĆ³n.';
+ e.target.parentElement.appendChild(div);
+ }
+ box.value = location.href.split('#')[0] + '#import=' + data;
+ box.focus();
+ box.select();
+}
+
document.addEventListener("DOMContentLoaded", function() {
+ importar();
+
if (localStorage.hasOwnProperty("weabot")) {
weabot = JSON.parse(localStorage.getItem("weabot"));
} else {
@@ -215,11 +231,11 @@ document.addEventListener("DOMContentLoaded", function() {
}
setInputs();
- cargarEstilos();
checkboxes();
cargarFiltros();
document.getElementById('switchview').addEventListener('click', cambiarModo);
+ document.getElementById('export').addEventListener('click', exportar);
init('bbs');
init('ib');