]> code.citadel.org Git - citadel.git/commitdiff
randomString() is now always the same length and always begins with "ctdl_"
authorArt Cancro <ajc@citadel.org>
Sat, 1 Jan 2022 20:31:31 +0000 (15:31 -0500)
committerArt Cancro <ajc@citadel.org>
Sat, 1 Jan 2022 20:31:31 +0000 (15:31 -0500)
webcit-ng/static/js/util.js
webcit-ng/static/js/view_forum.js

index b8d04fc35039bc3c90da33f044d74bc70e399887..5e80a898644d22976b9dab0e25c84aa9598a25ab 100644 (file)
@@ -46,17 +46,8 @@ function quoted_printable_encode(str) {
 
 // Generate a random string of the specified length
 // Useful for generating one-time-use div names
-function randomString(length) {
-       var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghiklmnopqrstuvwxyz'.split('');
-       var str = '';
-
-       if (!length) {
-               length = Math.floor(Math.random() * chars.length);
-       }
-       for (var i = 0; i < length; i++) {
-               str += chars[Math.floor(Math.random() * chars.length)];
-       }
-       return str;
+function randomString() {
+       return Math.random().toString(36).replace('0.','ctdl_' || '');
 }
 
 
index 2d8ea52ec7a9b6659d41e5a87ee8cff34fa89dbb..de3950ca8da83b9443254bb6c7c04af7932196e5 100644 (file)
@@ -41,7 +41,7 @@ function forum_readmessages(target_div_name, gt_msg, lt_msg) {
                                if (msgs.length > messages_per_page) {
                                        msgs = msgs.slice(msgs.length - messages_per_page);
                                }
-                               new_old_div_name = randomString(10);
+                               new_old_div_name = randomString();
                                if (msgs.length < 1) {
                                        newlt = lt_msg;
                                }
@@ -57,11 +57,11 @@ function forum_readmessages(target_div_name, gt_msg, lt_msg) {
                        }
 
                        // The messages will go here.
-                       let msgs_div_name = randomString(10);
+                       let msgs_div_name = randomString();
                        target_div.innerHTML += "<div id=\"" + msgs_div_name + "\"> </div>" ;
 
                        if (lt_msg == 9999999999) {
-                               new_new_div_name = randomString(10);
+                               new_new_div_name = randomString();
                                if (msgs.length <= 0) {
                                        newgt = gt_msg;
                                }
@@ -151,7 +151,7 @@ function forum_render_messages(message_numbers, msgs_div_name, scroll_to) {
 function forum_render_one(msg) {
 
        let div = document.createElement("div");
-       mdiv = randomString(10);                                        // div name for this message
+       mdiv = randomString();                                                  // div name for this message
        div.id = mdiv;
 
        try {
@@ -236,7 +236,7 @@ function compose_references(references, msgid) {
 // Open a reply box directly below a specific message
 function open_reply_box(parent_div, is_quoted, references, msgid) {
        let new_div = document.createElement("div");
-       let new_div_name = randomString(10);
+       let new_div_name = randomString();
        new_div.id = new_div_name;
 
        document.getElementById(parent_div).append(new_div);
@@ -374,7 +374,7 @@ function forum_save_message(editor_div_name) {
                + "/dummy_name_for_new_message"
                + "?wefw=" + wefw
                + "&subj=" + subj
-       boundary = randomString(20);
+       boundary = randomString();
        body_text =
                "--" + boundary + "\r\n"
                + "Content-type: text/html\r\n"