Latest topics
» Forumactif Edge - Releases
by Ange Tuteur Tue 03 Sep 2019, 11:49
» GIFActif - Giphy Button for the Editor
by Ange Tuteur Wed 08 May 2019, 17:21
» Forum Closure
by Ange Tuteur Mon 01 Jan 2018, 01:28
» Chit Chat Thread
by Valoish Sun 31 Dec 2017, 19:15
» Font/Text background color.
by Valoish Sun 31 Dec 2017, 19:11
» Forumactif Messenger - Instant Message Application for Forumotion
by Wolfuryo Sun 31 Dec 2017, 18:24
» [GAME] Count to One Million!
by brandon_g Fri 29 Dec 2017, 18:58
» Post Cards
by manikbiradar Wed 20 Dec 2017, 07:50
» [GAME] Countdown from 200,000
by Valoish Wed 13 Dec 2017, 23:22
» GeekPolice Tech Support Forums - GeekPolice.net
by Dr Jay Mon 11 Dec 2017, 19:12
» Asking about some plugin for Forumotion
by Dr Jay Mon 11 Dec 2017, 19:10
» [GAME] What are you thinking right now?
by Van-Helsing Sat 09 Dec 2017, 14:51
» Widget : Similar topics
by ranbac Wed 06 Dec 2017, 18:11
» Change the Background of the Forum and put an image and how to make prefixs?
by Clement Wed 06 Dec 2017, 15:19
» Hello from Western Australia
by SarkZKalie Wed 06 Dec 2017, 05:34
by Ange Tuteur Tue 03 Sep 2019, 11:49
» GIFActif - Giphy Button for the Editor
by Ange Tuteur Wed 08 May 2019, 17:21
» Forum Closure
by Ange Tuteur Mon 01 Jan 2018, 01:28
» Chit Chat Thread
by Valoish Sun 31 Dec 2017, 19:15
» Font/Text background color.
by Valoish Sun 31 Dec 2017, 19:11
» Forumactif Messenger - Instant Message Application for Forumotion
by Wolfuryo Sun 31 Dec 2017, 18:24
» [GAME] Count to One Million!
by brandon_g Fri 29 Dec 2017, 18:58
» Post Cards
by manikbiradar Wed 20 Dec 2017, 07:50
» [GAME] Countdown from 200,000
by Valoish Wed 13 Dec 2017, 23:22
» GeekPolice Tech Support Forums - GeekPolice.net
by Dr Jay Mon 11 Dec 2017, 19:12
» Asking about some plugin for Forumotion
by Dr Jay Mon 11 Dec 2017, 19:10
» [GAME] What are you thinking right now?
by Van-Helsing Sat 09 Dec 2017, 14:51
» Widget : Similar topics
by ranbac Wed 06 Dec 2017, 18:11
» Change the Background of the Forum and put an image and how to make prefixs?
by Clement Wed 06 Dec 2017, 15:19
» Hello from Western Australia
by SarkZKalie Wed 06 Dec 2017, 05:34
Recent Tutorials
Top posting users this month
Top Achievers
Who is online?
In total there are 57 users online :: 0 Registered, 0 Hidden and 57 Guests :: 2 Bots
None
Most users ever online was 515 on Tue 14 Sep 2021, 15:24
None
Most users ever online was 515 on Tue 14 Sep 2021, 15:24
_userdata.usergroup
Page 1 of 2 • Share
Page 1 of 2 • 1, 2
With this plugin, the variable
is now accessible on any forum version (including FAE).
Administration Panel > Modules > HTML & Javascript > Javascript codes management > Create new javascript
Title: _userdata.usergroup
Placement: In all the pages
Code:
Note: This is not optimized for special moderation privileges. It is not secure. If you want a javascript that is, then just leave a comment below.
I think the modifications are pretty self-explanatory. If anyone has an issue, then feel free to leave a reply on this thread.
Group IDs
is the order of group IDs on your forum,
having the highest priority and
having the lowest.
Cache Time
is the amount of minutes your browser will store the usergroup number.
New! Multiple Groups Option
, all usergroups that a user is in will be searched for and stored, as opposed to just the highest usergroup. If you don't care about lower usergroups that a user is in, then leave this as is.
You're probably wondering how this would be useful. With this plugin comes two new functions. One that can return the group(s) that the user is in (depending on what
is set to) and another that can check if the user is in the group(s) passed into the function.
New! returnGroups
New! checkGroups
Let's put these to use. For example, if you are using FAE and wanted to change the background for all Administrator group members when they visit the forum, you would add the following JavaScript:
Since, on any Forumotion forum, the administrator group ID will always be
.
Also, these are some key numbers that you should know if you use this plugin.
When
is:
, the user is not logged in
, the user is not in any group
I hope you guys like it
|
Installation
Administration Panel > Modules > HTML & Javascript > Javascript codes management > Create new javascript
Title: _userdata.usergroup
Placement: In all the pages
Code:
- Code:
$(function() {
'_userdata.usergroup ️ 2017 Version 5.0';
'Developed by Ace 1';
'All rights reserved';
window.faGroups = {
groupIDs: [1, 2, 3], // list of groupIDs
cacheTime: 30, // time in minutes to store data
multipleGroups: false, // enable to return all groups the user is in
storage: window.localStorage,
user_id: _userdata.session_logged_in ? _userdata.user_id : 0,
setGroup: function() {
var group,
i = 0, j;
if (faGroups.storage && faGroups.user_id > 0) {
if (!faGroups.storage['ug' + faGroups.user_id] || !(faGroups.storage['ug' + faGroups.user_id + '_exp'] > new Date().getTime() - faGroups.cacheTime * 60 * 1000)) {
$.ajax({
url: '/groups',
type: 'get',
async: false,
success: function(d) {
if (faGroups.multipleGroups) group = [];
for (; i < faGroups.groupIDs.length; i++) {
j = $('ul.noList a[href^="/g' + faGroups.groupIDs[i] + '-', d);
if (j[0]) {
if (!faGroups.multipleGroups) {
group = faGroups.groupIDs[i];
i = faGroups.groupIDs.length;
} else {
group.push(faGroups.groupIDs[i]);
}
}
}
faGroups.storage['ug' + faGroups.user_id] = group ? JSON.stringify(group) : group;
faGroups.storage['ug' + faGroups.user_id + '_exp'] = new Date().getTime();
}
});
}
// sets _userdata.usergroup to the user's current group
if (faGroups.storage['ug' + faGroups.user_id] != 'undefined') {
try {
_userdata.usergroup = JSON.parse(faGroups.storage['ug' + faGroups.user_id]);
} catch(e) {
_userdata.usergroup = faGroups.storage['ug' + faGroups.user_id];
}
} else {
_userdata.usergroup = -1; // user not within any group
}
} else {
_userdata.usergroup = 0; // _userdata.session_logged_in == 0
}
},
returnGroups: function() {
if (!_userdata.usergroup) return;
return JSON.parse(faGroups.storage['ug' + faGroups.user_id]);
},
checkGroups: function() {
var groups_to_check = [].slice.apply(arguments),
user_groups,
in_groups;
if (groups_to_check.length < 1 || !_userdata.usergroup) return;
user_groups = _userdata.usergroup;
if (typeof user_groups == 'object') {
// usergroup == array
if (groups_to_check.length > 1) {
// arguments == array
in_groups = user_groups.every(function(val) {
return groups_to_check.indexOf(val) > -1;
});
return in_groups ? true : false;
} else {
// arguments == string
return user_groups.indexOf(groups_to_check[0]) > -1 ? true : false;
}
} else {
// usergroup == string
if (groups_to_check.length > 1) {
// arguments == array
return false;
} else {
// arguments == string
return groups_to_check[0] == user_groups ? true : false;
}
}
}
};
faGroups.setGroup();
/*** Progress
var logs = {
'Version 1.0': 'Developed',
'Version 2.0': 'Enabled values -1 and 0 (no groups and not logged in, respectively)',
'Version 3.0': 'Enhanced and simplified',
'Version 4.0': 'Enabled multipleGroups, returnGroups(), checkGroups(args)'
'Version 5.0': 'Patched unexpected tokens in JSON as well as errors when _userdata.session_logged_in == 0'
};
***/
});
Note: This is not optimized for special moderation privileges. It is not secure. If you want a javascript that is, then just leave a comment below.
Modifications
I think the modifications are pretty self-explanatory. If anyone has an issue, then feel free to leave a reply on this thread.
Group IDs
- Code:
groupIDs: [ 1, 2, 3 ],
|
|
|
Cache Time
- Code:
cacheTime: 30,
|
New! Multiple Groups Option
- Code:
multipleGroups: false,
|
Use
You're probably wondering how this would be useful. With this plugin comes two new functions. One that can return the group(s) that the user is in (depending on what
|
New! returnGroups
- Code:
faGroups.returnGroups();
// will return a number or an array
New! checkGroups
- Code:
faGroups.checkGroups(1);
faGroups.checkGroups(1, 2, ...);
// will return true or false
Let's put these to use. For example, if you are using FAE and wanted to change the background for all Administrator group members when they visit the forum, you would add the following JavaScript:
- Code:
$(function() {
faGroups.checkGroups(1) && $('#fa_edge').css('background-color', 'black');
});
Since, on any Forumotion forum, the administrator group ID will always be
|
Also, these are some key numbers that you should know if you use this plugin.
When
|
|
|
I hope you guys like it
Last edited by Ace 1 on Fri 06 Oct 2017, 09:53; edited 17 times in total
@Ace 1 nice utility ! This'll definitely make it easier for people who want to identify what group a user is in. I remember a few people asked for something like this in the past -- showing something specific for certain groups.
Keep it up
Keep it up
- STBW
- Gender :
Posts : 33
Points : 3587
Reputation : 2
Language : Spanish
Browser : Forum Version :
I cannot achieve to make it work. Is supposed that I can put any ID of a group on this part no? (the zone colored with red)
if ( _userdata.usergroup == 1 )
Or it only works for Admin Id? Because when I put 1 it works.. but with any other ID (98 for example) it does not!
if ( _userdata.usergroup == 1 )
Or it only works for Admin Id? Because when I put 1 it works.. but with any other ID (98 for example) it does not!
@STBW I think I could've been a tad more specific when I explained it. The red number in your post is supposed to be the group ID.
https://fmdesign.forumotion.com/g2-administrators
So with the following Javascript:
That code will be executed for Ange Tuteur and Leah7.
https://fmdesign.forumotion.com/g2-administrators
http::::fmdesign.forumotion.com/g2-administrators |
So with the following Javascript:
- Code:
$(function() {
if ( _userdata.usergroup == 2 ) {
// code to execute for administrators
console.log('Hi Admin.');
}
});
That code will be executed for Ange Tuteur and Leah7.
- STBW
- Gender :
Posts : 33
Points : 3587
Reputation : 2
Language : Spanish
Browser : Forum Version :
It works when I put as ID 1 but do not work when I want to use it for group ID 98
I do not know if it is because is a number of 2 characters... (digits) or what
And one question apart, do someone know how to reset the group IDs? I mean, because if the group that used to have ID 3 is deleted.. how it can restart? to do not end having long IDs like 100 etc..
EDITED: I do not think is due the digits, because I tested it with ID 2 and did not work but it works on ID 1
I do not know if it is because is a number of 2 characters... (digits) or what
And one question apart, do someone know how to reset the group IDs? I mean, because if the group that used to have ID 3 is deleted.. how it can restart? to do not end having long IDs like 100 etc..
EDITED: I do not think is due the digits, because I tested it with ID 2 and did not work but it works on ID 1
I modified :
- Code:
number_of_groups: 10, // max number of groups
added:
- Code:
;$(function() {
if ( _userdata.usergroup == 7 ) $('body').css('background-color', 'red');
});$(function() {
if ( _userdata.usergroup == 4 ) $('body').css('background-color', 'lime');
});
does not work.thanks for your time
- STBW
- Gender :
Posts : 33
Points : 3587
Reputation : 2
Language : Spanish
Browser : Forum Version :
Yes, it is: http://www.live-the-worldwide.com/
jessy wrote:
I modified :
- Code:
number_of_groups: 10, // max number of groups
added:
- Code:
;$(function() {
if ( _userdata.usergroup == 7 ) $('body').css('background-color', 'red');
});$(function() {
if ( _userdata.usergroup == 4 ) $('body').css('background-color', 'lime');
});
does not work.thanks for your time
@jessy Since you're using Invision, replace your code with this:
- Code:
$(function() {
if ( _userdata.usergroup == 7 ) $('#ipbwrapper').css('background-color', 'red');
});$(function() {
if ( _userdata.usergroup == 4 ) $('#ipbwrapper').css('background-color', 'lime');
});
SLGray wrote:Exactly is not the group ID: the letter and number?
When I say ID I mean the number alone.
STBW wrote:Yes, it is: http://www.live-the-worldwide.com/
@STBW I'm going to need you to try the code and press Ctrl + Shift + J, type _userdata.usergroup inside the console, and press Enter. Let me know what number appears (if any).
- STBW
- Gender :
Posts : 33
Points : 3587
Reputation : 2
Language : Spanish
Browser : Forum Version :
Appears the number 1
Okay, so keep in mind that that number is the ID you need to use.
And I've also changed the code a tad bit because there was a discrepancy that you brought to my attention.
And I've also changed the code a tad bit because there was a discrepancy that you brought to my attention.
- STBW
- Gender :
Posts : 33
Points : 3587
Reputation : 2
Language : Spanish
Browser : Forum Version :
Still not working for me. In the list of groupIDs you must to put all the IDs or only the ones you want to use?
Ty for your replies
EDITED: And what happens if a user is in more than one group?
Ty for your replies
EDITED: And what happens if a user is in more than one group?
Ok @STBW I think this should have resolved the code problem. The problem was that the user you were testing for probably was not on the first page of the group URL.
For example, here on FMD:
https://fmdesign.forumotion.com/g6-auction-group is the first page of the default group.
https://fmdesign.forumotion.com/g6-auction-group?start=30 is the second page of the default group.
https://fmdesign.forumotion.com/g6-auction-group?start=60 is the last page.
I wasn't iterating through those other pages. Now the code does do that and it should work for you.
If the user is in more than one group, the group that they are associated with depends on the order in which you put your groupIDs.
Based on my script, if a user was in group 1 and 2, then the value of
would be 1. And if a user was in group 2 and 3, the value would be 2.
For example, here on FMD:
https://fmdesign.forumotion.com/g6-auction-group is the first page of the default group.
https://fmdesign.forumotion.com/g6-auction-group?start=30 is the second page of the default group.
https://fmdesign.forumotion.com/g6-auction-group?start=60 is the last page.
I wasn't iterating through those other pages. Now the code does do that and it should work for you.
STBW wrote:EDITED: And what happens if a user is in more than one group?
If the user is in more than one group, the group that they are associated with depends on the order in which you put your groupIDs.
- Code:
groups: [ 1, 2, 3 ], // list of groupIDs
Based on my script, if a user was in group 1 and 2, then the value of
|
sorry no work....maybe I'm wrong,this and all the code
thanks in advance
- Code:
$(function() {
'_userdata.usergroup 2016';
'Developed by Ace 1';
'All rights reserved';
window.faGroups = {
groupIDs: [1, 4, 3], // list of groupIDs
cacheTime: 30, // time in minutes to store data
storage: window.localStorage,
name: _userdata.username,
setGroup: function() {
var version,
groupNumber,
members = [],
loop,
i = 0,
j;
if (faGroups.storage && faGroups.name != 'Anonymous') {
if (!faGroups.storage['group_' + faGroups.name] || !faGroups.storage['group_' + faGroups.name + '_exp'] > new Date().getTime() - faGroups.cacheTime * 60 * 1000) {
for (; i < faGroups.groupIDs.length; i++) {
version = $('#phpbb').length || $('#fa_edge').length ? 'tr[class] strong' : $('.bodylinewidth').length ? 'td[class] a strong' : 'td[class] strong';
j = 0;
$.ajax({
url: '/g' + faGroups.groupIDs[i] + '-',
type: 'get',
async: false,
success: function(group) {
$(version, group).each(function() {
members.push($(this).text());
});
loop = (function() {
if ($('a[href*="?start"] ~ a.pag-img', group).html()) {
var url = $('a[href*="?start"] ~ a.pag-img', group).attr('href');
$.ajax({
url: url,
type: 'get',
async: false,
success: function(extendedGroup) {
$(version, extendedGroup).each(function() {
members.push($(this).text());
});
}
});
loop();
}
})();
}
});
for (; j < members.length; j++) {
if (faGroups.name == members[j]) {
groupNumber = faGroups.groupIDs[i];
j = members.length; // ends loop if found
i = faGroups.groups.length; // ends loop if found
}
}
members = [];
}
faGroups.storage['group_' + faGroups.name] = groupNumber;
faGroups.storage['group_' + faGroups.name + '_exp'] = new Date().getTime();
}
// sets _userdata.usergroup to the user's current group
if (Number(faGroups.storage['group_' + faGroups.name]) != NaN) {
_userdata.usergroup = Number(faGroups.storage['group_' + faGroups.name]);
} else {
_userdata.usergroup = -1; // user not within any group
}
} else {
_userdata.usergroup = 0; // _userdata.session_logged_in == 0
}
}
};
faGroups.setGroup();
});;$(function() {
if ( _userdata.usergroup == 1 ) $('#ipbwrapper').css('background-color', 'red');
});$(function() {
if ( _userdata.usergroup == 4 ) $('#ipbwrapper').css('background-color', 'lime');
});
thanks in advance
- STBW
- Gender :
Posts : 33
Points : 3587
Reputation : 2
Language : Spanish
Browser : Forum Version :
Same here, still not working (in my main forum at least, I tested it in another one I own and there it worked..)
@jessy Replace your code with this:
@STBW I'm still working on a way around the high digits thing. Don't worry. I should be done in the next week.
- Code:
$(function() {
'_userdata.usergroup 2016';
'Developed by Ace 1';
'All rights reserved';
window.faGroups = {
groupIDs: [1, 4, 3], // list of groupIDs
cacheTime: 30, // time in minutes to store data
storage: window.localStorage,
name: _userdata.username,
setGroup: function() {
var version,
groupNumber,
members = [],
loop,
i = 0,
j;
if (faGroups.storage && faGroups.name != 'Anonymous') {
if (!faGroups.storage['group_' + faGroups.name] || !faGroups.storage['group_' + faGroups.name + '_exp'] > new Date().getTime() - faGroups.cacheTime * 60 * 1000) {
for (; i < faGroups.groupIDs.length; i++) {
version = $('#phpbb').length || $('#fa_edge').length ? 'tr[class] strong' : $('.bodylinewidth').length ? 'td[class] a strong' : 'td[class] strong';
j = 0;
$.ajax({
url: '/g' + faGroups.groupIDs[i] + '-',
type: 'get',
async: false,
success: function(group) {
$(version, group).each(function() {
members.push($(this).text());
});
loop = (function() {
if ($('a[href*="?start"] ~ a.pag-img', group).html()) {
var url = $('a[href*="?start"] ~ a.pag-img', group).attr('href');
$.ajax({
url: url,
type: 'get',
async: false,
success: function(extendedGroup) {
$(version, extendedGroup).each(function() {
members.push($(this).text());
});
}
});
loop();
}
})();
}
});
for (; j < members.length; j++) {
if (faGroups.name == members[j]) {
groupNumber = faGroups.groupIDs[i];
j = members.length; // ends loop if found
i = faGroups.groups.length; // ends loop if found
}
}
members = [];
}
faGroups.storage['group_' + faGroups.name] = groupNumber;
faGroups.storage['group_' + faGroups.name + '_exp'] = new Date().getTime();
}
// sets _userdata.usergroup to the user's current group
if (Number(faGroups.storage['group_' + faGroups.name]) != NaN) {
_userdata.usergroup = Number(faGroups.storage['group_' + faGroups.name]);
} else {
_userdata.usergroup = -1; // user not within any group
}
} else {
_userdata.usergroup = 0; // _userdata.session_logged_in == 0
}
}
};
faGroups.setGroup();
});
$(function() {
if ( _userdata.usergroup == 1 ) {
$('#ipbwrapper').css('background-color', 'red');
} else if ( _userdata.usergroup == 4 ) {
$('#ipbwrapper').css('background-color', 'lime');
}
});
@STBW I'm still working on a way around the high digits thing. Don't worry. I should be done in the next week.
- STBW
- Gender :
Posts : 33
Points : 3587
Reputation : 2
Language : Spanish
Browser : Forum Version :
A lot of thaaankss!! it seems to work!
But, when you add or remove a user of the group... the changes are not working until you closes and reopens the browser (I changed the cacheTime: 30, // time in minutes to cacheTime: 2, // time in minutes and waited the 2 minutes... but nothing happened after refreshed the page)
Will be good that the changes really were applied after passed the time cached, ty in advance
But, when you add or remove a user of the group... the changes are not working until you closes and reopens the browser (I changed the cacheTime: 30, // time in minutes to cacheTime: 2, // time in minutes and waited the 2 minutes... but nothing happened after refreshed the page)
Will be good that the changes really were applied after passed the time cached, ty in advance
- STBW
- Gender :
Posts : 33
Points : 3587
Reputation : 2
Language : Spanish
Browser : Forum Version :
The code does not work for more than one function, how can I add more functions and make them work for a member that is in the required groups?
For example, there are 2 functions:
1) One that makes red bg for group 117
2) Other that makes appear green font color for group 116..
The problem is, that... I want the 2 functions work at same time, but only works one (usually the first one of the array). I want that the member who is on both groups (116 & 117) sees the red bg and the green font, but only one of them works.
Idk if I explained well my problem >.<
For example, there are 2 functions:
1) One that makes red bg for group 117
2) Other that makes appear green font color for group 116..
The problem is, that... I want the 2 functions work at same time, but only works one (usually the first one of the array). I want that the member who is on both groups (116 & 117) sees the red bg and the green font, but only one of them works.
Idk if I explained well my problem >.<
STBW wrote:The code does not work for more than one function, how can I add more functions and make them work for a member that is in the required groups?
For example, there are 2 functions:
1) One that makes red bg for group 117
2) Other that makes appear green font color for group 116..
The problem is, that... I want the 2 functions work at same time, but only works one (usually the first one of the array). I want that the member who is on both groups (116 & 117) sees the red bg and the green font, but only one of them works.
Idk if I explained well my problem >.<
@STBW
I see what you're saying. Hm.. I don't know if I can make a script that checks for ALL groups a user is in without putting a lot of stress on your browser every half an hour or so. The script above just gets the first group (based off the numbers you entered in the array) like you said. If I were to check for all groups, then I would probably have to make an array of all the groups that the logged on user is in. It's definitely possible and if it's really important to you, I can make this a priority. Just shoot me a post on this topic letting me know. And also, make sure you tag me because FMD is kinda inactive.
How many groups do you have on your forum?
- STBW
- Gender :
Posts : 33
Points : 3587
Reputation : 2
Language : Spanish
Browser : Forum Version :
A lot of thanks! @Ace 1 for your perseverance!
Yeah I am interested, but about how many groups I have... it is something that probably will change every now and then (because we are a roleplaying site.. and each RP group has its own FM group, so if a new RP group is created we create a new FM Group)
So.. I do not know what to answer to this, is it very important? What if I only will apply that rule to 20 specific groups? Let me know any other info you need!
A lot of thanks!
Yeah I am interested, but about how many groups I have... it is something that probably will change every now and then (because we are a roleplaying site.. and each RP group has its own FM group, so if a new RP group is created we create a new FM Group)
So.. I do not know what to answer to this, is it very important? What if I only will apply that rule to 20 specific groups? Let me know any other info you need!
A lot of thanks!
- Sponsored content
Page 1 of 2 • 1, 2
Create an account or log in to leave a reply
You need to be a member in order to leave a reply.
Page 1 of 2
Permissions in this forum:
You cannot reply to topics in this forum