HankLloydright / TCF 2022 Mods Beta Channel

// ==UserScript==
// @name         TCF 2022 Mods Beta Channel
// @namespace    http://tampermonkey.net/
// @version      0.0.28
// @description  Restore some links/looks from the old TCF
// @author       HankLloydRight
// @include      https://www.tivocommunity.com/*
// @grant        none
// @license      MIT
// html symbol reference: https://www.w3schools.com/charsets/ref_utf_symbols.asp
// ==/UserScript==
(function() {

    'use strict';
// .hScroller-scroll ==> following page
// .california-upper-page-nav ==> thead page
// .california-filter-container ==> forum page/thread list
    $('.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;'+
                  '<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;');

	$('#footer').html('<a style="" class="showignored tabs-tab">Show Ignored Threads</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
	$('[qid="thread-position-footer"]').prepend($(".button-group").html()+"&nbsp;&nbsp;&nbsp;");


    // 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
    $.each( $(".userbit-info"), function( key, val ) {
        var h=(val.children[3].attributes.title.nodeValue);
        if (h!="") val.children[2].innerHTML+="<br>"+h;
     });

    // 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();
      },1500);
	});

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=[];
  	$.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:"+error+" 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="'+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="'+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:"+error+" 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";
      },100);  // 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";
		}
	});

		$(".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");
*/



})();