thebob / Dashgum Modifications

// ==UserScript==
// @name        Dashgum Modifications
// @namespace   b3eb33c8741512e49c51ce31d4ec2861
// @include     http://*shazbat.tv/*
// @include     https://*shazbat.tv/*
// @version     1.3.12
// @grant       unsafeWindow
// @updateURL   https://openuserjs.org/meta/thebob/Dashgum_Modifications.meta.js
// @downloadURL https://openuserjs.org/install/thebob/Dashgum_Modifications.user.js
// ==/UserScript==

    var $jQ = unsafeWindow.jQuery;

    $jQ("<style type='text/css'> li.mt { margin-top: 10px !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> .notices { margin-left: 10px !important; } </style>").appendTo("head");
    $jQ("<style type='text/css'> span.message { white-space: normal !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> ul.dropdown-menu.extended.inbox { width: 340px !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> #motd { left: -175px !important; top: 45px !important; width: 500px !important; height: 15px !important; overflow: hidden !important;}</style>").appendTo("head");
    $jQ("<style type='text/css'> .header { height: 65px !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> #search { width: 200px !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> .notify-row { margin-left: -340px !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> ul.top-menu { margin-top: 5px !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> #chat-col { padding: 7px 7px 0px 7px !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> .ds { margin-left: 10px !important; margin-top: 10px !important; width: 250px !important; } </style>").appendTo("head");
    $jQ("<style type='text/css'> div#sidebar { width: 270px !important; opacity: 1 !important; } </style>").appendTo("head");
    $jQ("<style type='text/css'> .sidebar-closed { margin-left: -60px !important; } </style>").appendTo("head");
    $jQ("<style type='text/css'> .sidebar-closed #sidebar  { display: none !important; } </style>").appendTo("head");
    $jQ("<style type='text/css'> section#container.sidebar-closed { width: 106% !important; } </style>").appendTo("head");
    $jQ("<style type='text/css'> .main-chart { float: left !important; padding-left: 20px !important; min-width: 90% !important;} </style>").appendTo("head");
	$jQ("<style type='text/css'> .show .play { display: none !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> #rightbar { width:  !important; } </style>").appendTo("head");
    $jQ("<style type='text/css'> .chatrow { overflow-x: hidden !important; } </style>").appendTo("head");
    $jQ("<style type='text/css'> .searchbar-int { margin-left: 55px !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> #middle-content { margin-left: 50px !important; } </style>").appendTo("head");
    $jQ("<style type='text/css'> #watermark, span#unseededlist { display: none !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> #unseeded { width: 100% !important; }</style>").appendTo("head");
    $jQ("<style type='text/css'> #unseeded button { float: right !important; font-size: 11px !important; padding: 3px 9px !important; }</style>").appendTo("head");
	$jQ("<style type='text/css'> ul.sidebar-menu li a { padding: 5px 0 5px 10px !important; }</style>").appendTo("head");
	$jQ("<style type='text/css'> span#username { padding-left: 6px; color: #F2F2F2; font-weight: 700; font-size: 14px; }</style>").appendTo("head");
	$jQ("<style type='text/css'> a.followed { color: #385380 !important; }</style>").appendTo("head");
		
    var headerlink = $jQ('header.header a.internal');
		headerlink.attr("id","headerlink");
		
	var motd = headerlink.children("span");
        motd.addClass("hidden-xs");
        motd.addClass("visible-sm");
        motd.addClass("visible-md");

    // reformat notices
    var notices = $jQ('ul#nav-accordion span').first();
    notices.attr("id","notices");
    notices.addClass("notices");

    // grab username and remove it from it's current position
    var username = $jQ('h5.centered').first().text();
    $jQ("h5.centered").first().text("");

    // resize user icon and place username to the right
    var usericon = $jQ('p.centered a.internal');
    	usericon.children(0).attr("width","30");
    	usericon.append('<span id="username">' + username + '</span>');

    // hide searchbar ONLY when screenwidth is really narrow
    var searchbar = $jQ('#top_menu.nav.notify-row.pull-right');
    searchbar.removeClass("hidden-md");
    searchbar.addClass("visible-md");
    searchbar.addClass("visible-sm");

    // now update internal searchbar to only show
    var searchbar = $jQ('section.wrapper div.showback').first();
    searchbar.removeClass("visible-md");
    searchbar.addClass("searchbar-int");
    searchbar.attr("id","searchbar-int");

    var nav = $jQ("#nav-accordion");
    var chatcol = $jQ('div#rightbar div').first();
    chatcol.attr("id","chat-col");
    chatcol.removeClass("col-lg-3");
    chatcol.addClass("col-sm-3");

    var rightcol = $jQ('div#rightbar');
    rightcol.appendTo("#nav-accordion");

    // Add a filter to show only unseeded torrents on the "My Torrents" page:
	var target = document.querySelector("div#middle-content");
	var tmpMutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
	new tmpMutationObserver(lookForTorrentsPage).observe(target, { childList: true, subtree: true });
	
	function lookForTorrentsPage(){
		if ($jQ("div.showback h4").text() == "Torrents"){	
			var unseedButton = $jQ("div#unseeded button");
			if (unseedButton.length === 0) {
				addUnseededFilter();
			} 
		}
	}
	
    function addUnseededFilter(){
		$jQ('<div id="unseeded"><button>Unseeded</button></div>').insertAfter( $jQ("div.showback h4") );
		var unseedButton = $jQ("div#unseeded button");
		
		$jQ("div#unseeded button").click(function(){
		  if (unseedButton.text() == "Unseeded"){
			$jQ("#torrent-table tr.eprow, table.table.table-striped.table-advance tr").not('.highlight').hide();
			unseedButton.text("Show All");
		  } else {
			$jQ("#torrent-table tr.eprow, table.table.table-striped.table-advance tr").not('.highlight').show();			
			unseedButton.text("Unseeded");
		  }
		});
	}
	
	// load unseeded filter if we're landing on the "my torrents" page
	lookForTorrentsPage();
   

   // fix typo for in /assets/js/common-scripts.js (close => closed):
   function respView(){
    var wSize=$jQ(window).width();
    if(wSize<=768){$jQ('#container').addClass('sidebar-closed');$jQ('#sidebar > ul').hide();}
    if(wSize>768){$jQ('#container').removeClass('sidebar-closed');$jQ('#sidebar > ul').show();}
   }
   
   $jQ(window).on('load',respView);
   $jQ(window).on('resize',respView);
   
   
   // Changelog:
   // v1.3.12 - defaulted [annoying] unseeded torrent list (main window) to display:none. "unseeded warning" still shows up under star rank.