inherit
139476
0
Jan 19, 2020 4:24:42 GMT -8
Auburn
I will steal your smile and treasure it
263
April 2009
auburneye
|
Post by Auburn on Nov 6, 2009 22:27:59 GMT -8
What does a basic javascript code look like that will only apply to guests? Or, what if only to admins or other specific member groups? The only one I'm familiar with is: <script type="text/javascript"> if(pb_username!='Guest') { Code Here } </script> Which makes the code visible only to members. What would the codes look like for other member groups? Any insight on javascript [not just pertaining to this] would be awesome.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Nov 6, 2009 23:23:43 GMT -8
I don't think ProBoards currently supports a JavaScript version of a user's usergroup. I know you can find it via links to a user's profile, because it will be marked with CSS .group1, .group2, etc. But there is no JavaScript variable (such as pb_username, e.g. pb_groups) that tells.
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Nov 7, 2009 7:31:06 GMT -8
Unless you use this:
<script type="text/javascript"> if(pb_username == "admin|staffer|staffer") { Code Here } </script>
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Nov 7, 2009 8:49:05 GMT -8
Close.
<script type="text/javascript"> if (pb_username.match("/^(admin|user1|user2|user3)$/")) { //Code Here } </script>
But you'd have to add each person manually.
|
|
inherit
100824
0
May 13, 2012 5:37:49 GMT -8
Michael
14,585
March 2007
wrighty
|
Post by Michael on Nov 7, 2009 9:09:07 GMT -8
charles - Quotes aren't required - you're thinking PHP
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Nov 7, 2009 9:55:16 GMT -8
Indeed I am. I use RegEx in PHP much more often than in JS.
if (pb_username.match(/^(admin|user1|user2|user3)$/))
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Nov 7, 2009 12:36:53 GMT -8
I wouldn't think you would need RegExp.. if(pb_username.match(/admin|user|user/i); should work..
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 7, 2009 15:20:55 GMT -8
I wouldn't think you would need RegExp.. if(pb_username.match(/admin|user|user/i); should work.. What you just posted is a regular expression. You need the ^ because someone with the usernames xadmin, xxadmin, xxxadmin would match admin, and the $ because someone with the usernames admi, adm, ad, and a would also match admin.
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Nov 7, 2009 16:11:58 GMT -8
Oh, lol. the /i does that?
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 7, 2009 16:14:48 GMT -8
No, the ^ and $ do that. The ^ says this is the beginning of the expression and the $ says this is the end of the expression.
The i tells the match() function that this search is case-insensitive so the letters could be AdMIn and the function would still find a match.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Nov 7, 2009 23:32:30 GMT -8
Anything in /slashes/ is RegEx. >_> case-insensitive*
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 8, 2009 0:40:52 GMT -8
Anything in /slashes/ is RegEx. >_> case-insensitive* Haha, can't believe I said that.
|
|
inherit
16846
0
Nov 19, 2012 15:20:20 GMT -8
Chris
3,036
December 2003
cddude
|
Post by Chris on Nov 9, 2009 18:20:03 GMT -8
I wouldn't think you would need RegExp.. if(pb_username.match(/admin|user|user/i); should work.. What you just posted is a regular expression. You need the ^ because someone with the usernames dmin, min, in, and n would match admin, and the $ because someone with the usernames admi, adm, ad, and a would also match admin. Since we're all ragging on you, that's not necessarily the case. What you said would be if pb_username = "dmin", then that expression would be true. That's not true unfortunately. "dmin" does not match "admin" (or "user"). However, pb_username = "dadmin" or pb_username = "deadmin" would match "admin" which would then be true I just wanted to point this out to avoid confusing other people. We all know that you know what you meant Jordan... 'cause remember, it's the code you write that counts, not how you explain it. Edit: Oh, and I wrote this snippet a while back to try and aid with the issue of not having group access. *shrugs*
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Nov 9, 2009 18:29:04 GMT -8
>.> People hate me You could just use: if(pb_username === "admin"){} I know some javascript, just trying to help out x.x
|
|
#00AF33
14306
0
1
Sept 8, 2023 8:54:17 GMT -8
Jordan
What is truth?
11,838
October 2003
jab2
|
Post by Jordan on Nov 9, 2009 19:36:28 GMT -8
What you just posted is a regular expression. You need the ^ because someone with the usernames dmin, min, in, and n would match admin, and the $ because someone with the usernames admi, adm, ad, and a would also match admin. Since we're all ragging on you, that's not necessarily the case. What you said would be if pb_username = "dmin", then that expression would be true. That's not true unfortunately. "dmin" does not match "admin" (or "user"). However, pb_username = "dadmin" or pb_username = "deadmin" would match "admin" which would then be true I just wanted to point this out to avoid confusing other people. We all know that you know what you meant Jordan... 'cause remember, it's the code you write that counts, not how you explain it. Edit: Oh, and I wrote this snippet a while back to try and aid with the issue of not having group access. *shrugs* Thanks for catching that. What I meant to say didn't come out right. ><
|
|