inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jan 8, 2013 14:26:21 GMT -8
<script> {foreach $[plugin.settings.user_groups]} var grp = new RegExp(groupName, 'g') var groupName = "$[plugin.settings.user_groups.group_name]"; if(typeof(Storage)!=="undefined"){ if(location.href.match(proboards.data('user').url)) { $(function(){ if($(".name_and_group")[0].innerHTML.match(grp)){ localStorage.group_id = groupName; alert(groupName); } }); } if(location.href.match(/thread/)){ $(function(){ var name = proboards.data('user').name; var usrn = new RegExp(name, 'g'); if($(".mini-profile")[0].innerHTML.match(usrn) && $(".mini-profile")[0].innerHTML.match(grp)){ localStorage.group_id = groupName; alert("this worked"); } }); } }
{/foreach}
</script>
Okay so I know this is supposed to be a built in feature in the future but I have some codes I want to do based of of that so I made this. The way this works is that when the user views there profile page it searches the area below the big text with there name in it for a predefined user-group. If the any of the user-groups match then they are given local-storage with there user-group name. This will also check the mini-profile while the user is viewing a thread. There is a problem with that which I will get to later. The main problem is with the auto-form. The code without the auto-form works fine. It also works fine if you only specify ONE usergroup in the auto-form. But if you specify more, then if any of them match then in stead of giving you that usergroup it gives you the one that was listed LAST. So if I have three user-groups on my forum: Admin, G-mod, and Mod. Everyone will be given localStorage with there usergroup being Mod instead of what they actually are.
Now to the mini profile problem I know what the problem is but I don't know how to fix it. The code only checks the first mini-profile on the page, this is because of the line "if($(".mini-profile")[0].innerHTML.match(usrn) && $(".mini-profile")[0].innerHTML.match(grp)){". On that line I specify to check the first one when I put the [0] after (".mini-profile") however if I remove that [0] then the code doesn't function at all.
Any help is greatly appreciated.
|
|
inherit
King Oligochaete
126470
0
Feb 24, 2021 12:23:15 GMT -8
Wormopolis
Stop rating plugins with 1 star that dont deserve it.
20,002
June 2008
tbserialkillers
Wormo's Mini-Profile
|
Post by Wormopolis on Jan 9, 2013 8:06:28 GMT -8
whenever you assign a variable in a loop iike
var a = data
you replace whatever data was in there with the new data. you should use a temp variable and use the += operator , and then when done with the loop write the temp variable to session storage
|
|
inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jan 9, 2013 12:48:22 GMT -8
Okay, so your saying I should do var groupName += "$[plugin.settings.user_groups.group_name]"; ?
|
|
inherit
King Oligochaete
126470
0
Feb 24, 2021 12:23:15 GMT -8
Wormopolis
Stop rating plugins with 1 star that dont deserve it.
20,002
June 2008
tbserialkillers
Wormo's Mini-Profile
|
Post by Wormopolis on Jan 9, 2013 20:12:18 GMT -8
if you are wanting to store all the group names from the plugin data into sessionstorage, sure. what is the purpose of storing the group names?
|
|
inherit
170346
0
Mar 1, 2016 12:53:37 GMT -8
Shorty
Yeah, I'm that cool. Lol! No I'm not.
3,018
August 2011
shortyverrett94
|
Post by Shorty on Jan 9, 2013 22:29:57 GMT -8
Could you not also just use a template variable?
<script> <!-- var userGroup = '$[current_user.group]'; --> </script>
That just makes the current user's group a variable. You would just need the plugin user to add this right after the opening <body> tag, and you would be good to go. Just my input though.
|
|
inherit
King Oligochaete
126470
0
Feb 24, 2021 12:23:15 GMT -8
Wormopolis
Stop rating plugins with 1 star that dont deserve it.
20,002
June 2008
tbserialkillers
Wormo's Mini-Profile
|
Post by Wormopolis on Jan 10, 2013 0:24:43 GMT -8
I believe template variable are only available in the template editor. unless you used that trick from other post with making a hidden div that stored template data
|
|
inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jan 10, 2013 13:40:17 GMT -8
The purpose is for userGroup specific codes. I know that proboards is going to give us built in data but I've had a couple ideas that need this. So I decided to try and make this while I was waiting.
It's also stored in localStorage I just forgot to remove the myGroup variable (it's never used in the code)
Also I may have been a bit vague in my first post. This code gives each person localStorage with there userGroup in it. That way codes can be run by userGroup by just calling that local storage and seeing if it matches.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,018
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Jan 12, 2013 7:40:52 GMT -8
Could you not also just use a template variable? <script> <!-- var userGroup = '$[current_user.group]'; --> </script> That just makes the current user's group a variable. You would just need the plugin user to add this right after the opening <body> tag, and you would be good to go. Just my input though. A lot more info (including group affiliations) have been added to the dataHash in the most recent update. Give the command console.log(JSON.stringify(proboards.data("user"),null,2)) a go in your console to see the additional data
|
|
inherit
173855
0
Apr 23, 2024 9:59:44 GMT -8
Texas
I check in every once in a while...
869
November 2011
petermaggio
|
Post by Texas on Jan 12, 2013 8:31:30 GMT -8
Sooo...looks like I don't need this anymore
|
|