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.

Prefix Coding for Admin/Mod Only

3 posters

Go down

Solved Prefix Coding for Admin/Mod Only

Post by Babybok August 4th 2017, 11:33 am

Good day, So I have this problem if it is possible that the use of prefix is for Admin and Mod's only. Anyone can help or code me with this problem? cause I've this Admin/Mod Warning button that only Admin/Mod can use and I think my problem is possible also to code it for admin/mod only.


Here is the code.
Code:
var prefixes = ["Form", "In Progress", "Request", "Suggestion", "Notice", "Information", "Tutorial", "Guide"];
var _pm = false;
 
var chk = false;
function toMenu(a) {
  var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
  for (i in a)
  htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
  htmlpre += '</select>';
  return htmlpre;
}
 
function checkpre(ar, input) {
  for (i in ar) {
      var p = new RegExp("" + ar[i], "g");
      var title = input.substr(0, input.indexOf(']'));
      if (p.test(title)) return ar[i];
  }
  return "";
}
$(function () {
  if (_pm) chk = /\privmsg/.test(location.href);
  if (/\/post/.test(location.href) || chk) {
      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
      var mw = $("#prefix").width() + 5;
      $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
      var t = $("[name='subject']").val();
      var cur = checkpre(prefixes, t);
      if (cur != "") {
        $("[value=" + cur + "]").attr("selected", "selected");
        $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
      }
      $("input[name='post']").click(function () {
        var sub = $("input[name='subject']").val().trim();
        if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
      })
  }
});


code of the admin/mod warning

Code:
$(function() {
  var modButton = true, admButton = true,
  modImage = 'http://i39.servimg.com/u/f39/18/21/41/30/bouton11.png',
  admImage = 'http://i39.servimg.com/u/f39/18/21/41/30/bouton10.png';

  if (_userdata.user_level != 0 && modButton === true) {
    $("#text_editor_textarea").before("<img src='"+modImage+"' title='Moderator warning' id='mod-b'/>");
    $('#mod-b').click(function(){$('#text_editor_textarea').sceditor('instance').insertText('[mod]','[/mod]')});
  }
  if (_userdata.user_level === 1 && admButton === true) {
    $("#text_editor_textarea").before("<img src='"+admImage+"' title='Admin warning' id='adm-b'/>");
    $('#adm-b').click(function(){$('#text_editor_textarea').sceditor('instance').insertText('[adm]','[/adm]')});
  }
  $('div.postbody div').each(function () {
    if ($(this).text().indexOf('[adm]') != -1) $(this).html($(this).html().replace(/\[adm\](.+?)\[\/adm\]/gi, '<div class="adm_mess"><div class="titl">Administrator Warning</div><div>$1 </div></div>'));
    if ($(this).text().indexOf('[mod]') != -1) $(this).html($(this).html().replace(/\[mod\](.+?)\[\/mod\]/gi, '<div class="mod_mess"><div class="titl">Moderator Warning</div><div>$1 </div></div>'));
  }); 
});


Hope anyone can help me. thanks!


Last edited by Babybok on August 10th 2017, 11:32 am; edited 1 time in total
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Guest August 4th 2017, 4:09 pm

Use this code:
Code:
 if(!_userdata. user_level){      var prefixes = ["Form", "In Progress", "Request", "Suggestion", "Notice", "Information", "Tutorial", "Guide"];
        var _pm = false;
       
        var chk = false;
        function toMenu(a) {
          var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
          for (i in a)
          htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
          htmlpre += '</select>';
          return htmlpre;
        }
       
        function checkpre(ar, input) {
          for (i in ar) {
              var p = new RegExp("" + ar[i], "g");
              var title = input.substr(0, input.indexOf(']'));
              if (p.test(title)) return ar[i];
          }
          return "";
        }
        $(function () {
          if (_pm) chk = /\privmsg/.test(location.href);
          if (/\/post/.test(location.href) || chk) {
              $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
              var mw = $("#prefix").width() + 5;
              $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
              var t = $("[name='subject']").val();
              var cur = checkpre(prefixes, t);
              if (cur != "") {
                $("[value=" + cur + "]").attr("selected", "selected");
                $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
              }
              $("input[name='post']").click(function () {
                var sub = $("input[name='subject']").val().trim();
                if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
              })
          }
        });
};
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 5th 2017, 6:56 am

