aboutsummaryrefslogtreecommitdiff
path: root/static/js
diff options
context:
space:
mode:
authorLibravatar Choom 2023-01-16 05:32:08 -0300
committerLibravatar Choom 2023-01-18 22:06:34 -0300
commit542e8d1452130079ae47f7a56328f8421e56f5ab (patch)
tree37c15cdd5803f05ad5a36fb2e62cd05ad3fc6ef3 /static/js
parent53056e445626d21523a799c8d8f03b16f24b0c47 (diff)
downloadweabot-542e8d1452130079ae47f7a56328f8421e56f5ab.tar.gz
weabot-542e8d1452130079ae47f7a56328f8421e56f5ab.tar.xz
weabot-542e8d1452130079ae47f7a56328f8421e56f5ab.zip
Config para el usuario
Diffstat (limited to 'static/js')
-rw-r--r--static/js/userconf.js114
-rw-r--r--static/js/weabotxt.js2
2 files changed, 115 insertions, 1 deletions
diff --git a/static/js/userconf.js b/static/js/userconf.js
new file mode 100644
index 0000000..985090a
--- /dev/null
+++ b/static/js/userconf.js
@@ -0,0 +1,114 @@
+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;
+
+ if (this.dataset.view == '1') {
+ iframe.addEventListener('load', mostrarEstilo);
+ iframe.src = '/static/example/bbs2.html';
+ this.value = 'Ver modo frontal';
+ this.dataset.view = '2';
+ } else {
+ iframe.src = '/static/example/bbs1.html';
+ this.value = 'Ver modo respuesta';
+ this.dataset.view = '1';
+ }
+}
+
+function mostrarEstilo(e) {
+ var tipo = e.target.dataset.type;
+ if (e.target.tagName.toLowerCase() == 'iframe') {
+ var estilo = document.getElementById(('style'+tipo)).value;
+ var iframe = e.target;
+ } else {
+ var estilo = e.target.value;
+ var id = "example" + tipo;
+ var iframe = document.getElementById(id);
+ }
+
+ var css = iframe.contentDocument.getElementById('css');
+ var loc = "/static/css/";
+ if (tipo == 'bbs') {
+ loc += 'txt/';
+ }
+
+ css.href = loc + estilo.toLowerCase() + ".css";
+}
+
+function cargariframe(tipo) {
+ var iframe = document.createElement('iframe');
+ iframe.id = 'example' + tipo;
+ iframe.dataset.type = 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);
+}
+
+function cargarDatos(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;
+ mostrarEstilo(e);
+ this.tabIndex = -1;
+ }
+ 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);
+ });
+}
+
+document.addEventListener("DOMContentLoaded", function() {
+ document.getElementById("escondeme").style.display = 'none';
+
+ cargarEstilos();
+
+ document.getElementById('switchview').addEventListener('click', cambiarModo);
+ init('bbs');
+ init('ib');
+});
diff --git a/static/js/weabotxt.js b/static/js/weabotxt.js
index 2c93105..27d3cda 100644
--- a/static/js/weabotxt.js
+++ b/static/js/weabotxt.js
@@ -1,4 +1,4 @@
-var style_cookie = "weabot_style_txt";
+var style_cookie = "weabot_style_bbs";
if (localStorage.hasOwnProperty(style_cookie)) {
setTheme(localStorage.getItem(style_cookie));
}