The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Optimizing the script

5 posters

Go down

Solved Optimizing the script

Post by BloodDrunk May 6th 2017, 10:14 pm

Technical Details


Forum version : #phpBB3
Position : Founder
Concerned browser(s) : Google Chrome
Who the problem concerns : All members
Forum link : http://www.nfssecrets.tk/

Description of problem

Hello,

Is anybody here interested in checking a jQuery code out, and if possible, optimize it?
It was in tutorials here, and it seems to work well, but starts to really lag the browser when writing the message (approaching 60+ messages).

Here's the code:
Code:
window.localStorage&&$(function(){
$(function(){
if($("#text_editor_textarea").length&&typeof $.sceditor!="undefined"){
var a=$(document.post.mode).val(),
d=$("#text_editor_textarea").sceditor("instance"),
e,f,g=function(){
localStorage.setItem(a,d.val());
f=0},
b=JSON.parse(localStorage.getItem("br-data"))||[],c;
switch(a){
case"editpost":return;
case"reply":a+=$(document.post.t).val();
break;
case"newtopic":a+=$(document.post.f).val()
}
a=parseInt((my_getcookie("fa_"+location.hostname.replace(/\./g,"_")+"_data")||"0").replace(/.*s:6:"userid";(i:([0-9]+)|s:[0-9]+:"([0-9]+)");.*/,"$2$3"))+a;
-1!=(c=$.inArray(a,b))&&b.splice(c,1);
if(20<b.length){
for(c=b.length-1;0<=c;c--)/^\s*$/.test(localStorage.getItem(b[c])||"")&&(localStorage.removeItem(b[c]),
b.splice(c,1));
20<b.length&&(localStorage.removeItem(b[0]),
b.splice(0,1))}b.push(a);
localStorage.setItem("br-data",JSON.stringify(b));
$(document.post).submit(function(){
localStorage.setItem("br-target",a)
});
!d.val()&&((e=localStorage.getItem(a))&&d.val(e));
d.keyDown(function(){
f||(f=setTimeout(g,3E3))
})}})});
window.localStorage&&(localStorage.getItem("br-target")&&function(){
$("meta[http-equiv='refresh'][content]:first").length&&function(){
var a=JSON.parse(localStorage.getItem("br-data")),
b=localStorage.getItem("br-target"),c;
if(-1!=(c=$.inArray(b,a)))a.splice(c,1),
localStorage.setItem("br-data",JSON.stringify(a));
localStorage.removeItem(b)}();
localStorage.removeItem("br-target")}());


Last edited by BloodDrunk on May 9th 2017, 5:48 pm; edited 1 time in total
BloodDrunk
BloodDrunk
Forumember

Posts : 127
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by zenzo May 6th 2017, 11:28 pm

can you link where you get this tutorial.
zenzo
zenzo
Forumember

Posts : 564
Reputation : 13
Language : english,tagalog
Location : philippines

Back to top Go down

Solved Re: Optimizing the script

Post by BloodDrunk May 7th 2017, 12:04 am

BloodDrunk
BloodDrunk
Forumember

Posts : 127
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by Draxion May 7th 2017, 1:49 am

Try this.
Code:
window.localStorage && $(function() {
    $(function() {
        if ($("#text_editor_textarea").length && typeof $.sceditor != "undefined") {
            var a = $(document.post.mode).val(),
                d = $("#text_editor_textarea").sceditor("instance"),
                e, f, g = function() {
                    localStorage.setItem(a, d.val());
                    f = 0
                },
                b = JSON.parse(localStorage.getItem("br-data")) || [],
                c;
            switch (a) {
                case "editpost":
                    return;
                case "reply":
                    a += $(document.post.t).val();
                    break;
                case "newtopic":
                    a += $(document.post.f).val()
            }
            a = parseInt((my_getcookie("fa_" + location.hostname.replace(/\./g, "_") + "_data") || "0").replace(/.*s:6:"userid";(i:([0-9]+)|s:[0-9]+:"([0-9]+)");.*/, "$2$3")) + a; -
            1 != (c = $.inArray(a, b)) && b.splice(c, 1);
            if (20 < b.length) {
                for (c = b.length - 1; 0 <= c; c--) /^\s*$/.test(localStorage.getItem(b[c]) || "") && (localStorage.removeItem(b[c]),
                    b.splice(c, 1));
                20 < b.length && (localStorage.removeItem(b[0]),
                    b.splice(0, 1))
            }
            b.push(a);
            localStorage.setItem("br-data", JSON.stringify(b));
            $(document.post).submit(function() {
                localStorage.setItem("br-target", a)
            });
            !d.val() && ((e = localStorage.getItem(a)) && d.val(e));
            d.keyDown(function() {
                f || (f = setTimeout(g, 3E3))
            })
        }
    })
});
window.localStorage && (localStorage.getItem("br-target") && function() {
    $("meta[http-equiv='refresh'][content]:first").length && function() {
        var a = JSON.parse(localStorage.getItem("br-data")),
            b = localStorage.getItem("br-target"),
            c;
        if (-1 != (c = $.inArray(b, a))) a.splice(c, 1),
            localStorage.setItem("br-data", JSON.stringify(a));
        localStorage.removeItem(b)
    }();
    localStorage.removeItem("br-target")
}());
Draxion
Draxion
Helper
Helper