Wolfuryo wrote:Use this code:
Code:
 if(!_userdata. user_level){      var prefixes = ["Form", "In Progress", "Request", "Suggestion", "Notice", "Information", "Tutorial", "Guide"];
        var _pm = false;
       
        var chk = false;
        function toMenu(a) {
          var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
          for (i in a)
          htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
          htmlpre += '</select>';
          return htmlpre;
        }
       
        function checkpre(ar, input) {
          for (i in ar) {
              var p = new RegExp("" + ar[i], "g");
              var title = input.substr(0, input.indexOf(']'));
              if (p.test(title)) return ar[i];
          }
          return "";
        }
        $(function () {
          if (_pm) chk = /\privmsg/.test(location.href);
          if (/\/post/.test(location.href) || chk) {
              $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
              var mw = $("#prefix").width() + 5;
              $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
              var t = $("[name='subject']").val();
              var cur = checkpre(prefixes, t);
              if (cur != "") {
                $("[value=" + cur + "]").attr("selected", "selected");
                $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
              }
              $("input[name='post']").click(function () {
                var sub = $("input[name='subject']").val().trim();
                if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
              })
          }
        });
};

Hello good day, thanks for the fast reply, but when I replace this code to the code that I have in my Javascript section it didn't worked, the prefix was gone as well as the prefix css. @Wolfuryo
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Guest August 5th 2017, 7:36 am

Code:
        if(_userdata. user_level){      var prefixes = ["Form", "In Progress", "Request", "Suggestion", "Notice", "Information", "Tutorial", "Guide"];
                var _pm = false;
             
                var chk = false;
                function toMenu(a) {
                  var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
                  for (i in a)
                  htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
                  htmlpre += '</select>';
                  return htmlpre;
                }
             
                function checkpre(ar, input) {
                  for (i in ar) {
                      var p = new RegExp("" + ar[i], "g");
                      var title = input.substr(0, input.indexOf(']'));
                      if (p.test(title)) return ar[i];
                  }
                  return "";
                }
                $(function () {
                  if (_pm) chk = /\privmsg/.test(location.href);
                  if (/\/post/.test(location.href) || chk) {
                      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
                      var mw = $("#prefix").width() + 5;
                      $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
                      var t = $("[name='subject']").val();
                      var cur = checkpre(prefixes, t);
                      if (cur != "") {
                        $("[value=" + cur + "]").attr("selected", "selected");
                        $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
                      }
                      $("input[name='post']").click(function () {
                        var sub = $("input[name='subject']").val().trim();
                        if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
                      })
                  }
                });
        };

Made a small mistake in the code. See if this works.
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 5th 2017, 8:11 am

Wolfuryo wrote:
Code:
        if(_userdata. user_level){      var prefixes = ["Form", "In Progress", "Request", "Suggestion", "Notice", "Information", "Tutorial", "Guide"];
                var _pm = false;
             
                var chk = false;
                function toMenu(a) {
                  var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
                  for (i in a)
                  htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
                  htmlpre += '</select>';
                  return htmlpre;
                }
             
                function checkpre(ar, input) {
                  for (i in ar) {
                      var p = new RegExp("" + ar[i], "g");
                      var title = input.substr(0, input.indexOf(']'));
                      if (p.test(title)) return ar[i];
                  }
                  return "";
                }
                $(function () {
                  if (_pm) chk = /\privmsg/.test(location.href);
                  if (/\/post/.test(location.href) || chk) {
                      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
                      var mw = $("#prefix").width() + 5;
                      $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
                      var t = $("[name='subject']").val();
                      var cur = checkpre(prefixes, t);
                      if (cur != "") {
                        $("[value=" + cur + "]").attr("selected", "selected");
                        $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
                      }
                      $("input[name='post']").click(function () {
                        var sub = $("input[name='subject']").val().trim();
                        if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
                      })
                  }
                });
        };

Made a small mistake in the code. See if this works.

Still not working :'(

Anyways here my forum address : forums.mo-rpg.com
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Guest August 5th 2017, 9:53 am

