inherit
244991
0
Dec 2, 2023 16:05:42 GMT -8
sundae13
8
May 2017
sundae13
|
Post by sundae13 on May 27, 2017 4:33:17 GMT -8
Hi!
I have a strange one for you all. Members of our board like to joke about the like to post ratio (number of likes their posts have gotten/number of posts) as a form of self validation. Is there any bit of code out there that would allow us to display this in their mini profiles? We've already add a total number of like line, but math.
See, strange?
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on May 30, 2017 2:38:45 GMT -8
Download | Source | Instructions
Ignore below, use plugin above. Edit: Don't bother using this now. It will break threads that have more than 1 page due to the document.write part of it. EDIT: Don't use. Am leaving this here to show that even experienced coders make stupid mistakes. <br /><span title="$[user.likes]">Likes</span> to <span title="$[user.posts]">posts</span> ratio: <script>
var __likes = parseInt("$[user.likes]".replace(/\D+/g, ""), 10); var __posts = parseInt("$[user.posts]".replace(/\D+/g, ""), 10);
document.write((__likes / __posts).toFixed(2)); // Change toFixed number for more decimal places
</script> Place in mini profile template. Probably want it inside the "info" container.
|
|
inherit
244991
0
Dec 2, 2023 16:05:42 GMT -8
sundae13
8
May 2017
sundae13
|
Post by sundae13 on May 30, 2017 16:04:54 GMT -8
Thank you! This is awesome!
|
|
inherit
240015
0
Jun 12, 2021 19:09:24 GMT -8
wolverineblues
51
December 2016
wolverineblues
|
Post by wolverineblues on Jan 2, 2018 4:16:05 GMT -8
Hello, this may be Necromancer, but since this is a really handy feature (which I'd love to use) and it had relatively few replies, I'd like to ask on my own. The code Peter posted did not work for me. It doesn't work with any posted over 1000 posts for some reason, showing instead of a number the word "nan". Also, when it manages to show up correctly, it only does so for the thread opener and not the following posters. Is there a way to improve the code or anyone to help me figuring out what's wrong with it? This weird stuff also appears when I try loading other page:
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Jan 3, 2018 1:21:32 GMT -8
|
|
inherit
240015
0
Jun 12, 2021 19:09:24 GMT -8
wolverineblues
51
December 2016
wolverineblues
|
Post by wolverineblues on Jan 3, 2018 21:56:28 GMT -8
Thanks Peter! Although the ratios show right and neat now... Nonetheless, I still get this issue when moving to another page. It fails to load and shows this now (instead of NaN) What could this be? They appear to be a chain of the entire posters's ratios that have posted in the page... but apparently something in the code somehow screws up the loading of the page... Any idea?
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Jan 4, 2018 4:15:20 GMT -8
wolverineblues , Ah yeah, don't bother with this code then. I suggest asking for a plugin. I completely forgot about the caching that goes on, so document.write is causing that issue.
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Jan 4, 2018 10:33:21 GMT -8
Just wanted to clarify the issue for those that don't understand document.write. When the document (aka the HTML page) has loaded, then document.write calls will call document.open automatically. So in case of the code above, when changing pages in a thread, it will actually write to a new document and breaks the forum. The same would likely apply to cached AJAX calls when changing pages. However, you never get to this point, so the caching isn't the issue here. Basically don't use document.write like the nub I am, or you break forums. Even experienced programmers make stupid mistakes wolverineblues, I have seen your request, if I get time at the weekend, I might do it for you.
|
|
inherit
240015
0
Jun 12, 2021 19:09:24 GMT -8
wolverineblues
51
December 2016
wolverineblues
|
Post by wolverineblues on Jan 4, 2018 11:22:08 GMT -8
Thanks PeterI also noticed that if I press the "back" button in the explorer, the page works correctly. I would not have a problem using it that way but I fear that may deter less patient users.
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Jan 14, 2018 7:26:25 GMT -8
|
|