diff options
author | junk | 2021-03-28 07:51:40 -0300 |
---|---|---|
committer | junk | 2021-03-31 05:27:26 -0300 |
commit | f7baf0c69606d49c6be86d3f27bc88d9d58cd4ba (patch) | |
tree | f0d72c1a497f73863078f1970e3ba692ffec860d /static/js/weabotxt.js | |
parent | aa8a6056f4c3cd8c6663d1714782f972bcb87b8f (diff) | |
download | weabot-f7baf0c69606d49c6be86d3f27bc88d9d58cd4ba.tar.gz weabot-f7baf0c69606d49c6be86d3f27bc88d9d58cd4ba.tar.xz weabot-f7baf0c69606d49c6be86d3f27bc88d9d58cd4ba.zip |
Mejor forma de ocultar posts
Diffstat (limited to 'static/js/weabotxt.js')
-rw-r--r-- | static/js/weabotxt.js | 114 |
1 files changed, 53 insertions, 61 deletions
diff --git a/static/js/weabotxt.js b/static/js/weabotxt.js index df4bc56..fec445d 100644 --- a/static/js/weabotxt.js +++ b/static/js/weabotxt.js @@ -1,11 +1,9 @@ var style_cookie = "weabot_style_txt"; -if (style_cookie && localStorage.hasOwnProperty(style_cookie)) { - set_stylesheet(localStorage.getItem(style_cookie)); +if (localStorage.hasOwnProperty(style_cookie)) { + setTheme(localStorage.getItem(style_cookie)); } -var hiddenposts = Array(); - -function set_stylesheet(styletitle) { +function setTheme(styletitle) { var css = document.getElementById("css"); if (css) css.href = "/static/css/txt/" + styletitle.toLowerCase() + ".css"; localStorage.setItem(style_cookie, styletitle); @@ -28,9 +26,8 @@ if (!Array.prototype.indexOf) { function getPassword() { if (weabot.password) return weabot.password; var pass = ""; - var char = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!-_."; - while (pass.length < 10) { + var char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?!-_."; + for (var i=0; i<11; i++) { pass += char[Math.floor(Math.random() * char.length)]; } weabot.password = pass; @@ -135,6 +132,24 @@ function previewPost(e) { xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(text); } +function get_xmlhttp() { + var xmlhttp; + try { + xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e1) { + try { + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (e1) { + xmlhttp = null; + } + } + if (!xmlhttp && typeof XMLHttpRequest != "undefined") + xmlhttp = new XMLHttpRequest(); + return xmlhttp; +} +function is_ie() { + return document.all && !document.opera; +} function listSort(e) { e.preventDefault(); @@ -178,52 +193,23 @@ function searchSubjects(e) { } } -function get_xmlhttp() { - var xmlhttp; - try { - xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); - } catch (e1) { - try { - xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); - } catch (e1) { - xmlhttp = null; - } - } - if (!xmlhttp && typeof XMLHttpRequest != "undefined") - xmlhttp = new XMLHttpRequest(); - return xmlhttp; -} - -function is_ie() { - return document.all && !document.opera; -} - -function showpost(post) { - post.children[0].classList.remove("hidden"); - post.children[1].removeAttribute("style"); -} -function hidepost(post) { - post.children[0].classList.add("hidden"); - post.children[1].style.display = "none"; -} -function togglepost(e) { - e.preventDefault(); - var post = this.parentElement; - var postid = board + this.getElementsByClassName("date")[0].dataset.unix; - if (post.children[1].style.display == "none") { - showpost(post); - if (hiddenposts.includes(postid)) - hiddenposts.splice(hiddenposts.indexOf(postid), 1); +function togglePost(e) { + var post = e.parentElement; + var pid = post.id.slice(1); + + var hidp = localStorage.getItem("hid-p-"+board); + var hid = Array(); + if (hidp) hid = hidp.split("!"); + + if (post.classList.contains("hidden")) { + post.classList.remove("hidden"); + if (hid.includes(pid)) hid.splice(hid.indexOf(pid), 1); } else { - hidepost(post); - if (!hiddenposts.includes(postid)) hiddenposts.push(postid); + post.classList.add("hidden"); + if (!hid.includes(pid)) hid.push(pid); } - localStorage.setItem("hiddenposts", hiddenposts.join("!")); -} -function applyTheme() { - var newTheme = document.getElementById("styles").value; - set_stylesheet(newTheme); + localStorage.setItem("hid-p-"+board, hid.join("!")); } document.addEventListener("DOMContentLoaded", function() { @@ -232,6 +218,7 @@ document.addEventListener("DOMContentLoaded", function() { else weabot = { name: null, email: null, password: null }; board = document.body.dataset.brd; + var head = document.getElementById("main_nav"); if (head) { var b = head.getElementsByTagName("a"); @@ -250,7 +237,7 @@ document.addEventListener("DOMContentLoaded", function() { var styleSelect = document.getElementById("styles"); if (styleSelect) { - styleSelect.addEventListener("change", applyTheme, false); + styleSelect.addEventListener("change", function(e) { setTheme(this.value); }); styleSelect.value = localStorage.getItem(style_cookie); } @@ -262,16 +249,13 @@ document.addEventListener("DOMContentLoaded", function() { document.getElementById("l_sr").addEventListener("keyup", searchSubjects); } - if (localStorage.hasOwnProperty("hiddenposts")) - hiddenposts = localStorage.getItem("hiddenposts").split("!"); - - var dt = document.getElementsByClassName("date"); - for (var i = 0; i < dt.length; i++) { - if (hiddenposts.includes(board + dt[i].dataset.unix)) { - console.log(dt[i].dataset.unix); - hidepost(dt[i].parentElement.parentElement); + var hidp = localStorage.getItem("hid-p-"+board); + if (hidp) { + var hid = hidp.split("!"); + for (var i = 0; i < hid.length; i++) { + var post = document.getElementById("p"+hid[i]); + if (post) post.classList.add("hidden"); } - dt[i].parentElement.addEventListener("dblclick", togglepost); } }); @@ -287,4 +271,12 @@ document.addEventListener("click", function(e) { deletePost(e.target); return; } +}, false); + +document.addEventListener("dblclick", function(e) { + if (e.target.closest("h4")) { + e.preventDefault(); + togglePost(e.target.closest("h4")); + return; + } }, false);
\ No newline at end of file |