Advertisement
bitrate16

Untitled

Jul 24th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 33.41 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4.     <title>
  5.         <%>Here will be page title</%>
  6.     </title>
  7.     <!-- fs?f=w/ -->
  8.    
  9.     <META content="text/html; charset=utf-8" http-equiv=Content-Type>
  10.     <link rel="stylesheet" href="fs?f=w/styles/style-showthread.css">
  11.     <!--  -->
  12.  
  13.  
  14.     <script type="text/javascript">
  15.         window.storage = {
  16.             "ROOT_URL": "localhost:24971",
  17.             "branch": "<%>Here will be branch of current threads, delimited by '/'</%>",
  18.             "branch_nodes": "<%>Array of branch nodes goes here, splitten by ','</%>",
  19.             "branch_posts": <%>JSON Array with posts goes here. Display only current page</%>,
  20.             "page_count": <%>Amount of pages goes here</%>,
  21.             "edit_mode": false,
  22.             "edit_id": -1,
  23.             "expanders": [],
  24.             "users": {},
  25.             "can_send": true
  26.         };
  27.  
  28.         window.onload = function() {
  29.             initExpanders();
  30.             rebuildBlockquotes();
  31.             var id = setInterval(function() {
  32.                 scrollToSelectedID();
  33.                 clearInterval(id);
  34.             }, 1000);
  35.         };
  36.  
  37.         function initExpanders() {
  38.             // <div class="expander-view">
  39.             //     <div class="expander-header"></div>
  40.             //     <div class="expander-body"></div>
  41.             // </div>
  42.  
  43.             var expanders = document.getElementsByClassName("expander-view");
  44.  
  45.             for (var i = 0; i < expanders.length; i++) {
  46.                var expander = {
  47.                    active: false,
  48.                    c0: expanders[i].getElementsByClassName("expander-header")[0],
  49.                    c1: expanders[i].getElementsByClassName("expander-body")[0]
  50.                };
  51.                expander.change = function() {
  52.                    if (expander.active)
  53.                        expander.c1.style.display = "none";
  54.                    else
  55.                        expander.c1.style.display = "block";
  56.                    expander.active = !expander.active;
  57.                };
  58.                expander.expand = function() {
  59.                    expander.c1.style.display = "block";
  60.                    expander.active = true;
  61.                };
  62.                expander.collapse = collapse = function() {
  63.                    expander.c1.style.display = "none";
  64.                    expander.active = false;
  65.                };
  66.                expander.c0.onclick = expander.change;
  67.                expander.collapse();
  68.  
  69.                window.storage.expanders.push(expander);
  70.            }
  71.        }
  72.  
  73.        function rebuildBlockquotes() {
  74.            // <div class="blockquote">
  75.  
  76.             var blockquotes = document.getElementsByClassName("blockquote");
  77.  
  78.             for (var i = 0; i < blockquotes.length; i++) {
  79.                var text = blockquotes[i].innerHTML;
  80.  
  81.                // Text block background
  82.                text = blockquote(text, "REDB", "span style=\"background-color:red\"", true);
  83.                text = blockquote(text, "GREENB", "span style=\"background-color:green\"", true);
  84.                text = blockquote(text, "BLUEB", "span style=\"background-color:blue\"", true);
  85.                text = blockquote(text, "YELLOWB", "span style=\"background-color:yellow\"", true);
  86.  
  87.                // Text block color
  88.                text = blockquote(text, "RED", "span style=\"color:red\"", true);
  89.                text = blockquote(text, "GREEN", "span style=\"color:green\"", true);
  90.                text = blockquote(text, "BLUE", "span style=\"color:blue\"", true);
  91.                text = blockquote(text, "YELLOW", "span style=\"color:yellow\"", true);
  92.  
  93.                // XXX: Parse BLOCKQUOTE attributes
  94.                text = blockquote(text, "B", "b");
  95.                text = blockquote(text, "I", "i");
  96.                text = blockquote(text, "U", "u");
  97.                text = blockquote(text, "H1", "h1");
  98.                text = blockquote(text, "H2", "h2");
  99.                text = blockquote(text, "H3", "h3");
  100.                text = blockquote(text, "H4", "h4");
  101.                text = blockquote(text, "H5", "h5");
  102.                text = blockquote(text, "H6", "h6");
  103.                text = blockquote(text, "FRAME", "iframe");
  104.                text = blockquote(text, "IMG", "img");
  105.                text = blockquote(text, "VIDEO", "video");
  106.                text = blockquote(text, "AUDIO", "audio");
  107.                text = blockquote(text, "SOURCE", "source");
  108.                text = blockquote(text, "A", "a");
  109.  
  110.                if (blockquotechanges == 0)
  111.                    continue;
  112.                blockquotechanges = 0;
  113.  
  114.                blockquotes[i].innerHTML = text;
  115.  
  116.                // Additional function for opening images in new tab on click
  117.                var images = blockquotes[i].getElementsByTagName("img");
  118.                for (j in images) {
  119.                    const image_ = images[j];
  120.                    if (typeof image_ != "object")
  121.                        continue;
  122.  
  123.                    image_.setAttribute('title', 'CLICK to open');
  124.                    image_.onclick = function(e) {
  125.                        e.preventDefault();
  126.  
  127.                        //                        if (e.ctrlKey)
  128.                        window.open(image_.src, '_blank').focus();
  129.                    };
  130.                }
  131.            }
  132.        }
  133.  
  134.        var blockquotechanges = 0;
  135.  
  136.        function blockquote(string, block, tag, excludeMatch) {
  137.            string = string.replace(new RegExp("\\[(" + block + ").*?\\]", "g"), function(match) {
  138.                match = match.substr(1 + block.length, match.length - 2 - block.length);
  139.                blockquotechanges++;
  140.                return "<" + tag + (excludeMatch ? "" : match) + ">";
  141.             });
  142.             string = string.replace(new RegExp("\\[/(" + block + ")\\]", "g"), "</" + tag.split(" ")[0] + ">");
  143.             return string;
  144.         }
  145.  
  146.         function createThread() {
  147.             var name = prompt("Enter Thread name");
  148.  
  149.             if (name != undefined && name != null && name.match(/([A-Z0-9a-zа-яА-Я])+([A-Z.0-9a-zа-яА-Я\-_() ])*/g)) {
  150.                name = name.trim();
  151.                 var xhr = new XMLHttpRequest;
  152.                 xhr.open("GET", "/st?a=c&t=" + window.storage.branch + "&n=" + name + "&token=" + getCookie("token"), false);
  153.                 xhr.send();
  154.  
  155.                 if (xhr.status != 200)
  156.                     alert(xhr.responseText);
  157.                 else
  158.                     window.location = "/st?t=" + xhr.responseText;
  159.  
  160.             } else if (name == undefined || name == null || name.length == 0) return;
  161.             else alert("Invalid name: " + name + "\nExpected to match pattern ([A-Z0-9a-z])+([A-Z.0-9a-z\-_() ])*");
  162.         }
  163.  
  164.         function deleteThread(e, elem, name) {
  165.             if (name != undefined && name != null) {
  166.                if (!e.ctrlKey)
  167.                    if (!confirm("Delete Thread " + name + "?")) return;
  168.  
  169.                 name = name.trim();
  170.                 var xhr = new XMLHttpRequest;
  171.                 xhr.open("GET", "/st?a=d&t=" + window.storage.branch + "&n=" + name + "&token=" + getCookie("token"), false);
  172.                 xhr.send();
  173.  
  174.                 if (xhr.status != 200)
  175.                     alert(xhr.responseText);
  176.                 else if (!e.ctrlKey)
  177.                     window.location = "/st?t=" + xhr.responseText;
  178.                 else if (e.ctrlKey) {
  179.                     elem.style.backgroundColor = "red";
  180.                 }
  181.             }
  182.         }
  183.  
  184.         function getUser(id) {
  185.             var user = window.storage.users[id];
  186.             if (user == null || user == undefined) {
  187.                 user = {};
  188.                 if (getCookie("id") == (id + "")) {
  189.                     user = {};
  190.                     user.login = getCookie("login");
  191.                     user.id = getCookie("id");
  192.                     user.is_moder = getCookie("is_moder");
  193.                     user.is_admin = getCookie("is_admin");
  194.                     user.token = getCookie("token");
  195.  
  196.                     window.storage.users[id] = user;
  197.                 } else {
  198.                     var xhr = new XMLHttpRequest;
  199.                     xhr.open("GET", "/us?a=gbid&id=" + id, false);
  200.                     xhr.send();
  201.  
  202.                     if (xhr.status != 200)
  203.                         console.log(xhr.responseText);
  204.                     else {
  205.                         user = {};
  206.                         var json = JSON.parse(xhr.responseText);
  207.                         user["login"] = json.login;
  208.                         user["id"] = json.id;
  209.                         user["is_moder"] = json.is_moder;
  210.                         user["is_admin"] = json.is_admin;
  211.                         user["token"] = json.token;
  212.  
  213.                         window.storage.users[id] = user;
  214.                     }
  215.                 }
  216.             }
  217.             return user;
  218.         }
  219.  
  220.         function deletePost(e, elem, id) {
  221.             if (id != undefined && id != null) {
  222.                var xhr = new XMLHttpRequest;
  223.                 xhr.open("GET", "/st?a=dp&id=" + id + "&token=" + getCookie("token"), false);
  224.                 xhr.send();
  225.  
  226.                 if (xhr.status != 200)
  227.                     alert(xhr.responseText);
  228.                 else if (!e.ctrlKey)
  229.                     window.location = "/st?t=" + window.storage.branch;
  230.                 else if (e.ctrlKey) {
  231.                     elem.style.backgroundColor = "red";
  232.                 }
  233.             }
  234.         }
  235.  
  236.         function setCookie(cname, cvalue, exdays) {
  237.             var d = new Date();
  238.             d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  239.             var expires = "expires=" + d.toUTCString();
  240.             document.cookie = cname + "=" + cvalue + "; " + expires;
  241.         }
  242.  
  243.         function getCookie(cname) {
  244.             var name = cname + "=";
  245.             var ca = document.cookie.split(';');
  246.             for (var i = 0; i < ca.length; i++) {
  247.                var c = ca[i];
  248.                while (c.charAt(0) == ' ') {
  249.                    c = c.substring(1);
  250.                }
  251.                if (c.indexOf(name) == 0) {
  252.                    return c.substring(name.length, c.length);
  253.                }
  254.            }
  255.            return undefined;
  256.        }
  257.  
  258.        (function() {
  259.            if (getCookie("token") == undefined || getCookie("token").length == 0)
  260.                return;
  261.  
  262.            // validate user token in background
  263.            var xhr = new XMLHttpRequest;
  264.            xhr.open("GET", "/us?a=v&token=" + getCookie("token"), false);
  265.            xhr.send();
  266.  
  267.            if (xhr.status != 200)
  268.                console.log(xhr.responseText);
  269.            else if (xhr.responseText[0] == "0") {
  270.                setCookie("login", "");
  271.                setCookie("id", "id");
  272.                setCookie("token", "");
  273.                window.location.reload();
  274.            }
  275.  
  276.        })();
  277.  
  278.        function scrollIntoView(eleID) {
  279.            var e = document.getElementById(eleID);
  280.            if (!!e && e.scrollIntoView) {
  281.                e.scrollIntoView();
  282.            }
  283.        }
  284.  
  285.        function getParameter(name) {
  286.            if (name = (new RegExp('[?&]' + encodeURIComponent(name) + '=([^&]*)')).exec(location.search))
  287.                return decodeURIComponent(name[1]);
  288.        }
  289.  
  290.        function scrollToSelectedID() {
  291.            var id = getParameter("id");
  292.            if (id != null && id != undefined && id != "")
  293.                scrollIntoView(id);
  294.        }
  295.  
  296.    </script>
  297. </head>
  298.  
  299. <body>
  300.     <div class="header">
  301.         <div style="width: 100%; border: 1px solid black; text-align: right">
  302.             <div style="display: inline-block; position: absolute; left: 1%" id="logged-as"></div>
  303.             <input type="email" alt="login" placeholder="login" id="login">
  304.             <input type="password" alt="password" placeholder="password" id="password">
  305.             <input type="button" value="register" id="register-button">
  306.             <input type="button" value="login" id="login-button">
  307.             <input type="button" value="change password" id="change-password-button">
  308.         </div>
  309.         <script type="text/javascript">
  310.             (function() {
  311.                 document.getElementById("logged-as").innerHTML += "<b>" + getCookie("login") + "</b>";
  312.  
  313.                 document.getElementById("login-button").onclick = function() {
  314.                     var login = document.getElementById("login").value;
  315.                     var password = document.getElementById("password").value;
  316.  
  317.                     var xhr = new XMLHttpRequest;
  318.                     xhr.open("GET", "/us?a=l&login=" + login + "&password=" + password, false);
  319.                     xhr.send();
  320.  
  321.                     if (xhr.status != 200)
  322.                         alert(xhr.responseText);
  323.                     else {
  324.                         var json = JSON.parse(xhr.responseText);
  325.                         setCookie("login", json.login);
  326.                         setCookie("id", json.id);
  327.                         setCookie("is_moder", json.is_moder);
  328.                         setCookie("is_admin", json.is_admin);
  329.                         setCookie("token", json.token);
  330.                         window.location.reload();
  331.                     }
  332.                 };
  333.                 document.getElementById("register-button").onclick = function() {
  334.                     var login = document.getElementById("login").value;
  335.                     var password = document.getElementById("password").value;
  336.  
  337.                     var xhr = new XMLHttpRequest;
  338.                     xhr.open("GET", "/us?a=r&login=" + login + "&password=" + password, false);
  339.                     xhr.send();
  340.  
  341.                     if (xhr.status != 200)
  342.                         alert(xhr.responseText);
  343.                     else {
  344.                         var json = JSON.parse(xhr.responseText);
  345.                         setCookie("login", json.login);
  346.                         setCookie("id", json.id);
  347.                         setCookie("is_moder", json.is_moder);
  348.                         setCookie("is_admin", json.is_admin);
  349.                         setCookie("token", json.token);
  350.                         window.location.reload();
  351.                     }
  352.                 };
  353.                 document.getElementById("change-password-button").onclick = function() {
  354.                     var password = document.getElementById("password").value;
  355.  
  356.                     var xhr = new XMLHttpRequest;
  357.                     xhr.open("GET", "/us?a=cp&password=" + password + "&token=" + getCookie("token"), false);
  358.                     xhr.send();
  359.  
  360.                     if (xhr.status != 200)
  361.                         alert(xhr.responseText);
  362.                     else {
  363.                         var json = JSON.parse(xhr.responseText);
  364.                         setCookie("login", json.login);
  365.                         setCookie("id", json.id);
  366.                         setCookie("is_moder", json.is_moder);
  367.                         setCookie("is_admin", json.is_admin);
  368.                         setCookie("token", json.token);
  369.                         window.location.reload();
  370.                     }
  371.                 };
  372.             })();
  373.  
  374.         </script>
  375.         <div class="header-subsection" id="branch"></div>
  376.         <script type="text/javascript">
  377.             (function() {
  378.                 var elem = document.getElementById("branch");
  379.                 var parts = window.storage.branch.split("\/");
  380.                 window.storage.cur_node = parts[parts.length - 1];
  381.  
  382.                 for (var i = 0; i < parts.length; i++) {
  383.                    if (i == 0)
  384.                        elem.innerHTML += "<a href=\"/st?t=/\">$</a>";
  385.                     elem.innerHTML += " / ";
  386.  
  387.                     var url = "/st?t=";
  388.                     for (var j = 0; j < i + 1; j++) {
  389.                        url += "/";
  390.                        url += parts[j];
  391.                    }
  392.  
  393.                    var link = document.createElement(i == parts.length - 1 ? "b" : "a");
  394.                    link.setAttribute("href", url);
  395.                    link.innerHTML = parts[i];
  396.                    elem.appendChild(link);
  397.                }
  398.            })();
  399.  
  400.        </script>
  401.         <div class="h-splitter"></div>
  402.         <div class="header-subsection">
  403.             <div class="expander-view">
  404.                 <div class="expander-header" id="branch-expander-header"></div>
  405.                 <div class="h-splitter"></div>
  406.                 <div class="expander-body" id="branch-expander-body">
  407.  
  408.                 </div>
  409.                 <script type="text/javascript">
  410.                     (function() {
  411.                         document.getElementById("branch-expander-header").innerHTML = "/" + window.storage.cur_node + " =>";
  412.                         var body = document.getElementById("branch-expander-body");
  413.  
  414.                         if (!(getCookie("token") == "" || getCookie("token") == undefined))
  415.                             body.innerHTML += '<div onclick="createThread()">+ Thread</div>';
  416.  
  417.                         if (window.storage.branch_nodes.length == 0)
  418.                             return;
  419.  
  420.                         window.storage.nodes_t = window.storage.branch_nodes.split(",");
  421.                         window.storage.nodes = [];
  422.                         for (var i = 0; i < window.storage.nodes_t.length; i++)
  423.                            window.storage.nodes[i] = window.storage.nodes_t[i].split("/");
  424.  
  425.                        for (var i = 0; i < window.storage.nodes.length; i++) {
  426.                            var url = (window.storage.branch.endsWith("/") ? window.storage.branch.substr(0, window.storage.branch.length - 1) : window.storage.branch);
  427.                            url += "/" + window.storage.nodes[i][0].trim();
  428.  
  429.                            var link = document.createElement("a");
  430.                            link.setAttribute("href", "/st?t=" + (url.startsWith("/") ? url : ("/" + url)));
  431.                            link.innerHTML = "/" + window.storage.nodes[i][0].trim();
  432.                            body.appendChild(link);
  433.                            if (getCookie("is_admin") == 1 || getCookie("id") == window.storage.nodes[i][1])
  434.                                body.innerHTML += '&nbsp;<a class="delete" onclick="deleteThread(event, this,\'' + window.storage.nodes[i][0] + '\')">(delete)</a>'
  435.  
  436.                             if (i < window.storage.nodes.length - 1)
  437.                                body.appendChild(document.createElement("div"));
  438.                        }
  439.                    })();
  440.  
  441.                </script>
  442.             </div>
  443.             <div style="border: 1px solid black; display: inline-block; width: 100%" id="pages0"></div>
  444.             <div style="width: 100%; border: 1px solid black; text-align: center" onclick="window.scrollTo(0, document.body.scrollHeight);">↓↓↓ на дно ↓↓↓</div>
  445.         </div>
  446.     </div>
  447.     <br>
  448.     <div class="content" id="content-block"></div>
  449.     <script type="text/javascript">
  450.         function editPost(event, post_id) {
  451.             window.storage.edit_mode = true;
  452.             window.storage.edit_id = post_id;
  453.  
  454.             document.getElementById("post-text").value = window.storage.posts_by_id[post_id].message;
  455.             document.getElementById("post-text").focus();
  456.         }
  457.  
  458.         (function() {
  459.             var elem = document.getElementById("content-block");
  460.             window.storage.posts_by_id = {};
  461.  
  462.             for (var i = 0; i < window.storage.branch_posts.length; i++) {
  463.                window.storage.posts_by_id[window.storage.branch_posts[i].id] = window.storage.branch_posts[i];
  464.                var post = window.storage.branch_posts[i];
  465.                var innerHTML = '<div class="h-splitter"></div>';
  466.                 innerHTML += '<div class="post-header">'; // Post header data hoes here:
  467.                 innerHTML += '<b>' + getUser(post.author_id).login + '</b>&nbsp;';
  468.                 var d = new Date(post.date),
  469.                     dformat = [d.getMonth() + 1,
  470.                         d.getDate(),
  471.                         d.getFullYear()
  472.                     ].join('/') + ' ' + [d.getHours(),
  473.                         d.getMinutes(),
  474.                         d.getSeconds()
  475.                     ].join(':');
  476.                 innerHTML += '<div style="display:inline-block" id=\"' + post.id + '\"><i>' + dformat + '</i></div>&nbsp;';
  477.                 innerHTML += '<div style="display:inline-block"><a href="/st?a=pid&id=' + post.id + '"><b>#' + post.id + '</b></a></div>&nbsp;';
  478.                 if (getCookie("is_moder") == 1 || getCookie("is_admin") == 1 || post.author_id == getCookie("id")) {
  479.                     innerHTML += '<div class="delete" style="display:inline-block" onclick="deletePost(event, this, ' + post.id + ')">(delete)</div>';
  480.  
  481.                     innerHTML += '<div class="edit" style="display:inline-block" onclick="editPost(event, ' + post.id + ')">(edit)</div>';
  482.                 }
  483.                 innerHTML += '</div>';
  484.                 innerHTML += '<br>';
  485.                 innerHTML += '<div class="blockquote"><pre>' + post.message + '</pre></div>';
  486.  
  487.                 elem.innerHTML += innerHTML;
  488.             }
  489.         })();
  490.  
  491.     </script>
  492.     <div style="width: 100%; border: 1px solid black; text-align: center" onclick="window.scrollTo(0, 0);">↑↑↑ с дна ↑↑↑</div>
  493.     <br>
  494.     <div class="post-writer">
  495.         <script type="text/javascript">
  496.             function insertImage() {
  497.                 var url = prompt("Paste image URL here");
  498.                 if (url == null || url == undefined || url.length == 0)
  499.                     return;
  500.  
  501.                 insertText("[IMG width=300 src=\"" + url + "\"]", true);
  502.             }
  503.  
  504.             function insertVideo() {
  505.                 var url = prompt("Paste video URL here");
  506.                 if (url == null || url == undefined || url.length == 0)
  507.                     return;
  508.  
  509.                 insertText("[VIDEO controls][SOURCE src=\"" + url + "\" type=\"" + (url.endsWith("mp4") ? "video/mp4" : (url.endsWith("webm") ? "video/webm" : (url.endsWith("ogg") ? "video/ogg" : ""))) + "\"][/VIDEO]", true);
  510.             }
  511.  
  512.             function insertYoutube() {
  513.                 var url = prompt("Paste youtube video URL here");
  514.                 if (url == null || url == undefined || url.length == 0)
  515.                     return;
  516.  
  517.                 var url_split = url.split("/");
  518.                 var url_split = url_split[url_split.length - 1].split("=");
  519.                 insertText("[FRAME width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/" + url_split[url_split.length - 1] + "\" frameborder=\"0\" allowfullscreen]", true);
  520.             }
  521.  
  522.             function insertCoub() {
  523.                 var url = prompt("Paste youtube video URL here");
  524.                 if (url == null || url == undefined || url.length == 0)
  525.                     return;
  526.  
  527.                 var url_split = url.split("/");
  528.                 insertText("[FRAME width=\"400\" height=\"224\" src=\"https://coub.com/embed/" + url_split[url_split.length - 1] + "?muted=false&autostart=false&originalSize=false&startWithHD=false\" frameborder=\"0\" allowfullscreen]", true);
  529.             }
  530.  
  531.             function insertAudio() {
  532.                 var url = prompt("Paste audio URL here");
  533.                 if (url == null || url == undefined || url.length == 0)
  534.                     return;
  535.  
  536.                 insertText("[AUDIO controls][SOURCE src=\"" + url + "\" type=\"" + (url.endsWith("mp3") ? "audio/mpeg" : (url.endsWith("ogg") ? "audio/ogg" : (url.endsWith("wav") ? "audio/wav" : ""))) + "\"][/AUDIO]", true);
  537.             }
  538.  
  539.             function insertIFrame() {
  540.                 var url = prompt("Paste frame URL here");
  541.                 if (url == null || url == undefined || url.length == 0)
  542.                     return;
  543.  
  544.                 insertText("[FRAME src=\"" + url + "\"]", true);
  545.             }
  546.  
  547.             function insertURL() {
  548.                 var url = prompt("Paste URL here");
  549.                 if (url == null || url == undefined || url.length == 0)
  550.                     return;
  551.  
  552.                 var url_split = url.split("/");
  553.  
  554.                 insertText("[A href=\"" + url + "\"]" + url_split[url_split.length - 1] + "[/A]", true);
  555.             }
  556.  
  557.             function insertPostID() {
  558.                 var id = prompt("Paste post id here");
  559.                 if (id == null || id == undefined || id.length == 0 || !(/[0-9]/g.test(id)))
  560.                     return;
  561.  
  562.                 insertText('[A href="/st?a=pid&id=' + id + '"]#' + id + '[/A]', true);
  563.             }
  564.  
  565.             function uploadFile() {
  566.                 if (!window.storage.can_send)
  567.                     alert("Wait till file will be uploaded");
  568.  
  569.                 pickAndUploadFile("*", function() {
  570.                     console.log("shit");
  571.                     document.getElementById("upload-status").innerHTML = "uploaded";
  572.  
  573.                     var url_split = window.storage.lastUpload.split("=");
  574.                     url_split = url_split[url_split.length - 1].split("/");
  575.                     url_split = url_split[url_split.length - 1];
  576.                     insertText("[A href=\"/fs?f=/u/" + url_split + "\"]" + url_split + "[/A]", true);
  577.                 });
  578.             }
  579.  
  580.             function uploadImage() {
  581.                 if (!window.storage.can_send)
  582.                     alert("Wait till file will be uploaded");
  583.  
  584.                 pickAndUploadFile("image/jpeg,image/png,image/gif", function() {
  585.                     console.log("shit");
  586.                     document.getElementById("upload-status").innerHTML = "uploaded";
  587.  
  588.                     var url_split = window.storage.lastUpload.split("=");
  589.                     url_split = url_split[url_split.length - 1].split("/");
  590.                     url_split = url_split[url_split.length - 1];
  591.                     insertText("[IMG width=300 src=\"/fs?f=/u/" + url_split + "\" alt=\"" + url_split + "\"]", true);
  592.                 });
  593.             }
  594.  
  595.             function pickAndUploadFile(mime_type, success) {
  596.                 if (!window.storage.can_send)
  597.                     alert("Wait till file will be uploaded");
  598.  
  599.                 document.getElementById("input_file").accept = mime_type;
  600.                 document.getElementById("input_file").onchange = function() {
  601.                     if (this.value == null || this.value == undefined || this.value == "")
  602.                         return;
  603.  
  604.                     if (this.value.size / 1024 / 1024 > 24)
  605.                         alert("File too large");
  606.  
  607.                     var xhr = new XMLHttpRequest();
  608.  
  609.                     var file = document.getElementById("input_file").files[0];
  610.                     var fileName = this.value;
  611.                     var target = "/fs?u=" + randomString(40) + "." + fileName.substring(fileName.indexOf('.') + 1, fileName.length) || fileName;
  612.                     window.storage.lastUpload = target;
  613.                     var mimeType = "application/x-www-form-urlencoded";
  614.  
  615.                     window.storage.can_send = false;
  616.                     xhr.open('POST', target, true);
  617.                     xhr.setRequestHeader('Content-Type', mimeType);
  618.                     xhr.setRequestHeader('Content-Disposition', 'attachment; filename="' + encodeURIComponent(fileName) + '"');
  619.                     xhr.upload.onprogress = function(event) {
  620.                         window.storage.can_send = event.loaded >= event.total;
  621.                         if (event.loaded < event.total)
  622.                            document.getElementById("upload-status").innerHTML = (event.loaded / event.total * 100) + "%";
  623.                    };
  624.                    xhr.onload = function() {
  625.                        window.storage.can_send = true;
  626.                        if (this.status == 200)
  627.                            success(this, fileName);
  628.                        else
  629.                            document.getElementById("upload-status").innerHTML = "error " + this.status;
  630.                    }
  631.                    xhr.onerror = function() {
  632.                        document.getElementById("upload-status").innerHTML = "error " + this.status;
  633.                    };
  634.                    window.storage.can_send = false;
  635.                    xhr.send(file);
  636.                };
  637.                document.getElementById("input_file").click();
  638.            }
  639.  
  640.            function randomString(size) {
  641.                var text = "";
  642.                var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
  643.  
  644.                for (var i = 0; i < size; i++)
  645.                    text += possible.charAt(Math.floor(Math.random() * possible.length));
  646.  
  647.                return text;
  648.            }
  649.  
  650.            function insert(block) {
  651.                insertText("[" + block + "]", true);
  652.                insertText("[/" + block + "]", false);
  653.            }
  654.  
  655.            function insertText(text, moveToEnd) {
  656.                var textfield = document.getElementById("post-text");
  657.  
  658.                var cursor = textfield.selectionStart;
  659.                var left = textfield.value.substr(0, cursor);
  660.                var right = textfield.value.substr(cursor, textfield.value.length - cursor);
  661.  
  662.  
  663.                textfield.value = left + text + right;
  664.                textfield.focus();
  665.  
  666.                if (moveToEnd) {
  667.                    textfield.selectionStart = cursor + text.length;
  668.                    textfield.selectionEnd = cursor + text.length;
  669.                } else {
  670.                    textfield.selectionStart = cursor;
  671.                    textfield.selectionEnd = cursor;
  672.                }
  673.            }
  674.  
  675.        </script>
  676.         <div style="border: 1px solid black; width: 100%">
  677.             <div class="insert" onclick="insertImage()">+ IMAGE</div>
  678.             <div class="insert" onclick="insertVideo()">+ VIDEO</div>
  679.             <div class="insert" onclick="insertYoutube()">+ YOUTUBE</div>
  680.             <div class="insert" onclick="insertCoub()">+ COUB</div>
  681.             <div class="insert" onclick="insertAudio()">+ AUDIO</div>
  682.             <div class="insert" onclick="insertIFrame()">+ FRAME</div>
  683.             <div class="insert" onclick="insertURL()">+ URL</div>
  684.             <div class="insert" onclick="uploadFile()">UPLOAD FILE</div>
  685.             <div class="insert" onclick="uploadImage()">UPLOAD IMAGE</div>
  686.             <div class="insert" onclick="insertPostID()">+ POST ID</div>
  687.             <div class="insert" onclick="insert('DIV')">+ DIV</div>
  688.             <div class="insert" onclick="insert('B')">+ BOLD</div>
  689.             <div class="insert" onclick="insert('I')">+ ITALIC</div>
  690.             <div class="insert" onclick="insert('U')">+ UNDERLINE</div>
  691.             <div class="insert" onclick="insert('H1')">+ H1</div>
  692.             <div class="insert" onclick="insert('H2')">+ H2</div>
  693.             <div class="insert" onclick="insert('H3')">+ H3</div>
  694.             <div class="insert" onclick="insert('H4')">+ H4</div>
  695.             <div class="insert" onclick="insert('H5')">+ H5</div>
  696.             <div class="insert" onclick="insert('H6')">+ H6</div>
  697.             <div class="insert" onclick="uploadFile">+ H6</div>
  698.             <div id="upload-status"></div>
  699.             <input type="file" style="display: none" id="input_file">
  700.         </div>
  701.         <textarea id="post-text" style="width:100%; height:10rem"></textarea>
  702.         <div align="right"><input type="button" value="submit" id="post-send"></div>
  703.         <script type="text/javascript">
  704.             (function() {
  705.                 var post_send = document.getElementById("post-send");
  706.                 post_send.onclick = function(event) {
  707.                     if (!window.storage.can_send)
  708.                         alert("Wait untill file load");
  709.                     var post_text = document.getElementById("post-text").value;
  710.  
  711.                     var xhr = new XMLHttpRequest;
  712.                     if (window.storage.edit_mode)
  713.                         xhr.open("GET", "/st?a=ep&id=" + window.storage.edit_id + "&m=" + encodeURIComponent(post_text) + "&token=" + getCookie("token"), false);
  714.                     else
  715.                         xhr.open("GET", "/st?a=wp&t=" + window.storage.branch + "&m=" + encodeURIComponent(post_text) + "&token=" + getCookie("token"), false);
  716.                     xhr.send();
  717.  
  718.                     if (xhr.status != 200)
  719.                         alert(xhr.responseText);
  720.                     else if (!event.ctrlKey)
  721.                         window.location = "/st?a=pid&id=" + xhr.responseText;
  722.                     else
  723.                         post_send.style.backgroundColor = "red";
  724.                 };
  725.             })();
  726.  
  727.         </script>
  728.     </div>
  729.     <br>
  730.     <div style="border: 1px solid black; display: inline-block; width: 100%" id="pages1"></div>
  731.     <script type="text/javascript">
  732.         (function() {
  733.             var elem0 = document.getElementById("pages0");
  734.             var elem1 = document.getElementById("pages1");
  735.             for (var i = 0; i < window.storage.page_count; i++) {
  736.                elem0.innerHTML += '<a href="st?t=' + window.storage.branch + '&p=' + i + '">' + i + '</a>';
  737.                 elem1.innerHTML += '<a href="st?t=' + window.storage.branch + '&p=' + i + '">' + i + '</a>';
  738.                 if (i < window.storage.page_count - 1) {
  739.                    elem0.innerHTML += ',&nbsp;';
  740.                    elem1.innerHTML += ',&nbsp;';
  741.                }
  742.            }
  743.        })();
  744.  
  745.    </script>
  746. </body>
  747.  
  748. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement