HankLloydright / RDForum.org hide read threads in "/watched/threads"

// ==UserScript==
// @name         RDForum.org hide read threads in "/watched/threads" 
// @namespace    http://tampermonkey.net/
// @version      1.03.26d
// @description  For the latest Xenforo update on many sites, there's no longer a "View Unread Watched Threads" link like there used to be. This plugin hides all "read" threads in the "Watched Threads" view. Also opens all threads in a new tab.
// @author       HankLloydRight
// @include      https://www.rdforum.org/watched/threads*
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @grant        none
// @license      MIT
// ==/UserScript==

var links = $('[data-xf-init="preview-tooltip"]');
var tag="<span style='color:#13ff68e8;font-size:10px;'> Jumps to New</span>";

$(".p-title-value").html("Watched threads <a class='showunread' data-unread='true'> Show All Threads</a>");
setTimeout(function () {$('.structItem--thread:not(".is-unread")').hide();},250); // hide  all read threads after 1/4 second

$.each( links, function( key, val ) {
    var lnk=$(this);
    var href=lnk.attr("href");
    lnk.attr('target','_blank'); // open in new tab
    if (href.indexOf("/unread")==-1) {
        lnk.html(lnk.html()+tag).attr("href",href+"unread/"); // set unread tag to go to first unread // set "Jumps to new" indicator
    }
});

$(".showunread").on('click', function() {
    if ($(this).data("unread")==true) {
        $(".showunread").html("Show Unread Threads");
        $('.structItem--thread').show();
        $(this).data("unread",false);
    }
    else {
        $(".showunread").html("Show All Threads");
        $('.structItem--thread:not(".is-unread")').hide();
        $(this).data("unread",true);
    }
});