All pastes #347863 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-02-09 19:29 UTC
rendered paste body
// ==UserScript==
// @name          CCE+
// @namespace     http://www.dvdmypictures.com
// @source        http://userscripts.org/scripts/show/6982
// @identifier    http://userscripts.org/scripts/source/6982.user.js
// @version       2.0
// @date          2007-01-19
// @include		http://ev5.neondragon.net/*
// @include		http://evo-dev.neondragon.net/*
// @include			http://ev5.neondragon.net/*
// @include			http://evo-dev.neondragon.net/*
// @author			Pipes
// ==/UserScript==

// ***************************************************************************
// ** Global Variables
// ***************************************************************************

const scriptversion = '0.1';
const scriptversionID = '[CCE]evo+ ' + scriptversion;
const scriptTag = 'Play The Piper';
GM_log(scriptversionID + " start");

// safegard
if(! unsafeWindow.evo_plus ) {
	alert("Improper installation. Please uninstall evo+ AND nEvo+, then install:\n- evo+\n- nEvo+\nIn that order.");
	return;
}

// page handlers
var pageHandlers = new Array();

var contents = null; // pointer to the 'content' node in the page

// imported vars
var units = unsafeWindow.evo_plus.units; // units :P
var pMetal = unsafeWindow.evo_plus.pMetal;
var pMineral = unsafeWindow.evo_plus.pMineral;
var pFood = unsafeWindow.evo_plus.pFood;
var pScore = unsafeWindow.evo_plus.pScore;
var eeb = Number(GM_getValue('eeb', 1)); // efficient breeding center ratio

// constants
var FOODCOST = 91;

// evo, devo?
var dEvo = /^http:\/\/evo-dev\./.test(document.location.href);

//
// ***************************************************************************
// ** Page handlers
// ***************************************************************************


const boostally = boostally;



(function() {  



var words = new Array();

var bgColors = new Array();

var fgColors = new Array();



/* Add your own "words" to this "list", in the same format.  The next word would be 

 * words[2] = "some word or phrase" 

 * add more colors, too

 * if there is no color corresponding to the word (no bgColors[4] for words[4]) the first (bgColors[0]) will be used

 * The words are should be written in all caps, but the word matching is not case sensitive */

 

var ally = "[CCE]|[NOD]";
var allyColor = "skyblue";
var enemy = "[PHI]|[{rnb}]";
var enemyColor = "red";
var nap = "[KWH]|[WTF]";
var napColor = "orange";

theAllies = ally.split("|");
for (z = 0; z <= theAllies.length; z++){
if (theAllies[z] == undefined) continue;
words[words.length] = theAllies[z].toUpperCase();
bgColors[bgColors.length] = allyColor;
}

theNAPs = nap.split("|");
for (z = 0; z <= theNAPs.length; z++){
if (theNAPs[z] == undefined) continue;
words[words.length] = theNAPs[z].toUpperCase();
bgColors[bgColors.length] = napColor;
}

theEnemys = enemy.split("|");
for (z = 0; z <= theEnemys.length; z++){
if (theEnemys[z] == undefined) continue;
words[words.length] = theEnemys[z].toUpperCase();
bgColors[bgColors.length] = enemyColor;
}


words[words.length] = "[CCE]"; 

bgColors[bgColors.length] = "";

fgColors[fgColors.length] = "yellowgreen";



words[words.length] = "---";

bgColors[bgColors.length] = "lightGreen";

fgColors[fgColors.length] = "Black";



// Leaders

words[words.length] = "BEREFT OF";

bgColors[bgColors.length] = "lightblue";

fgColors[fgColors.length] = "Black";



words[words.length] = "DRACON7";

bgColors[bgColors.length]= "lightblue";

fgColors[fgColors.length] = "Black";



words[words.length] = "MUNCH OF";

bgColors[bgColors.length] = "lightblue";

fgColors[fgColors.length] = "Black";





// Rebel Guard

words[words.length] = "MURF OF CATHAL";

bgColors[bgColors.length] = "White";

fgColors[fgColors.length] = "Black";



words[words.length] = "SCORPATTARIUS OF";

bgColors[bgColors.length] = "White";

fgColors[fgColors.length] = "Black";



words[words.length] = "GEARJAMMER OF";

bgColors[bgColors.length] = "White";

fgColors[fgColors.length] = "Black";





words[words.length] = "PIPES6969";

bgColors[bgColors.length] = "White";

fgColors[fgColors.length] = "Black";



words[words.length] = "THE1STVOICE";

bgColors[bgColors.length] = "White";

fgColors[fgColors.length] = "Black";





 for(var i = 0; i < words.length; i++) { 

  var xpath = "//a[contains(translate(.,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),'"+words[i]+"')]";

  var results = document.evaluate(xpath, document, null, XPathResult.UNORDERED_SNAPSHOT_TYPE, null);

  var items = new Array();

  var thisItem = results.iterateNext();

  while(thisItem) { items.push(thisItem); thisItem = results.iterateNext(); }



  for(var ii = 0; ii < items.length; ii++) {  

   items[ii].style.backgroundColor = bgColors[i]?bgColors[i]:bgColors[0];

   items[ii].style.color = fgColors[i]?fgColors[i]:fgColors[0];

  }  

 }



})()





