Prefix Coding for Admin/Mod Only
3 posters
Page 1 of 1
Prefix Coding for Admin/Mod Only
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 of the admin/mod warning
Hope anyone can help me. thanks!
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
Re: Prefix Coding for Admin/Mod Only
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)
})
}
});
};
Guest- Guest
Re: Prefix Coding for Admin/Mod Only
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
Re: Prefix Coding for Admin/Mod Only
- 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.
Guest- Guest
Re: Prefix Coding for Admin/Mod Only
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
Re: Prefix Coding for Admin/Mod Only
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)
})
}
});
};
Guest- Guest
Re: Prefix Coding for Admin/Mod Only
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..
Re: Prefix Coding for Admin/Mod Only
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.
Guest- Guest
Re: Prefix Coding for Admin/Mod Only
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);
});
}
});
}
Re: Prefix Coding for Admin/Mod Only
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.
Re: Prefix Coding for Admin/Mod Only
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.
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.
Guest- Guest
Re: Prefix Coding for Admin/Mod Only
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
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.
Re: Prefix Coding for Admin/Mod Only
- 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:
|
Guest- Guest
Re: Prefix Coding for Admin/Mod Only
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
When posting it (There is no prefix appearing)
Creation of Topic
When posting it (There is no prefix appearing)
Re: Prefix Coding for Admin/Mod Only
By default there's no prefix selected, you have to click on the box saying prefix 1 and select something from it.
Guest- Guest
Re: Prefix Coding for Admin/Mod Only
I have selected prefix 1 and prefix 2 but still nothing happened. :'(
Re: Prefix Coding for Admin/Mod Only
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.
Guest- Guest
Re: Prefix Coding for Admin/Mod Only
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.
Re: Prefix Coding for Admin/Mod Only
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.
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)
})
}
});
});
Re: Prefix Coding for Admin/Mod Only
Topic solved & archived ~ brandon_g
|
Remember to mark your topic when a solution is found.
General Rules | Tips & Tricks | FAQ | Forgot Founder Password?
Team Leader
Review Section Rules | Request A Review | Sticker Points
Similar topics
» My prefix show only to Admin & Moderator, not guest & other member
» Add User to Admin to Help with Coding
» Coding Spot (FM-Coding Support)
» Topic Prefix:
» prefix to usernames
» Add User to Admin to Help with Coding
» Coding Spot (FM-Coding Support)
» Topic Prefix:
» prefix to usernames
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum