• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Maps - "Type" Column

Status
Not open for further replies.

WMA

WMA

Level 1
Joined
Jan 17, 2011
Messages
1
This is my first term visiting the proper forum section of this board - so forgive me if this is in the wrong area.

I've always been a avid downloader of maps from here, but one feature I've always wanted was a little column describing the map 'Type' for uploaded maps (similar to the 'Rating' and 'Time' columns).

Having some free time this afternoon, I decided to see if anyone had written a Greasemonkey script.

Unfortunately, I couldn't find anything - so I decided to write my own.

Firstly - I'm horrible at JavaScript. I only ever use it for throwing together ugly hacks in Greasemonkey, and the way I've written this script is bad (No error catching, assumed node structure, null references galore, grabbing of entire webpages! - Oh, and it also injects JQuery into the page because I couldn't figure out how to get it to work).

That said, I thought I would share my script here for other people to use. Simply put this in a file called "HiveWorkshop.user.js" and open with a browser that supports User Script extensions, and you should be good to go.

Please note: I measured the bandwidth, and on standard settings (20 map hits per page) this script uses roughly 10x the bandwidth (I.e. it pulled around 1.2MB of data, as opposed to the standard ~120KB).
Preview:

Code:
// ==UserScript==
// @name        Hiveworkshop Map Types
// @description Shows Map Type
// @include     http://www.hiveworkshop.com/forums/maps.php*
// ==/UserScript==

	function letsJQuery () {

	function getElementsByClass(searchClass,node,tag) {
		var classElements = new Array();
		if ( node == null )
			node = document;
		if ( tag == null )
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
		for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	};


	function populate_types() {
	   if (count >= (els.length)) {
	       return;
	   }
	   var entry = els[count++];
	   var ref = entry.children[1].children[1].getAttribute('href');
	   $.get(ref, function(response) {
		 // var type = response.match(/Type:.*?<\/span>/)[0].match(/<span.*/); // Doesn't match comma's.
                 var type = response.match(/Type:<\/td>.*?<\/td>/)[0].match(/<span.*/);
		 entry.innerHTML += '<td class="alt1">' + type + '</td>';});
	   populate_types();
	};

	var els = getElementsByClass('tborder')[3].getElementsByTagName('tbody')[0].children;
	var count = 2;

	els[0].getElementsByTagName('td')[0].setAttribute('colspan', '6');
	els[1].innerHTML += '<td class="thead" width="10%"> Type </td>';
	populate_types();
}
var jQuery = document.createElement("script"),
    inject = document.createElement("script");

jQuery.setAttribute("type", "text/javascript");
jQuery.setAttribute("src", "http://code.jquery.com/jquery-latest.js");

inject.setAttribute("type", "text/javascript");
inject.appendChild(document.createTextNode("(" + letsJQuery + ")()"));

document.body.appendChild(jQuery);
document.body.appendChild(inject);

Edit: Fixed issue with multiple map types.
 
Last edited:
Status
Not open for further replies.
Top