function do_platypus_script() {

html_insert_it(window.document,document.evaluate('/HTML[1]/BODY[1]/DIV[1]/DIV[1]/DIV[4]/DIV[2]/UL[1]/LI[1]/A[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,'<li><a href="http://www.aokforums.com/confederatedcon/">Off Site Forum</a></li><li><a href="http://www.dvdmypictures.com/EVO/CCE/Mass-High-Guard.html">Mas.Msg (High Guard)</a></li><li><a href="http://www.dvdmypictures.com/EVO/CCE/AllAlliance.htm">Mas.Msg (Alliance)</a></li>',true,false);

html_insert_it(window.document,document.evaluate('/HTML[1]/BODY[1]/DIV[1]/DIV[1]/DIV[3]/DIV[2]/UL[1]/LI[4]/A[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,'       <li><a href="http://www.ev5.mtggreer.com/">Att / Def Calc</a></li>       <li><a href="http://www.ev5.mtggreer.com/coord.php">Launch Table Calc</a></li>',false,false);

html_insert_it(window.document,document.getElementById('gametime'),'<iframe width="170" height="140" src="http://www.geocities.com/solarbusinessman75/CCE/CCE_newstic.html" SCROLLING="no" FRAMEBORDER="0" border=0></iframe>',false,false);

}; // Ends do_platypus_script

window.addEventListener("load", function() { do_platypus_script() }, false);

//

//  Mon Dec 19 15:59:37 2005 -- Scott R. Turner

//  Short, uncommented file containing all the code to implement Platypus

//  actions.  Can be "included" into the Platypus script.

//

// 

// 

function walk_down(node, func) {

  if (node.nodeType == 1) {

    if (node.tagName != "IMG") func(node);

    if (node.childNodes.length != 0)

      for (var i=0; i<node.childNodes.length; i++)

walk_down(node.childNodes.item(i),func);

  }

}

function make_bw(doc, node) {

  walk_down(node,

            function (node) {

      if (node.tagName != 'A') {

  node.bgcolor = "white";

  node.color = "black";

  node.style.backgroundColor = "white";

  node.style.color = "black";

  node.style.backgroundImage = "";

      }});

}

function center_it(doc, node) {

  var center_node = doc.createElement ("CENTER");

  node.parentNode.insertBefore(center_node, node);

  node.parentNode.removeChild(node);  

  center_node.appendChild(node);

  return center_node;

};

function erase_it(doc, node) {

  var offset_height = node.offsetHeight;

  var offset_width = node.offsetWidth;

  var replacement_div = doc.createElement ("DIV");

  replacement_div.setAttribute('style',

       "height: "+offset_height+"; width: "+offset_width+";");

  node.parentNode.insertBefore(replacement_div, node);

  node.style.display = "none";

  return replacement_div;

};

function smart_remove(doc, node) {

    if (node.parentNode.childNodes.length == 1) {

smart_remove(doc, node.parentNode);

    } else {

remove_it(doc, node);

    };

};

function remove_it(doc, node) {

  if (doc == null || node == null) return;

  if (!node.parentNode) return;

  node.style.display = "none";

  doc.last_removed_node = node;

};

function script_paste(doc, where, what) {

    var new_node = what.cloneNode(true);

    new_node.style.display = "";

    where.parentNode.insertBefore(new_node, where);

};

function isolate(doc, node) {

  if (!node.parentNode) return;

  node.parentNode.removeChild(node);

  while (doc.body.childNodes.length > 0) {

    doc.body.removeChild(doc.body.childNodes[0]);

  };

  var replacement_div = doc.createElement ("DIV");

  replacement_div.setAttribute('style',

       "margin: 0 2%; text-align: left");

  replacement_div.appendChild(node);

  doc.body.appendChild(replacement_div);

};

function set_style_script(doc, element, new_style) {

    element.setAttribute('style', new_style);

};

function modify_single_url(doc, match_re, replace_string, node) {

    if (node.href) {

node.href = node.href.replace(match_re, replace_string);

    };

};

function do_modify_url_it(doc, node, match_re, replace_string, global_flag) {

    match_re = new RegExp(match_re);

    if (global_flag) {

var allurls = doc.getElementsByTagName('A');

for(var i = 0, url; url = allurls[i]; i++)

  modify_single_url(doc, match_re, replace_string, url);

    } else {

modify_single_url(doc, match_re, replace_string, node);

    };

};

function do_modify_html_it(doc, element, match_re, replace_string) {

    match_re = new RegExp(match_re);

    if (element.innerHTML) {

element.innerHTML = element.innerHTML.replace(match_re, replace_string);

    };

};

function relax(doc, node) {

  walk_down(node, function (node) {

      node.style.width = 'auto';

      node.style.marginLeft = '0pt';

      node.style.marginRight = '0pt';

      if (node.width) node.width = null; });

}

function fix_page_it(doc, node) {

    doc.background = null;

    doc.bgColor = "white";

    if (doc.style) {

      doc.style.backgroundColor = "white";

      doc.style.backgroundImage = "none";

      if (doc.style.color == "white") {

doc.style.color = "black";

      };

      if (doc.text == "white") {

doc.text = "black";

      };

    };

    doc.body.background = null;

    doc.body.bgColor = "white";

    if (doc.body.style) {

      doc.body.style.backgroundColor = "white";

      doc.body.style.backgroundImage = "none";

      if (doc.body.style.color == "white") {

doc.body.style.color = "black";

      };

      if (doc.body.text == "white") {

doc.body.text = "black";

      };

    };

};

function insertAfter(newNode, target) {

    var parent = target.parentNode;

    var refChild = target.nextSibling;

    if(refChild != null)

parent.insertBefore(newNode, refChild);

    else

parent.appendChild(newNode);

};

function html_insert_it(doc, element, new_html, before, insert_as_block) {

  var new_element;

  if (insert_as_block) {

    new_element = doc.createElement ("DIV");

  } else {

    new_element = doc.createElement ("SPAN");

  };

  new_element.innerHTML = new_html;

  if (before) {

      element.parentNode.insertBefore(new_element, element);

  } else {

      insertAfter(new_element, element);

  };

};

function auto_repair_it(doc, node) {

  var biggest_elem = find_biggest_elem(doc);

  isolate(doc, biggest_elem);

  relax(doc, biggest_elem);

  make_bw(doc, biggest_elem);

  fix_page_it(doc, biggest_elem);

};

function find_biggest_elem(doc) {

  const big_element_limit = 0.25;

  var size_of_doc = doc.documentElement.offsetHeight *

      doc.documentElement.offsetWidth;

  var body = doc.body;

  var size_of_body = body.offsetHeight * body.offsetWidth;

  if (size_of_body < (0.80 * size_of_doc)) {

      size_of_body = size_of_doc;

  };

  var max_size = 0;

  var max_elem = doc;

  var allElems = document.evaluate("//*",

 doc.body, null,

 XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,

 null);

  for (var i = 0; i < allElems.snapshotLength; i++) {

    var thisElem = allElems.snapshotItem(i);

    var thisElem_size = thisElem.offsetHeight * thisElem.offsetWidth;



    if (thisElem_size < size_of_body &&

thisElem_size > max_size &&

!contains_big_element(thisElem, size_of_body * big_element_limit)) {

      max_size = thisElem_size;

      max_elem = thisElem;

    };

  };

  return max_elem;

};



function contains_big_element(node, limit) {

    if (node.childNodes.length != 0)

for (var i=0; i<node.childNodes.length; i++) {

    var child = node.childNodes.item(i);

    var child_size = child.offsetHeight * child.offsetWidth;

    if (child_size > limit) return true;

};

    return false;

};



function platypus_do(win, func_name, o, other, other2, other3) {

    var func = eval(func_name);

    var doc = null;

    if (func == null) return;

    if (!o) {

Warning("Platypus couldn't find a page element when executing the command "+

func_name+".  This usually happens when running a script -- maybe the"+

" web page the script is running on has changed.");

    };

    doc = win.document;

    func(doc, o, other, other2, other3);

};

//
// ***************************************************************************
// ** MAIN
// ***************************************************************************
//
(function () {
	var node;

	// Initialization
	// -----------------------------------------------------------------------
	// contents node
	contents = document.getElementById("content");

	// get out of the bloody forums message editor
	if( contents == null ) return;

	// Dispatch
	// -----------------------------------------------------------------------
	for(var i = 0; i < pageHandlers.length; i++ ) {
		if( pageHandlers[i].urlRegEx == null || pageHandlers[i].urlRegEx.test(document.location.pathname) )
			pageHandlers[i].handler();
	}

	node = document.getElementById('evomagik');
	if (node){
	node.appendChild(document.createElement('br'));
	node.appendChild(document.createTextNode(scriptversionID));
	}
	// fix a bug in evo with non existent adverts that prevent the use of the top panel 
	if(! (node = document.getElementById('advert')) ) {
		node = document.createElement('span');
		node.id = 'advert';
		contents.appendChild(node);
	}
}) ();

// ***************************************************************************
// ** Helper functions
// ***************************************************************************

function evoLayoutChanged() {
	alert('Oops.. Page layout was not recognized, Neon probably changed the page :(');
}

function evoNumber2String(num) {
	var re = /(\d+)(\d{3})/g;

	num = String(num);
	var decimalIdx = num.indexOf('.');
	var part1 = '1', part2="";
	if( decimalIdx != -1 ) {
		part1 = num.substring(0, decimalIdx);
		part2 = num.substring(decimalIdx + 1, num.length);
	}
	else
		part1 = num;

	while( re.test(part1) )
		part1 = part1.replace(re, '$1,$2');

	return part2 == "" ? part1 : part1 + "." + part2;
}

function evoString2Number(num) {
	return Number(num.replace(/,/g,''));
}

function evoFromatNumberZ(num, zeros) {
	var str = "0000" + Math.floor(Math.abs(num));
	return str.substr(-zeros);
}

//

// ***************************************************************************
// ** Objects
// ***************************************************************************

//
// Page Handler hooks
function pageHandler(urlRegEx, handler) {
	this.urlRegEx = urlRegEx;
	this.handler = handler;
}
function regPageHandler(urlRegEx, handler) {
	pageHandlers.push(new pageHandler(urlRegEx,  handler));
}

//
// ***************************************************************************
// ** MISC
// ***************************************************************************

// GM implementation of cookies :)
function evoSetCookie(name, value, hours) {
	GM_setValue('cv_' + name, value);
	var expire = new Date();
	expire.setUTCHours(expire.getUTCHours() + hours);
	GM_setValue('cx_' + name, expire.toGMTString());
}

function evoGetCookie(name) {
	var value = GM_getValue('cv_' + name);
	var expire = GM_getValue('cx_' + name);
	if( value != null && expire != null ) {
		expire = new Date(expire);
		if( expire.valueOf() >= Date.now() ) return value;
	}
	return null;
}