HankLloydright / TCF 2022 Mods

// ==UserScript==
// @name         TCF 2022 Mods
// @namespace    http://tampermonkey.net/
// @version      4.1.22.2
// @description  Restore some links/looks from the old TCF
// @author       HankLloydRight
// @match        https://www.tivocommunity.com/*
// @updateURL    https://openuserjs.org/meta/HankLloydright/TCF_2022_Mods.meta.js
// @downloadURL  https://openuserjs.org/install/HankLloydright/TCF_2022_Mods.user.js
// @grant        none
// @license      MIT
// html symbol reference: https://www.w3schools.com/charsets/ref_utf_symbols.asp
// ==/UserScript==
(function() {

    'use strict';
    var $ = $ || window.$;
// .hScroller-scroll ==> following page
// .california-upper-page-nav ==> thead page
// .california-filter-container ==> forum page/thread list


// added Oct 30,2023 ======= 
// to add back page nav functions lost in recent VS "update"
    $('.username').css("font-weight","bolder");
	$('.california-lower-page-nav').css("margin-left","0");
	$('.california-thread-position').css("font-size","x-small");
	let color="blue"; // light mode
	if ($(".california-menu-item--light").css("display")=="list-item") color="chartreuse"; //dark mode
	$('[qid="page-nav-next-button"]').css("color",color).css("font-weight","bold");
	try {
	let pages=$('.pageNav-jump[data-original-title="Go to page"]').html().trim();
	let splt=pages.indexOf(" of ");
	let a=pages.substring(0,splt),b=pages.substring(splt+4);
	console.log("["+pages+"]",splt,a,b);	
	if ((b-a)>1) $('[qid="page-nav-next-button"]').html((b-a)+" More Pages ");
	if ((b-a)==1) $('[qid="page-nav-next-button"]').html("1 More Page ");
	if (a==b) $('[qid="page-nav-next-button"]').html("Last Page").css("display","block").removeClass("pageNav-jump--next");
	}
	catch {}
// end of added Oct 30,2023 ======= 

	//Dan203 fix for avatars 1/22/2024
	$("[class^=avatar-]").css("width","95%").css("height","auto");


    $('.hScroller-scroll,.california-upper-page-nav').append(
                 // '<br><a style=""  class="tabs-tab" href="/watched" rel="nofollow" qid="following-participated-discussions">Following</a>&nbsp;&nbsp;&nbsp;&nbsp;'+
                  '<br><a style="" class="tabs-tab" href="/account/alerts" rel="nofollow" qid="following-participated-discussions">Alerts</a>&nbsp;&nbsp;&nbsp;&nbsp;');

    $('.hScroller-scroll,.california-filter-container').append(
                  '<a style="" class="showunread tabs-tab" >Hide Read Threads</a>&nbsp;&nbsp;&nbsp;&nbsp;');

    // add colored visited links
    $('head').append( "<style>a.thread-title--gtm:visited, a.structItem-title:visited  { color:#8e44ad !important; }</style>" );

	$('#footer').html(
		'<a style="" id="showignored" class="tabs-tab">Show Ignored Threads</a>&nbsp;&nbsp;&nbsp;&nbsp;'+
		'<a style="" class="toggletooltips tabs-tab">Tooltip Previews</a>&nbsp;&nbsp;&nbsp;&nbsp;'
	).show();

	// add hover to user menu dropdown
    $('[qid="navbar-profile-button"]').hover(
         function() {$(this).trigger("click");},
         function() {} );// leave this, it's required for hoverout to do nothing

    //move things around
    $('[qid="thread-position-footer"]').css("float","right");
    $('.california-lower-page-nav').css("float","left"); //bottom pagination
    $('[qid="action-bar-section"]').css("float","right");
    // hide recommended reading, footer
    $("#thread-recommended-reading").hide();

    // add 'follow' link to bottom of thread page
    if ($(".button-group").length) $('.california-block-outer-lower-nav').prepend($(".button-group").html()+"&nbsp;&nbsp;&nbsp;");
	$('[qid="thread-follow-unfollow-button"],[qid="thread-follow-follow-button"],[qid="thread-jump-to-latest"]').css("float","right");

	// morac fix the edit button 1/21/2024 version 2
    var edits=$('[data-xf-init="reaction"]');
    var like_width = $('[qid="post-actionbar-like-wrapper"]').filter((k,v) => $(v).width() != 0).width();
    if (like_width == 0) like_width = 60;
    $.each( edits, function( key, val ) {
        $(this.parentElement.parentElement).css("padding-right",like_width);
    });

     // 1/1/2024 remove the skimresources links -- shhhh-- don't tell anyone or post about it. Don't want to anger the gods :) 
	 // might be buggy
	 // if you have questions or bug fixes, please PM me. 
	 $.each( $('a'), function(key,val ) {
		 var link=$(this).attr("href");
		 if (link) {
			 if (link.indexOf("skimresources")>0) {
				 var loc=link.indexOf("sref=");
				 var newlink= decodeURIComponent(link.substr(loc+5));
				 console.warn(newlink);
				 $(this).attr("href",newlink);
		 }
		 }
	 });

	
    // color political forum threads with red background
    $.each( $('[itemprop="item"]'), function( ) {
        if ($(this).attr("href").indexOf("political-talk.63")>0 || $("title").text().indexOf("Political Talk")>0) {
            $(".p-body").attr("style","background: linear-gradient(79deg, #c10808, transparent);");
        }});

     if ($("title").text().indexOf("Political Talk")!=-1) {
           $(".p-body").attr("style","background: linear-gradient(79deg, #c10808, transparent);");
      }

    // add location to user-bit area
    // dswallow bug fix
    // morac contribution to change userbit on orientation change on mobile
	$.each( $(".userbit-info"), function( key, val ) {
         if ($(val).children().length>3) {  
            var h=(val.children[3].attributes.title.nodeValue);
            if (h!="") val.children[2].innerHTML+="&nbsp;<span class='user-port'> "+h+"</span><span class='user-land'><br>"+h+"</span>";
         }
     });
    function addLocation(aEvent) {
        var landscape = aEvent ? (aEvent.orientation == "landscape") : window.matchMedia("(orientation: landscape)").matches;
		if (landscape) {$(".user-land").show();$(".user-port").hide();}
		else {$(".user-port").show();$(".user-land").hide();}
    }
	$(window).on("orientationchange",addLocation);
    addLocation();

    // add edit link to action bar after edit or new post
	$( document ).on( "click", '#edit-thread-save-button,[qid="quick-reply-post-submit"]', function(e) {
	  setTimeout(function () {
			 movelinks();
      },2000);
	});

function movelinks() {
	var edits=$('[data-xf-click="quick-edit"]');
	$.each( edits, function( key, val ) {
		var editlnk=$(this);
		var id=editlnk.attr("href");
		var newid=id.replace("edit","bookmark");
		$(this).prepend("&#9998;");
		$('[href="'+newid+'"').parent().append(editlnk);
		$('.menu-linkRow').css("margin-top","3px");
	});
	$('[qid="action-bar-section"]').css("float","right");
}

   var ignorelist=[];
	var page= window.location.href;
   	if (
   	    page.search("threads")!=-1 || 
   	    page.search("discussions")!=-1 ||
   	    page.search("forums")!=-1 ||
   	    page.search("watched")!=-1 ||
   	    page.search("whats-new")!=-1) {
      	$.ajax({
    	type: 'post',
		    url: 'https://lexbrook.com/tcf/list.php',
		    dataType: 'json',
		    data: {
    			action: 'list',
			    user: $(".avatar--xxs").data("user-id")
		    },
		    complete:  function(response) {
    			ignorelist=response.responseJSON;
			    processthreads();
		    },
		    success: function (response) {},
		    error:function(XMLHttpRequest,status,error){ alert("AJAX error in processthreads"); console.log("Ajax error:",error); console.log(" Ajax Status:",status);	}
	    });
	}

	function processthreads() {
    // open threads in new window with infinitey icon
	 $.each( $('[qid="thread-item-title"]'), function() {
		$(this).parent().append('&nbsp;&nbsp;<a title="Open thread in new browser window" target=_blank href="'+$(this).attr("href")+'">&nbsp;&nbsp;&infin;&nbsp;&nbsp;</a>');
		var title=$(this).html();
		var cls=$(this).parent().parent().parent().attr('class');
		var pos=cls.search("js-threadListItem-");
		var id=parseInt(cls.substr(pos+18,7));
         if (ignorelist.indexOf(id)!=-1) {
			 $(this).parent().append('&nbsp;&nbsp;<a title="Unignore Thread" style="font-size: 8px;vertical-align: top;" class="ignore" data-action="unignore" data-threadid="'+id+'" data-title="'+encodeURI(title)+'" >&nbsp;&nbsp;&#9989;&nbsp;&nbsp;</a>');
			 $(this).parent().parent().parent().addClass("ignored--thread").hide();
		} else {
			$(this).parent().append('&nbsp;&nbsp;<a title="Ignore Thread" style="font-size: 8px;vertical-align: top;" class="ignore" data-action="ignore" data-threadid='+id+' data-title="'+encodeURI(title)+'" >&nbsp;&nbsp;&#10060;&nbsp;&nbsp;</a>');
			$(this).parent().parent().parent().removeClass("ignored--thread").show();

		}
	 });
	}

    var ignoretimout;
	$( document ).on( "click", '.ignore', function(e) {
        var elm=$(this);
	  	$.ajax({
			type: 'post',
			url: 'https://lexbrook.com/tcf/save.php',
			dataType: 'json',
			data: {
				action: $(this).data("action"),
				id:$(this).data("threadid"),
				title:$(this).data("title"),
				user: $(".avatar--xxs").data("user-id")
			},
			complete:  function(response) {
				//var reply=response["responseJSON"];
				if (elm.data("action")=="ignore") {
					elm.html("Ignored").data("action","unignore");
					ignoretimout=setTimeout(function() {
							   elm.parent().parent().parent().addClass("ignored--thread").slideUp();
				},2000);
				} else {
					clearTimeout(ignoretimout);
					elm.html("Unignored");
				}
			},
			success: function (response) {},
			error:function(XMLHttpRequest,status,error){ alert("AJAX error in .ignore"); console.log("Ajax error:",error); console.log(" Ajax Status:",status);	}
		});
	});


	movelinks();

	// add link to user posts
	$.each($('[qid="message-number-of-posts"]'), function() {
        let x_member_a = $($(this).parent().parent()).find('.username');
		$(this).html('<a title="Latest Activity" target=_blank href="'+x_member_a.attr("href")+'#latest-activity">'+$(this).html()+'</a>');
    });


    //color read threads as reduced opaticy
    $('.structItem--is-read').parent().parent().parent().css("opacity","0.55");
	// mark clicked on threads that open up in a new window as read
	$( document ).on( "click", '[qid="thread-item-title"]', function(e) {
		 $(this).parent().parent().parent().css("opacity","0.55");
	});

    //hide read threads if localstorage is set to 1 or undefined

    if (localStorage.showthreads=="hide" || localStorage.showthreads==undefined) {
	     setTimeout(function () {
          $('.structItem--thread:not(".is-unread")').hide();
          $(".showunread").html("Show Read Threads");
		  localStorage.showthreads="hide";
      },500);// hide  all read threads after 1/2 second
    } else {$(".showunread").html("Hide Read Threads");}


	$(".showunread").on('click', function() {
		if (localStorage.showthreads=="hide") {
			$(".showunread").html("Hide Read Threads");
			$('.structItem--thread:not(".ignored--thread")').slideDown();
			localStorage.showthreads="show";
		}
		else {
			$(".showunread").html("Show Read Threads");
			$('.structItem--thread:not(".is-unread")').slideUp();
			localStorage.showthreads="hide";
		}
	});


	if (localStorage.hidepreviews==1) {
		// thanks to laria for this...
		$('<style>').text('.memberTooltip,.tooltip.tooltip--preview { display: none !important; }').appendTo('head');
		$(".toggletooltips").html("Enable Tooltip Previews");
	}
	else {
		$(".toggletooltips").html("Disable Tooltip Previews");
	}

	$(".toggletooltips").on('click', function() {
		// for some reason I can't figure out, 'localStorage.hidepreviews=!localStorage.hidepreviews;' doesn't work
		// so I have to do it this kludged way. And yes, I tried all the true/false versions instead of 1/0. 
		if (localStorage.hidepreviews==1) {localStorage.hidepreviews=0;}
		else {localStorage.hidepreviews=1;}
		location.reload();
	});

	$("#showignored").on('click', function() {
			$('.ignored--thread').slideDown();
	});

	
/*
  ignore... saved here for future use
	$("#newtabs").on("click",function() {
		$("#footer").html("<a href=# id='newtabs'>Open links in same tab</a>");
		if ( localStorage.newtabs==undefined || localStorage.newtabs==1) {
			localStorage.newtabs=2
		}
		if ( localStorage.newtabs==2) {
			$("#footer").html("<a href=# id='newtabs'>Open links in new tab &nbsp;&nbsp;&infin;</a>");
			localStorage.newtabs=1;
		}
		location.reload();
	});

	if (localStorage.newtabs==undefined || localStorage.newtabs==1)
		$("#footer").html("<a href=# id='newtabs'>Open links in new tab</a>");
		else
		$("#footer").html("<a href=# id='newtabs'>Open links in same tab</a>");
	if (localStorage.newtabs==2) {
	       //$(this).html($(this).html()+"&nbsp;&nbsp;&infin;").attr("target","_blank");
*/



})();