Try this. There was an extra space in the code.
Code:
 if(_userdata.user_level){      var prefixes = ["Form", "In Progress", "Request", "Suggestion", "Notice", "Information", "Tutorial", "Guide"];
                var _pm = false;
           
                var chk = false;
                function toMenu(a) {
                  var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
                  for (i in a)
                  htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
                  htmlpre += '</select>';
                  return htmlpre;
                }
           
                function checkpre(ar, input) {
                  for (i in ar) {
                      var p = new RegExp("" + ar[i], "g");
                      var title = input.substr(0, input.indexOf(']'));
                      if (p.test(title)) return ar[i];
                  }
                  return "";
                }
                $(function () {
                  if (_pm) chk = /\privmsg/.test(location.href);
                  if (/\/post/.test(location.href) || chk) {
                      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
                      var mw = $("#prefix").width() + 5;
                      $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
                      var t = $("[name='subject']").val();
                      var cur = checkpre(prefixes, t);
                      if (cur != "") {
                        $("[value=" + cur + "]").attr("selected", "selected");
                        $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
                      }
                      $("input[name='post']").click(function () {
                        var sub = $("input[name='subject']").val().trim();
                        if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
                      })
                  }
                });
        };
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 5th 2017, 10:37 am

Wolfuryo wrote:Try this. There was an extra space in the code.
Code:
 if(_userdata.user_level){      var prefixes = ["Form", "In Progress", "Request", "Suggestion", "Notice", "Information", "Tutorial", "Guide"];
                var _pm = false;
           
                var chk = false;
                function toMenu(a) {
                  var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
                  for (i in a)
                  htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
                  htmlpre += '</select>';
                  return htmlpre;
                }
           
                function checkpre(ar, input) {
                  for (i in ar) {
                      var p = new RegExp("" + ar[i], "g");
                      var title = input.substr(0, input.indexOf(']'));
                      if (p.test(title)) return ar[i];
                  }
                  return "";
                }
                $(function () {
                  if (_pm) chk = /\privmsg/.test(location.href);
                  if (/\/post/.test(location.href) || chk) {
                      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
                      var mw = $("#prefix").width() + 5;
                      $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
                      var t = $("[name='subject']").val();
                      var cur = checkpre(prefixes, t);
                      if (cur != "") {
                        $("[value=" + cur + "]").attr("selected", "selected");
                        $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
                      }
                      $("input[name='post']").click(function () {
                        var sub = $("input[name='subject']").val().trim();
                        if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
                      })
                  }
                });
        };

Hello thanks for your help but the code you gave still not working.. Sad
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Guest August 5th 2017, 12:09 pm

So, what do you exactly want? If you want the code to only be executed for mods and admins, than that's exactly what the code I gave you does.
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Draxion August 5th 2017, 4:25 pm

Why not try this?
Code:
if (_userdata["user_level"] == 1 || _userdata["user_level"] == 2) {
  var prefixes = [
    "Form",
    "In Progress",
    "Request",
    "Suggestion",
    "Notice",
    "Information",
    "Tutorial",
    "Guide"
  ];
  var _pm = false;

  var chk = false;
  function toMenu(a) {
    var htmlpre =
      '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
    for (i in a)
      htmlpre += '<option value="' + a[i] + '">' + a[i] + "</option>";
    htmlpre += "</select>";
    return htmlpre;
  }

  function checkpre(ar, input) {
    for (i in ar) {
      var p = new RegExp("" + ar[i], "g");
      var title = input.substr(0, input.indexOf("]"));
      if (p.test(title)) return ar[i];
    }
    return "";
  }
  $(function() {
    if (_pm) chk = /\privmsg/.test(location.href);
    if (/\/post/.test(location.href) || chk) {
      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
      var mw = $("#prefix").width() + 5;
      $("input[name='subject']").css(
        "width",
        $("input[name='subject']").width() - mw
      );
      var t = $("[name='subject']").val();
      var cur = checkpre(prefixes, t);
      if (cur != "") {
        $("[value=" + cur + "]").attr("selected", "selected");
        $("input[name='subject']").val(t.replace("[" + cur + "]", "").trim());
      }
      $("input[name='post']").click(function() {
        var sub = $("input[name='subject']").val().trim();
        if (sub != "" && $("#prefix").val() != "")
          $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub);
      });
    }
  });
}
Draxion
Draxion
Helper
Helper

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

