inherit
264279
0
Feb 5, 2024 17:01:15 GMT -8
shawnatdgk
59
May 2021
shawnatdgk
|
Post by shawnatdgk on Jun 25, 2023 9:27:10 GMT -8
SPLIT PAGE TO URLs THIRD backslash TO GET ONLY FORUM URL
var url = window.location.href
var split = url.split('/');
var split_result = split[2] GET POST NUMBER
path_to_fetch_post_num = $(".list > tbody >tr").attr('id')
sliced_path_to_post_num = path_to_fetch_post_num.slice(5) FORM THE LINK TO THE POST
built_url = split_result + "/" + "post" + "/" + sliced_path_to_post_num + "/thread";
So I have went to h-e-double hockey sticks and back trying to find a good way to get the "link to post" url via javascript. Most of the only places I could find the post number was under the "Post Options" settings tool that's located on the top right of each post. But it seems, nothing in there retrievable because the codes apparently not ran until the list is opened via the tool icon. So the only place i could find to extract the "post link #" from was this line of code:
<tr id="post-114"
<table class="list" role="presentation">
<tbody class="lm-content-A2ng5nIwCQ6L28yxsLQI">
<tr id="post-114" class="item post js-post deletable first">
<td class="unblocked">
<table role="grid">
<tbody><tr>
<td class="left-panel" rowspan="2">
<div class="mini-profile"> I had to get that tr id and splice it at (-) to get just the number and then get the url of the forum by splitting the page url at the 3rd ( / ). And with them results, build the url to the "post link" as I see it when I use the tool.
Soooo, my question is: Is this a solid way of doing it? From my experience, I'm about to be told, you didn't have to do all that, its this simple ...... lol
Thanks in advance
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,324
January 2004
todge
|
Post by Todge on Jun 25, 2023 10:41:15 GMT -8
Well, you can get the forum URL with this..
var forum_url = pb.data('forum_url');
As for the post number, there are a couple of ways, but the post's TR id is as good as any.
|
|
inherit
264279
0
Feb 5, 2024 17:01:15 GMT -8
shawnatdgk
59
May 2021
shawnatdgk
|
Post by shawnatdgk on Jun 25, 2023 13:03:12 GMT -8
Well, you can get the forum URL with this.. var forum_url = pb.data('forum_url'); As for the post number, there are a couple of ways, but the post's TR id is as good as any. Cool deal. Good to know. Thanks Todge!!
|
|
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 Jun 25, 2023 13:19:27 GMT -8
SPLIT PAGE TO URLs THIRD backslash TO GET ONLY FORUM URL var url = window.location.href
var split = url.split('/');
var split_result = split[2] GET POST NUMBER path_to_fetch_post_num = $(".list > tbody >tr").attr('id')
sliced_path_to_post_num = path_to_fetch_post_num.slice(5) FORM THE LINK TO THE POST built_url = split_result + "/" + "post" + "/" + sliced_path_to_post_num + "/thread"; So I have went to h-e-double hockey sticks and back trying to find a good way to get the "link to post" url via javascript. Most of the only places I could find the post number was under the "Post Options" settings tool that's located on the top right of each post. But it seems, nothing in there retrievable because the codes apparently not ran until the list is opened via the tool icon. So the only place i could find to extract the "post link #" from was this line of code: <tr id="post-114"<table class="list" role="presentation">
<tbody class="lm-content-A2ng5nIwCQ6L28yxsLQI">
<tr id="post-114" class="item post js-post deletable first">
<td class="unblocked">
<table role="grid">
<tbody><tr>
<td class="left-panel" rowspan="2">
<div class="mini-profile"> I had to get that tr id and splice it at (-) to get just the number and then get the url of the forum by splitting the page url at the 3rd ( / ). And with them results, build the url to the "post link" as I see it when I use the tool. Soooo, my question is: Is this a solid way of doing it? From my experience, I'm about to be told, you didn't have to do all that, its this simple ...... lol Thanks in advance In PBv5, it is generally best practice to employ the data sent with the page. The old-school method of scraping the HTML should be only considered when the data you're seeking cannot be found elsewhere, especially since Proboards now allows removing or replacing things such as ID and classes or even changing the entire HTML structure via the template layouts in each theme. Other codes running on the forum can also make changes (which is one reason Proboards started serving the data in PBv5, this was a very valid pain point in PBv4), so it will eventually fail if your code relies on these easily changeable things. On any page, you can see the data Proboards sends with that page by popping open your browser's built-in debugger and typing proboards.dataHash in the console. As you can see, the forum_url Todge mentioned is in there, and you can access it using either proboards.dataHash.forum_url or pb.data('forum_url') with the former method deprecated and slated to be removed in PBV6. If you look closely at the data returned for this very thread we are now in, you will see there is a data point in that dataHash called proboards.post, which holds data regarding each post in this thread. To access it, you use either proboards.dataHash['proboards.post'] or pb.data('proboards.post'), which returns the following (prior to me adding my reply to this thread): { "7328370": { "id": 7328370, "url": "https://support.proboards.com/post/7328370", "liked": 0, "created_by": 264279, "ip": "127.0.0.1", "created_on": 1687714030, "thread_id": 674134 }, "7328372": { "created_on": 1687718475, "thread_id": 674134, "ip": "127.0.0.2", "created_by": 19529, "id": 7328372, "url": "https://support.proboards.com/post/7328372", "liked": 1 } } That gives you info about all the posts you can see on the page. - If we were in a multi-page thread, then the posts on subsequent pages (and their associated data) would only become available once the posts from that page are viewable.
- This is especially valuable when combined with the proboards.thread data on pages such as search results/recent posts that display a list of posts from completely different threads and boards.
- Protected data such as IP would only be served to those with permission to see them, so keep that in mind. If you can see them, don't assume a non-staff user can see them as well
|
|
inherit
264279
0
Feb 5, 2024 17:01:15 GMT -8
shawnatdgk
59
May 2021
shawnatdgk
|
Post by shawnatdgk on Jun 25, 2023 15:15:54 GMT -8
SPLIT PAGE TO URLs THIRD backslash TO GET ONLY FORUM URL var url = window.location.href
var split = url.split('/');
var split_result = split[2] GET POST NUMBER path_to_fetch_post_num = $(".list > tbody >tr").attr('id')
sliced_path_to_post_num = path_to_fetch_post_num.slice(5) FORM THE LINK TO THE POST built_url = split_result + "/" + "post" + "/" + sliced_path_to_post_num + "/thread"; So I have went to h-e-double hockey sticks and back trying to find a good way to get the "link to post" url via javascript. Most of the only places I could find the post number was under the "Post Options" settings tool that's located on the top right of each post. But it seems, nothing in there retrievable because the codes apparently not ran until the list is opened via the tool icon. So the only place i could find to extract the "post link #" from was this line of code: <tr id="post-114"<table class="list" role="presentation">
<tbody class="lm-content-A2ng5nIwCQ6L28yxsLQI">
<tr id="post-114" class="item post js-post deletable first">
<td class="unblocked">
<table role="grid">
<tbody><tr>
<td class="left-panel" rowspan="2">
<div class="mini-profile"> I had to get that tr id and splice it at (-) to get just the number and then get the url of the forum by splitting the page url at the 3rd ( / ). And with them results, build the url to the "post link" as I see it when I use the tool. Soooo, my question is: Is this a solid way of doing it? From my experience, I'm about to be told, you didn't have to do all that, its this simple ...... lol Thanks in advance In PBv5, it is generally best practice to employ the data sent with the page. The old-school method of scraping the HTML should be only considered when the data you're seeking cannot be found elsewhere, especially since Proboards now allows removing or replacing things such as ID and classes or even changing the entire HTML structure via the template layouts in each theme. Other codes running on the forum can also make changes (which is one reason Proboards started serving the data in PBv5, this was a very valid pain point in PBv4), so it will eventually fail if your code relies on these easily changeable things. On any page, you can see the data Proboards sends with that page by popping open your browser's built-in debugger and typing proboards.dataHash in the console. As you can see, the forum_url Todge mentioned is in there, and you can access it using either proboards.dataHash.forum_url or pb.data('forum_url') with the former method deprecated and slated to be removed in PBV6. If you look closely at the data returned for this very thread we are now in, you will see there is a data point in that dataHash called proboards.post, which holds data regarding each post in this thread. To access it, you use either proboards.dataHash['proboards.post'] or pb.data('proboards.post'), which returns the following (prior to me adding my reply to this thread): { "7328370": { "id": 7328370, "url": "https://support.proboards.com/post/7328370", "liked": 0, "created_by": 264279, "ip": "127.0.0.1", "created_on": 1687714030, "thread_id": 674134 }, "7328372": { "created_on": 1687718475, "thread_id": 674134, "ip": "127.0.0.2", "created_by": 19529, "id": 7328372, "url": "https://support.proboards.com/post/7328372", "liked": 1 } } That gives you info about all the posts you can see on the page. - If we were in a multi-page thread, then the posts on subsequent pages (and their associated data) would only become available once the posts from that page are viewable.
- This is especially valuable when combined with the proboards.thread data on pages such as search results/recent posts that display a list of posts from completely different threads and boards.
- Protected data such as IP would only be served to those with permission to see them, so keep that in mind. If you can see them, don't assume a non-staff user can see them as well
Hmm interesting. We just don't know what we don't know! lol Thanks for that explanation and insight. I understand. On a side note, it probably erks you to see old school coders scraping the HTMl, huh? lol I guess some bad habits never die! lol no but I'm glad you've put it into perspective for me! I needed that! Every time I venture back to Proboards to fiddle around with some coding like I normally sporadically do, I insecurely and regularly think to myself while coding, "I bet they must have come up with newer and better ways to do this and I'm probably doing this for nothing!.. lol And yes it really was a huge problem the old school way for the exact reasons you mentioned here. I appreciate the response.
|
|
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 Jun 25, 2023 21:05:00 GMT -8
shawnatdgk , you are welcome, and not much irks me nowadays. I've learned to accept the things I cannot change and only try to change the things I cannot accept. I'm just giving you an updated lay of the land to save you some traveling time. If you wish to pursue the scenic route, then by all means, have at it. At times, I've found pleasure in the journey regardless of the destination. Edit:
I neglected to mention a third access method for those special data points ( proboards.post, proboards.thread, proboards.conversation, proboards.message, proboards.badge and proboards.user) and that is in the form: pb.item('post',7328370)
|
|