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/*
// @version     1.1
// @grant       none
// ==/UserScript==

document.querySelectorAll('body')[0].innerHTML +='<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 { position: relative } \
	.topic-post-badges{ position: absolute; display: block; top: 10px; left: 10px; } \
	.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 a:last-child{ position: absolute; bottom: 0px; right: 0px }</style>';

function organize_tr( $this ){
	$this.classList.add('organized');
	var tds = $this.querySelectorAll('td');
	for ( var i = 0; i < tds.length; ++i) {
		tds[i].style.padding = '30px 15px';
	}
	
	var posters = $this.querySelectorAll('.posters a');
	var $first = posters[0].cloneNode(true);
	var $last = posters[posters.length - 1].cloneNode(true);
	
	var parent = $this.querySelectorAll('td')[0];
	var child = document.createElement("div");
	child.className = 'organized-posters';
	parent.insertBefore(child, parent.firstChild);
	
	var organizedPosters = $this.querySelector('.organized-posters');
	organizedPosters.appendChild( $first );
	organizedPosters.appendChild( $last );
	
	var image = $this.querySelectorAll('.organized-posters a')[0].querySelector('img');
	image.setAttribute('src', image.getAttribute('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     = document.querySelectorAll(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.
		*/
		for ( var i = 0; i < targetNodes.length; ++i) {
			var jThis = targetNodes[i];
			var alreadyFound = jThis.dataset.alreadyFound  ||  false;

			if (!alreadyFound) {
				//--- Call the payload function.
				var cancelFound     = actionFunction (jThis);
				if (cancelFound){
					btargetsFound   = false;
				}
				else{
					jThis.dataset.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;
}