https://www.talesoftellene.com/

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 5th 2017, 10:46 pm

Wolfuryo wrote:So, what do you exactly want? If you want the code to only be executed for mods and admins, than that's exactly what the code I gave you does.

yeah I want mod and admins only to use the prefix, but it does not support in my forum.
I've tried it many times, but it still doesn't work and some of my javascript have been disabled with that code.

Draxion wrote:Why not try this?
Code:
if (_userdata["user_level"] == 1 || _userdata["user_level"] == 2) {
  var prefixes = [
    "Form",
    "In Progress",
    "Request",
    "Suggestion",
    "Notice",
    "Information",
    "Tutorial",
    "Guide"
  ];
  var _pm = false;

  var chk = false;
  function toMenu(a) {
    var htmlpre =
      '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
    for (i in a)
      htmlpre += '<option value="' + a[i] + '">' + a[i] + "</option>";
    htmlpre += "</select>";
    return htmlpre;
  }

  function checkpre(ar, input) {
    for (i in ar) {
      var p = new RegExp("" + ar[i], "g");
      var title = input.substr(0, input.indexOf("]"));
      if (p.test(title)) return ar[i];
    }
    return "";
  }
  $(function() {
    if (_pm) chk = /\privmsg/.test(location.href);
    if (/\/post/.test(location.href) || chk) {
      $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
      var mw = $("#prefix").width() + 5;
      $("input[name='subject']").css(
        "width",
        $("input[name='subject']").width() - mw
      );
      var t = $("[name='subject']").val();
      var cur = checkpre(prefixes, t);
      if (cur != "") {
        $("[value=" + cur + "]").attr("selected", "selected");
        $("input[name='subject']").val(t.replace("[" + cur + "]", "").trim());
      }
      $("input[name='post']").click(function() {
        var sub = $("input[name='subject']").val().trim();
        if (sub != "" && $("#prefix").val() != "")
          $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub);
      });
    }
  });
}

Thanks for this code, but still doesn't support in my forum

anyways, my forum is Invision.
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 7th 2017, 5:48 am

Bump! Even in my PHPBB2 forum the code doesn't work.. help please @Draxion @Wolfuryo
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Guest August 7th 2017, 2:40 pm

Hi again,

I'm not the author of those scripts so I have no idea why they don't work. I could look through them to find the error, but it would be easier for me if I create a code from scratch. Just to clarify, the code should add a list of prefixes in the topic posting page. When the user clicks one of them, the prefix is inserted in the title of the post, right? I'll wait for you answer than I'll start working on the code.
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 7th 2017, 3:06 pm

Wolfuryo wrote:Hi again,

I'm not the author of those scripts so I have no idea why they don't work. I could look through them to find the error, but it would be easier for me if I create a code from scratch. Just to clarify, the code should add a list of prefixes in the topic posting page. When the user clicks one of them, the prefix is inserted in the title of the post, right? I'll wait for you answer than I'll start working on the code.

Yes sir, you are correct but only MODS/ADMINS can use it. Here is what I have now in my forum
Prefix Coding for Admin/Mod Only Ryps47X

I hope that will be the same when you code it from scratch. thank you very much sir, I appreciated your fast reply and help.
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 8th 2017, 3:30 pm

Bumo! @Wolfuryo
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Guest August 9th 2017, 6:34 am

Code:
$(function(){
/*Coded by Wolfuryo. Use at your own risk. This notice must be kept in place*/
var prefixes=["prefix1", "prefix2"];
if(/post/.test(location.pathname) && $("label:contains('Title of the topic')") && _userdata.user_level){
var t=$(".posting-subject"), h="", len=prefixes.length, i=0;
for(i;i<len;i++){
h+="<option>"+prefixes[i]+"</option>";
}
h="<select id='pref'>"+h+"</select>";
t.after(h);
$("#pref>option").click(function(){
var t=$(".posting-subject");
if(/\[.+\]/.test(t.val())){
t.val(t.val().replace(/\[.+\]/, "["+this.innerHTML+"]"));
} else {
t.val("["+this.innerHTML+"]"+t.val());
}
})
}
})