Male Posts : 2518
Reputation : 321
Language : English
Location : USA

https://www.talesoftellene.com/

Back to top Go down

Solved Re: Optimizing the script

Post by BloodDrunk May 7th 2017, 11:56 am

Still starts to get laggy after 30 words..
BloodDrunk
BloodDrunk
Forumember

Posts : 127
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by SLGray May 7th 2017, 10:39 pm

Are you sure it is this code, not other things on your forum?


Optimizing the script Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51463
Reputation : 3519
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: Optimizing the script

Post by BloodDrunk May 7th 2017, 10:45 pm

SLGray wrote:Are you sure it is this code, not other things on your forum?

You know what, now when I tried disabling some other codes, it stopped lagging. Now it lags while having this following code:
Code:
$(function(){$(function(){
 
      var MinNumberOfWords = 1;
      var LetterCountPerWord = 4;
      var ico_compl = "http://i73.servimg.com/u/f73/18/10/89/49/ok-gre10.png";
      var ico_incompl = "http://i73.servimg.com/u/f73/18/10/89/49/exclam10.png"; 
 
    if($("#text_editor_textarea").length != 0){
          $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");     
          $(".sceditor-container").after("<br/><div id='div_minchars' align='center'><div id='div_minchars_header'> Minimum words to send a message: " + MinNumberOfWords + " (at least " + LetterCountPerWord + " letters)</div><div id='div_minchars_info'></div></div>");
         
          var sceditor = $("#text_editor_textarea").sceditor("instance");                 
          var str = sceditor.val();
          var regex = new RegExp('\\w{' + LetterCountPerWord + ',}\\b', 'g');
          var str_arr = str.match(regex);
          var str_len = str_arr == null ? 0 : str_arr.length;
         
          if(str_len >= MinNumberOfWords) $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
         
          sceditor.keyUp(function(e) {
            str = sceditor.val();
            str_arr = str.match(regex);
            str_len = str_arr == null ? 0 : str_arr.length;
            if(str_len >= MinNumberOfWords) {
                $("#div_minchars_info").html("You've written <span style='color:green'>" + str_len + "</span> word(s). You can now send the message <img src='" + ico_compl  + "' />"); 
            $("input[type='submit'][name='post']").attr("disabled", false).css("opacity", "1");
            }else{
                $("#div_minchars_info").html("You've written <span style='color:red'>" + str_len + "</span> word(s). You need " + (MinNumberOfWords - str_len) + " word(s) to send this message <img src='" + ico_incompl  + "' />");
                $("input[type='submit'][name='post']").attr("disabled", true).css("opacity", "0.5");
            }
          });
      }
    })});
BloodDrunk
BloodDrunk
Forumember

Posts : 127
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by BloodDrunk May 9th 2017, 5:48 pm

Nevermind, I removed that word counter.
You can archive this now. Solved!
BloodDrunk
BloodDrunk
Forumember

Posts : 127
Reputation : 4
Language : English

http://www.nfssecrets.tk/

Back to top Go down

Solved Re: Optimizing the script

Post by Ape May 9th 2017, 5:54 pm

Problem solved & topic archived.
Please read our forum rules:  ESF General Rules


Optimizing the script Left1212Optimizing the script Center11Optimizing the script Right112
Optimizing the script Ape_b110
Optimizing the script Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19084
Reputation : 1988
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum