Envato Forum Oldy

Styles new envato forum to resamble more to old one

当前为 2015-08-26 提交的版本,查看 最新版本

// ==UserScript==
// @author 		DJMiMi
// @name        Envato Forum Oldy
// @namespace   envato_forum
// @description Styles new envato forum to resamble more to old one
// @include     https://forums.envato.com/
// @require		http://code.jquery.com/jquery-2.1.4.min.js
// @version     1
// @grant       none
// ==/UserScript==

jQuery(document).ready(function($){
	$('body').append(
		'<style>.organized-posters{ position: relative; display: inline-block; vertical-align: middle; } \
		.organized-posters a:first-child, .organized-posters a.latest:first-child{ display: block; position: relative; bottom: auto; right: auto; } \
		.organized-posters a:first-child, .organized-posters a:first-child img{ height: 75px; width: 75px } \
		.main-link .title{width: calc(100% - 120px); vertical-align: middle; display: inline-block; margin-left: 10px; padding: 0px;} \
		.topic-list .topic-list-item .discourse-tags{ margin-top: 15px } \
		.new-topic {display: none} \
		.organized-posters .latest{ position: absolute; bottom: 0px; right: 0px }</style>'
	);
	
	function organize_tr( $this ){
		$this.addClass('organized');
		$this.find('td').css('padding', '30px 15px');
		var $first = $this.find('.posters a:first').clone();
		var $last = $this.find('.posters a.latest').clone();
		
		$this.find('td:first').prepend( '<div class="organized-posters"></div>' );
		$this.find('.organized-posters').append( $first );
		$this.find('.organized-posters').append( $last );
		$this.find('.organized-posters a:first img').attr('src', $this.find('.organized-posters a:first img').attr('src').replace('25','75') );	
	}
	
	waitForKeyElements (".ember-view.topic-list tbody tr", organize_tr);
	
	function waitForKeyElements (
		selectorTxt,    /* Required: The jQuery selector string that
							specifies the desired element(s).
						*/
		actionFunction, /* Required: The code to run when elements are
							found. It is passed a jNode to the matched
							element.
						*/
		bWaitOnce,      /* Optional: If false, will continue to scan for
							new elements even after the first match is
							found.
						*/
		iframeSelector  /* Optional: If set, identifies the iframe to
							search.
						*/
	) {
		var targetNodes, btargetsFound;

		if (typeof iframeSelector == "undefined")
			targetNodes     = $(selectorTxt);
		else
			targetNodes     = $(iframeSelector).contents ()
											   .find (selectorTxt);

		if (targetNodes  &&  targetNodes.length > 0) {
			btargetsFound   = true;
			/*--- Found target node(s).  Go through each and act if they
				are new.
			*/
			targetNodes.each ( function () {
				var jThis        = $(this);
				var alreadyFound = jThis.data ('alreadyFound')  ||  false;

				if (!alreadyFound) {
					//--- Call the payload function.
					var cancelFound     = actionFunction (jThis);
					if (cancelFound)
						btargetsFound   = false;
					else
						jThis.data ('alreadyFound', true);
				}
			} );
		}
		else {
			btargetsFound   = false;
		}

		//--- Get the timer-control variable for this selector.
		var controlObj      = waitForKeyElements.controlObj  ||  {};
		var controlKey      = selectorTxt.replace (/[^\w]/g, "_");
		var timeControl     = controlObj [controlKey];

		//--- Now set or clear the timer as appropriate.
		if (btargetsFound  &&  bWaitOnce  &&  timeControl) {
			//--- The only condition where we need to clear the timer.
			clearInterval (timeControl);
			delete controlObj [controlKey]
		}
		else {
			//--- Set a timer, if needed.
			if ( ! timeControl) {
				timeControl = setInterval ( function () {
						waitForKeyElements (    selectorTxt,
												actionFunction,
												bWaitOnce,
												iframeSelector
											);
					},
					300
				);
				controlObj [controlKey] = timeControl;
			}
		}
		waitForKeyElements.controlObj   = controlObj;
	}
});