I'm running a discussion forum and I would like KM (if possible) to tally the number of times an individual posts in the forum. The html code is similar for a specific user's posts. Here is a screen shot of someone who posted twice:
My question is: is there a way that KM can identify the number of times an element of this code repeats? That would give me the total number of posts per each user.
I can't see your image because it is a TIFF (best to post JPG or PNG images).
So, shooting in the dark, you could do a JavaScript query to find and count the number of HTML elements of a given class or tag.
The user is only displayed as a link at the top of the page with their photo. Unfortunately, this is behind a password so I can’t provide access. I looked all over for the number of posts and it’s not there, which is strange.
That said the html code doesn’t have to be unique to the user. In fact, I would ideally just like KM to repeat through a macro that will identify the number of posts, then go to the next user…and so forth.
My thinking was, is there a way for it to count “discussion_entry communication_message” or perhaps “data-mark-read-url”? Since that shows up every time a new post is made, it could count those and mission accomplished!
I was able to get it to work on everything within the page, except the posts! It looks like the reason probably is because the posts are set within an iframe. Any suggestions?
@Scott_Matkovich, if my above post does not work for you, you might try this (just guessing):
var iframeElem = document.getElementById("ID_of_your_iframe");
var postList = iframeElem.querySelectorAll("div.discussion_entry");
postList
###OR
var iframeElem = document.getElementById("ID_of_your_iframe");
var iframeContent = iframeElem.contentWindow.document.body;
var postList = iframeContent.querySelectorAll("div.discussion_entry");
postList
Replace "ID_of_your_iframe" with the actual ID from the HTML code.
var iframeElem = document.getElementById("speedgrader_iframe");
var postList =iframeElem.contentWindow.document.body.querySelectorAll("div.discussion_entry");
postList
A really easy way to test is to right-click on the web page, and select "inspect".
Then just paste the above code into the JavaScript Console.
Hey JMichaelTX - I just have to say, that you are an awesome contributor! Also, every time I see your screen-name I think you are Texas Michael - which is a pretty awesome name.
Anyway, I am working on something similar to what Scott here is working on. Your iframe script is freaking awesome! I was able to get it to work by adding .length onto the end, and it worked like a charm.
So, what I am wondering, is there a way to write an if/then macro such that if there is no iframe that it will execute a 0 (zero) but if there is an iframe it will execute your script? Is there another script that is needed in order to recognize whether or not there is an iframe? Any advice or thoughts?
As always - Totally appreciate you and your help!