To add or edit prefixes, you have to do modifications here:
Code:
var prefixes=["prefix1", "prefix2"];
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 9th 2017, 7:10 am

Hi, good day @Wolfuryo Thanks for the help, I appreciate it. but it is still not working, yeah it is working in the creation of topic but when you post it the prefix doesn't appear

Creation of Topic
Prefix Coding for Admin/Mod Only PXvIUfz

When posting it (There is no prefix appearing)
Prefix Coding for Admin/Mod Only VUZUGtb

Prefix Coding for Admin/Mod Only 9iok2EX
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Guest August 9th 2017, 7:24 am

By default there's no prefix selected, you have to click on the box saying prefix 1 and select something from it.
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 9th 2017, 7:30 am

I have selected prefix 1 and prefix 2 but still nothing happened. :'(
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Guest August 9th 2017, 7:40 am

I tested on your forum and my code is working. Delete all the other codes that have to do with prefixes, there's no need for 3 codes that try to do the same thing and all of them failing.
avatar
Guest
Guest


Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 9th 2017, 8:02 am

Wolfuryo wrote:I tested on your forum and my code is working. Delete all the other codes that have to do with prefixes, there's no need for 3 codes that try to do the same thing and all of them failing.

I have no other prefix codes, just the css and 1 js to support the CSS Code and the code you gave.
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by Babybok August 10th 2017, 11:30 am

Oh I think this is solved, I've added a code in the previous code I got' copying from the code of admin/mod warning. So I think yeah this is done already. Thanks to @Wolfuryo for the help and idea and also to @Draxion for the contribute! cheers mates!


This is the code I've used.
Code:
$(function(){   
     if (_userdata.user_level) {
   var prefixes = ["Prefix1", "Prefix2"];
     var _pm = false;
   var chk = false;
      function toMenu(a) {
        var htmlpre = '<select style="margin-right:5px" id="prefix" size="1"><option value="">(None)</option>';
        for (i in a)
        htmlpre += '<option value="' + a[i] + '">' + a[i] + '</option>';
        htmlpre += '</select>';
        return htmlpre;
      }
        }
    
   function checkpre(ar, input) {
     for (i in ar) {
         var p = new RegExp("" + ar[i], "g");
         var title = input.substr(0, input.indexOf(']'));
         if (p.test(title)) return ar[i];
     }
     return "";
   }
   $(function () {
     if (_pm) chk = /\privmsg/.test(location.href);
     if (/\/post/.test(location.href) || chk) {
         $(toMenu(prefixes)).insertBefore("input[name='subject'][type='text']");
         var mw = $("#prefix").width() + 5;
         $("input[name='subject']").css("width", $("input[name='subject']").width() - mw);
         var t = $("[name='subject']").val();
         var cur = checkpre(prefixes, t);
         if (cur != "") {
           $("[value=" + cur + "]").attr("selected", "selected");
           $("input[name='subject']").val(t.replace('[' + cur + ']', '').trim())
         }
         $("input[name='post']").click(function () {
           var sub = $("input[name='subject']").val().trim();
           if (sub != "" && $("#prefix").val() != "") $("input[name='subject']").val("[" + $("#prefix").val() + "] " + sub)
         })
     }
   });
});
Babybok
Babybok
Forumember

Male Posts : 199
Reputation : 2
Language : Filipino, English
Location : Philippines

http://rl-rp.board.st

Back to top Go down

Solved Re: Prefix Coding for Admin/Mod Only

Post by brandon_g August 10th 2017, 1:26 pm

Topic solved & archived ~ brandon_g
Please read our forum rules: ESF General Rules


Prefix Coding for Admin/Mod Only Brando10
Remember to mark your topic Prefix Coding for Admin/Mod Only Solved15 when a solution is found.
General Rules | Tips & Tricks | FAQ | Forgot Founder Password?

Prefix Coding for Admin/Mod Only Scre1476
Team Leader
Review Section Rules | Request A Review | Sticker Points
brandon_g
brandon_g
Manager
Manager

Male Posts : 10113
Reputation : 923
Language : English
Location : USA

https://www.broadcastingduo.com

Back to top Go down

Back to top

- Similar topics

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