Script-based fix for vB5 unread posts issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GaWd
    New Member
    • May 2011
    • 29
    • 3.8.x

    Script-based fix for vB5 unread posts issues

    After not getting very much direction on how to fix the unread posts functionality, we fixed our using an in-house script. It only runs on search pages, only shows unread topics, and once read, the topics go away. Oh yeah, and it organizes the threads by last response...Kind of like vBulletin 4.

    Code:
    function getDate (thread) {
        var postdate = thread.getElementsByClassName("post-date")[0].innerHTML,
        dateRegex = /(\d\d)-(\d\d)-(\d\d\d\d), (\d\d):(\d\d)/,
        dateArray = postdate.match (dateRegex),
            threadDate = new Date (dateArray[3], dateArray[1], dateArray[2], dateArray[4], dateArray[5], 0);
        return threadDate;
    }
    
    var match = /search/.test(location.pathname);
    if (match) {
        var threads = document.getElementsByClassName("topic-item");
        var threadsArray = Array.prototype.slice.call(threads); 
        threadsArray.sort (function (a, b) {
                var aDate = getDate(a),
                      bDate = getDate(b);
                return (aDate - bDate);
            }).reverse ();
    
        table = document.getElementsByClassName ("topic-list")[0];
    
        threadsArray.forEach (function (thread) {
            if (thread.className.match (/read/)) {
            thread.style.display = "none";
            }
            table.appendChild (thread);
        });
        threadsArray = null;
    }
    I'm sure there are better or more efficient ways of doing it, but this only took us an hour or two from scratch, and it seems to work just fine, and hopefully it helps someone else out who is struggling with some of the quirks of vB5.
  • glennrocksvb
    Former vBulletin Developer
    • Mar 2011
    • 4020
    • 5.7.X

    #2
    Why not simply hide the "read" topic-item via CSS?

    Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!

    Comment

    • GaWd
      New Member
      • May 2011
      • 29
      • 3.8.x

      #3
      I guess you can to it that way, too. It wouldn't properly sort the results, though. So a different approach would be to use CSS to return results, and use the sort portion of the script to sort the results...which is currently horribly broken.

      Comment

      • glennrocksvb
        Former vBulletin Developer
        • Mar 2011
        • 4020
        • 5.7.X

        #4
        Either way, client-side fix for unread posts is not a good solution. What if you have read all the posts in page 1, then the first page would be empty.

        Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!

        Comment

        Related Topics

        Collapse

        Working...