Announcement

Collapse
No announcement yet.

Script-based fix for vB5 unread posts issues

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

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

    GIPHY for vB5 AutoLinker Auto-Create Flag Report Topic Social Icons in Postbit Clear Cache Cron DragDrop Upload Topic AJAX AutoUpdate Custom Avatars Selector Stop Links in Posts...and more!

    Comment


    • #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


      • #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.

        GIPHY for vB5 AutoLinker Auto-Create Flag Report Topic Social Icons in Postbit Clear Cache Cron DragDrop Upload Topic AJAX AutoUpdate Custom Avatars Selector Stop Links in Posts...and more!

        Comment

        Related Topics

        Collapse

        Working...
        X