Difference between revisions of "HTMonkey"

From Hattrick
m (added image)
(Preferred players sorting)
Line 14: Line 14:
 
Adds a box below the friends' box with a form to quickly view the information of a player, team or match, providing the ID.
 
Adds a box below the friends' box with a form to quickly view the information of a player, team or match, providing the ID.
  
===Preferred players sorting===
+
// ==UserScript==
Sort the list of players by the parameter that you prefer automatically, not the player number or the player's name.
+
// @name          hattrick
 +
// @namespace    http://oasi.upc.es/~kiusap/hattrick/
 +
// @description  Adds a box with links to friends' teams and some other cool features.
 +
// @include      http://www*.hattrick.org/*
 +
// @include      http://195.149.157.22/*
 +
// @exclude      http://www.hattrick.org/*
 +
// ==/UserScript==
 +
 
 +
var htmonkey_version = "1.0.1";
 +
 
 +
// file: kiusap_hattrick.user.js
 +
// author:kiusap - gilipollas.desconcertante at gmail com
 +
// initially based on GM script by:divvy - dyveshinftra@gmail.com
 +
// license: GPL-2 ( http://www.gnu.org/licenses/gpl.html )
 +
// history:*0.1 2006-02-10
 +
//*0.2 2006-02-14
 +
//*0.3 2006-02-14: easy edit your preferred width
 +
//*0.4 2006-02-17: preferred sort method on players' page
 +
//*0.5 2006-02-22:storing friends into firefox's preferences.
 +
//You don't lose them on script updates.
 +
//*0.6 2006-05-21: adapted for new design of hattrick.
 +
//*0.7 2006-07-06: bugfix + aligned to the left (for small
 +
//resolutions)
 +
//*0.8 2006-08-07: automatic update league method for the friends' box and NT players bug fixed (thanks Franck35)
 +
//*1.0 2006-08-27: search box + choose side for htmonkey stuff
 +
//*1.0.12006-09-11: Changed sideframe css location to new css on hattrick's site.
 +
//
 +
//
 +
// version:$Id: kiusap_hattrick.user.js,v 1.0 2006/08/29 12:00:00 kiusap Exp $
 +
 
 +
//////////////////////////////////
 +
// EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT
 +
///////////////////////////
 +
 
 +
//sort: indicate here the sorting on the team players' page  --'.
 +
//-> sort = 0-> sort by Surename
 +
//-> sort = 1 -> sort by Lastname
 +
//-> sort = 2-> sort by player ID
 +
//-> sort = 3 -> sort by Age
 +
//-> sort = 4-> sort by TSI
 +
//-> sort = 5 -> sort by player number (only supporters)
 +
 
 +
var sort = 0;
 +
 
 +
//edit this variable to the amount of pixels you want increase the main frame
 +
var myWidth = 200;
 +
 
 +
//Which should be (in pixels) the width for the friends box?
 +
var friendsBoxWidth = 95;
 +
 
 +
//How many friends would you like to allocate on the box?
 +
var numberOfFriends = 16;
 +
 
 +
//Where do you want the box, at left or right of hattrick's interface? (left: 1, right: 2)
 +
var side = 2;
 +
 
 +
if (document.location.href.match(/blank.html/i))
 +
{
 +
//matrix containing the data for your friends (DO NOT EDIT THIS)
 +
var v_amics = new Array(numberOfFriends);
 +
var amics_lliures = new Array(0);
 +
for (i = 0; i < v_amics.length; i++)
 +
{
 +
v_amics[i] = new Array(4);
 +
}
 +
 
 +
get_htmonkey_values();
 +
get_free_space();
 +
}
 +
 
 +
//If you don''t have your preferred friends'' box (you just installed the
 +
//script or want to replace friends) then read the lines below to edit the
 +
//friends'' box.
 +
//
 +
//Wanna have links to your friends and their leagues? Edit these lines below.
 +
//All values must be enclosed in single (' ') or double (" ") quotes.
 +
//*The first Value is a text to be shown on the link to your friend's
 +
//team (maybe your friend's team name or simply your friend's name)
 +
//*The second Value MUST be your friend's team ID
 +
//
 +
//The first line adds links to kiusap's (the creator of this script) team
 +
//and league. Edit the values you wish and UNCOMMENT (remove the '//' at
 +
//the beginning of the line) each line of a friend, ONCE you've edited it.
 +
//Just duplicate all the lines you want and modify them to add more friends.
 +
//(edit the variable 'numberOfFriends' above).
 +
//
 +
if (document.location.href.match(/blank.html/i))
 +
{
 +
//newFriend ("kiusap", "778431");// the creator of the script
 +
//newFriend ("name", "teamID");
 +
//newFriend ("name", "teamID");
 +
//newFriend ("name", "teamID");
 +
////repeat as many times as you wish
 +
}
 +
//
 +
//If you wish to edit any friend, there are two possible cases:
 +
//1.You have edited this script and have the 'newFriend' lines
 +
//uncomented (without the initial '//') and your friends''s data
 +
//in them. Then, modify the data at your will.
 +
//
 +
//2.You installed a newer version of this script, and you have NOT
 +
//your friends'' data here. It''s alright. This script saves
 +
//the data in your firefox preferences, which you can view typing
 +
//'about:config' in firefox''s address bar. Then, in the filter
 +
//input, write 'htmonkey.team'. You''ll see then a bunch of lines.
 +
//Each one of these lines store some data of your friends, one value
 +
//each (name and teamID for all your friends).
 +
//You''ll have to expand the 'preference name' field to see it
 +
//complete. These rows end in teamX.name, teamX.id... and the value
 +
//is the data they refer. For editing something, just double-click
 +
//the value and enter a new one.
 +
//
 +
//PLEASE NOTE:
 +
//*To delete a friend, his/her name must be set to 'undefined'
 +
//without any quotes if you are in case 1. or, if you are in case
 +
//2., you need to right-click the name value and 'Reset' it.
 +
 
 +
 
 +
// FINISHING EDIT!!! DO NOT EDIT ANYTHING PAST THIS POINT
 +
 
 +
 
 +
var sortArray = Array(6);
 +
sortArray[0] = 'Surename';
 +
sortArray[1] = 'Lastname';
 +
sortArray[2] = 'PlayerId';
 +
sortArray[3] = 'Age';
 +
sortArray[4] = 'MarketValue';
 +
sortArray[5] = 'PlayerNumber';
 +
 
 +
 
 +
 
 +
if (document.location.href.match(/default.asp/i) || document.location.href.match(/defaultconf.asp/i))
 +
{
 +
var allFramesets, thisFrameset;
 +
allFramesets = document.evaluate(
 +
'//frameset[@cols]',
 +
document,
 +
null,
 +
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
 +
null);
 +
 
 +
var colsDefinition;
 +
if (side == 1)
 +
{
 +
document.getElementsByName("Filler_right")[0].setAttribute('src',null);
 +
colsDefinition = ''+(friendsBoxWidth+10)+',' + (746 + myWidth) + ',*';
 +
} else {
 +
document.getElementsByName("Filler_left")[0].setAttribute('src',null);
 +
colsDefinition = '8,' + (746 + myWidth) + ',*';
 +
}
 +
for (var i = 0; i < allFramesets.snapshotLength; i++)
 +
{
 +
thisFrameset = allFramesets.snapshotItem(i);
 +
if (thisFrameset.cols == '*,746,*' || thisFrameset.cols == '5%,745,5%')
 +
{
 +
thisFrameset.cols = colsDefinition;
 +
}
 +
}
 +
}
 +
 
 +
if (!document.location.href.match(/header.asp/i) && !document.location.href.match(/menu.asp/i))
 +
{
 +
var allWidths, thisWidth;
 +
allWidths = document.evaluate(
 +
'//*[@width]',
 +
document,
 +
null,
 +
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
 +
null);
 +
 
 +
for (var i = 0; i < allWidths.snapshotLength; i++)
 +
{
 +
thisWidth = allWidths.snapshotItem(i);
 +
if (thisWidth.width > 350)
 +
{
 +
thisWidth.width = eval(thisWidth.width) + myWidth;
 +
}
 +
}
 +
}
 +
 
 +
 
 +
if (document.location.href.match(/blank/i))
 +
{
 +
get_htmonkey_values();//if we added someone right now (no need to refresh)
 +
// first, add some CSS to this page.
 +
var linkestil = document.createElement('LINK');
 +
linkestil.setAttribute('type', 'text/css');
 +
linkestil.setAttribute('rel', 'stylesheet');
 +
linkestil.setAttribute('href', 'Css/themes/green/main.css');
 +
var dochead = document.getElementsByTagName('HEAD')[0];
 +
dochead.appendChild(linkestil);
 +
var estil = document.createElement('STYLE');
 +
estil.setAttribute('type', 'text/css');
 +
var estiltxt = "div.box ul { list-style-type: none; margin: 0; padding: 0;}";
 +
estiltxt += "body {margin: 90px 0 0 0; padding: 0;}";
 +
var divBoxStyle = "border: 1px solid #267F30; padding: 0 0 2px 0; width: "+friendsBoxWidth+"px;";
 +
if (side != 1) divBoxStyle +=" margin: 5px;";
 +
estiltxt += "div.box {"+divBoxStyle+"}";
 +
estiltxt += "div.box h2 { margin: 0 0 3px 0; padding: 0 0 0 10px; background-color: #267F30; color: #fff; }";
 +
estiltxt += "div.box h2 + * {padding-left: 10px; margin: 0;}";
 +
estil.appendChild(document.createTextNode(estiltxt));
 +
dochead.appendChild(estil);
 +
 
 +
//then, do the hard work
 +
//first, the friends box
 +
var htlist = document.createElement('UL');
 +
for (i = 0; i < v_amics.length; i++)
 +
{
 +
if (v_amics[i][0] == undefined || v_amics[i][0] == 0) continue;
 +
var item = document.createElement('LI');
 +
var a = document.createElement('A');
 +
a.setAttribute('href', 'teamDetails.asp?teamID='+v_amics[i][1]);
 +
a.setAttribute('target', 'main');
 +
a.appendChild(document.createTextNode(v_amics[i][0]));
 +
item.appendChild(a);
 +
item.appendChild(document.createTextNode(" "));
 +
a = document.createElement('A');
 +
a.setAttribute('href', 'leagueDetails.asp?LeagueLevelUnitID='+v_amics[i][3]);
 +
a.setAttribute('target', 'main');
 +
a.appendChild(document.createTextNode(v_amics[i][2]));
 +
item.appendChild(a);
 +
htlist.appendChild(item);
 +
}
 +
if (!htlist.hasChildNodes())
 +
{
 +
htlist.appendChild(document.createTextNode("Must edit the script to add links here. If you have already edited it, be sure you have removed the initial slashes (\/\/) before each \"newFriend(...)\" line."));
 +
}
 +
var box = document.createElement('DIV');
 +
box.setAttribute('class', 'box');
 +
var titbox = document.createElement('H2');
 +
titbox.appendChild(document.createTextNode('FRIENDS'));
 +
box.appendChild(titbox);
 +
box.appendChild(htlist);
 +
var framebody = document.getElementsByTagName('BODY')[0];
 +
framebody.appendChild(box);
 +
 
 +
// put a link to update && update function
 +
var uplink = document.createElement('A');
 +
uplink.setAttribute('href','#');
 +
uplink.addEventListener(
 +
'click',
 +
function() {
 +
if (!confirm("Only use this option if some of your friends' teams are playing on a different league / division, or if you see an 'undefined' league.\n\nAre you sure you want to update your friends' league details?"))
 +
{
 +
return;
 +
}
 +
var quants = 0;
 +
for (var i = 0; i < v_amics.length; i++)
 +
{
 +
if (v_amics[i][1] > 0)
 +
{
 +
quants++;
 +
var id = v_amics[i][1];
 +
GM_xmlhttpRequest({
 +
method: 'GET',
 +
url: 'http://'+document.location.hostname+'/Common/teamDetails.asp?outputType=XML&actionType=view&teamID='+id,
 +
headers: {
 +
'User-agent': 'HTMonkey '+htmonkey_version,
 +
'Accept': 'text/xml,application/xml',
 +
'Accept-encoding': 'gzip'
 +
},
 +
onload: function(responseDetails) {
 +
var parser = new DOMParser();
 +
var dom = parser.parseFromString(responseDetails.responseText, 'application/xml');
 +
var leagueid = dom.getElementsByTagName('LeagueLevelUnitID')[0].childNodes[0].nodeValue;
 +
var leaguename = dom.getElementsByTagName('LeagueLevelUnitName')[0].childNodes[0].nodeValue;
 +
var idj = dom.getElementsByTagName('TeamID')[0].childNodes[0].nodeValue;
 +
for (var j = 0; j < v_amics.length; j++)
 +
{
 +
if (v_amics[j][1] == idj)
 +
{
 +
GM_setValue('htmonkey.team'+j+'.leagueName', leaguename);
 +
GM_setValue('htmonkey.team'+j+'.leagueId', eval(leagueid));
 +
}
 +
}
 +
quants--;
 +
if (quants == 0)
 +
{
 +
alert('League details update finished! This frame is going to be reloaded now');
 +
document.location.reload();
 +
}
 +
}
 +
});
 +
}
 +
}
 +
},
 +
false
 +
);
 +
uplink.appendChild(document.createTextNode("Update team league details"));
 +
framebody.appendChild(uplink);
 +
framebody.appendChild(document.createElement('BR'));
 +
 
 +
//then, the search form
 +
unsafeWindow.location.href = 'javascript:var mytestvar=1;';
 +
 
 +
if (unsafeWindow.mytestvar)//js enabled, continue. (thanks Jeremy Dunck from GM mailing list)
 +
{
 +
var frm = document.createElement('FORM');
 +
frm.setAttribute('type', 'get');
 +
frm.setAttribute('action', 'blank.html');
 +
frm.setAttribute('name', 'gm_foo');
 +
frm.setAttribute('id', 'gm_foo');
 +
var inp = document.createElement('INPUT');
 +
inp.setAttribute('name', 'kiuid');
 +
inp.setAttribute('id', 'kiuid');
 +
inp.setAttribute('type', 'text');
 +
inp.setAttribute('style', 'width: 83px; border: solid p1 #000;');
 +
var labinp = document.createElement('LABEL');
 +
labinp.setAttribute('for', 'kiuid');
 +
labinp.appendChild(document.createTextNode("Insert ID: "));
 +
labinp.appendChild(inp);
 +
frm.appendChild(labinp);
 +
frm.appendChild(document.createElement('BR'));
 +
var sel = document.createElement('SELECT');
 +
sel.setAttribute('name', 'kiusel');
 +
sel.setAttribute('id', 'kiusel');
 +
var op1 = document.createElement('OPTION');
 +
op1.setAttribute('value', 'player');
 +
op1.appendChild(document.createTextNode("player"));
 +
sel.appendChild(op1);
 +
var op2 = document.createElement('OPTION');
 +
op2.setAttribute('value', 'team');
 +
op2.appendChild(document.createTextNode("team"));
 +
sel.appendChild(op2);
 +
var op3 = document.createElement('OPTION');
 +
op3.setAttribute('value', 'match');
 +
op3.appendChild(document.createTextNode("match"));
 +
sel.appendChild(op3);
 +
var labsel = document.createElement('LABEL');
 +
labsel.setAttribute('for', 'kiusel');
 +
labsel.appendChild(document.createTextNode("Search for: "));
 +
labsel.appendChild(sel);
 +
frm.appendChild(labsel);
 +
frm.appendChild(document.createElement('BR'));
 +
var labchk = document.createElement('LABEL');
 +
labchk.setAttribute('for', 'kiuchk');
 +
labchk.appendChild(document.createTextNode("Pop-up? "));
 +
var chk = document.createElement('INPUT');
 +
chk.setAttribute('type', 'checkbox');
 +
chk.setAttribute('id', 'kiuchk');
 +
chk.setAttribute('name', 'kiuchk');
 +
chk.setAttribute('value', '1');
 +
labchk.appendChild(chk);
 +
frm.appendChild(labchk);
 +
frm.appendChild(document.createElement('BR'));
 +
var but = document.createElement('INPUT');
 +
but.setAttribute('type', 'submit');
 +
but.setAttribute('value', 'search');
 +
 
 +
but.addEventListener('click', function(event) {
 +
var inp = document.getElementById('kiuid');
 +
var quin = inp.value;
 +
var que = document.getElementById('kiusel').value;
 +
if (document.getElementById('kiuchk').checked)
 +
{
 +
void(open('http://'+document.location.hostname+'/Common/'+que+'Details.asp?'+que+'ID='+quin,que+quin,'width=630,height=550,resizable=1,scrollbars=yes'));
 +
} else {
 +
window.parent.frames[3].location = que+'Details.asp?'+que+'ID='+quin;
 +
}
 +
inp.value = "";
 +
 
 +
event.stopPropagation();
 +
event.preventDefault();
 +
}, true);
 +
 
 +
 
 +
 
 +
frm.appendChild(document.createElement('BR'));
 +
frm.appendChild(but);
 +
 
 +
var box2 = document.createElement('DIV');
 +
box2.setAttribute('class', 'box');
 +
var titbox2 = document.createElement('H2');
 +
titbox2.appendChild(document.createTextNode('SEARCH'));
 +
box2.appendChild(titbox2);
 +
box2.appendChild(frm);
 +
framebody.appendChild(box2);
 +
} else {
 +
framebody.appendChild(document.createTextNode("You've got JavaScript disabled. You won't be able to use the search form unless you enable JavaScript."));
 +
}
 +
}
 +
 
 +
function kiusap_search()
 +
{
 +
var quin = document.getElementById('kiuid').value;
 +
var que = document.getElementById('kiusel').selectedValue;
 +
}
 +
 
 +
var allLinks, thisLink;
 +
allLinks = document.evaluate(
 +
'//a[@href]',
 +
document,
 +
null,
 +
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
 +
null);
 +
 
 +
for (var i = 0; i < allLinks.snapshotLength; i++)
 +
{
 +
thisLink = allLinks.snapshotItem(i);
 +
if (thisLink.href.match(/players.asp/i))
 +
{
 +
//add sorting
 +
//National Teams doesn't support ordering by player number. If so, order by SureName
 +
if (thisLink.href.match(/nationalplayers.asp/i) && sort == 5) sort = 0;
 +
var myHref = 'OrderBy=' + sortArray[sort];
 +
 
 +
if (thisLink.href.substr(-1) == '?')
 +
{
 +
thisLink.href = thisLink.href + myHref;
 +
} else {
 +
thisLink.href = thisLink.href + '&' + myHref;
 +
}
 +
}
 +
}
 +
 
 +
function get_htmonkey_values()
 +
{
 +
for (var i = 0; i < v_amics.length; i++)
 +
{
 +
v_amics[i][0] = GM_getValue('htmonkey.team'+i+'.name');
 +
v_amics[i][1] = GM_getValue('htmonkey.team'+i+'.id');
 +
v_amics[i][2] = GM_getValue('htmonkey.team'+i+'.leagueName');
 +
v_amics[i][3] = GM_getValue('htmonkey.team'+i+'.leagueId');
 +
}
 +
}
 +
 
 +
 
 +
//just a function to add your friends to the preferences, for being
 +
//easy-readable by the script and easy-editable by you
 +
function newFriend(nom, id_equip)
 +
{
 +
if (amics_lliures.length == 0)//there is no space to store a new friend
 +
{
 +
return;
 +
}
 +
 
 +
//we have room enough for one friend more. first see if it isn't in the box:
 +
 
 +
for (var i = 0; i < v_amics.length; i++)
 +
{
 +
if (v_amics[i][1] == undefined || v_amics[i][1] == 0) continue;//no friend stored in this position
 +
if (v_amics[i][1] == id_equip)return;//this friend is repeated. don't do anything
 +
}
 +
 
 +
//if we arrived here, it means we can add our friend.
 +
var pos = amics_lliures.shift();
 +
GM_setValue('htmonkey.team'+pos+'.name', nom);
 +
GM_setValue('htmonkey.team'+pos+'.id', eval(id_equip));
 +
}
 +
 
 +
function get_free_space()
 +
{
 +
for (var i = 0; i < v_amics.length; i++)
 +
{
 +
if (v_amics[i][0] == undefined)
 +
{
 +
amics_lliures.push(i);
 +
}
 +
}
 +
}
  
 
==External Links==
 
==External Links==

Revision as of 02:05, 8 July 2007

HTMonkey (pictured top) compared to original Hattrick design (below)

HTMonkey is a UserScript for Greasemonkey (an extension for Firefox/Mozilla).

Features

Hattrick's Interface

By default, it enlarges the interface for 200 pixels, making hattrick a little wider (something necessary with these big monitors of 1280x1024 pixels being sold today!).

Friends' Box

Adds a box on any of the blank frames with shortcuts to your preferred teams and their respective links.

  • With HTMonkey: Just click in the link on the friends box.
  • Without HTMonkey: Go to search, enter name, press enter and then click in the team!

Search Box

Adds a box below the friends' box with a form to quickly view the information of a player, team or match, providing the ID.

// ==UserScript== // @name hattrick // @namespace http://oasi.upc.es/~kiusap/hattrick/ // @description Adds a box with links to friends' teams and some other cool features. // @include http://www*.hattrick.org/* // @include http://195.149.157.22/* // @exclude http://www.hattrick.org/* // ==/UserScript==

var htmonkey_version = "1.0.1";

// file: kiusap_hattrick.user.js // author:kiusap - gilipollas.desconcertante at gmail com // initially based on GM script by:divvy - dyveshinftra@gmail.com // license: GPL-2 ( http://www.gnu.org/licenses/gpl.html ) // history:*0.1 2006-02-10 //*0.2 2006-02-14 //*0.3 2006-02-14: easy edit your preferred width //*0.4 2006-02-17: preferred sort method on players' page //*0.5 2006-02-22:storing friends into firefox's preferences. //You don't lose them on script updates. //*0.6 2006-05-21: adapted for new design of hattrick. //*0.7 2006-07-06: bugfix + aligned to the left (for small //resolutions) //*0.8 2006-08-07: automatic update league method for the friends' box and NT players bug fixed (thanks Franck35) //*1.0 2006-08-27: search box + choose side for htmonkey stuff //*1.0.12006-09-11: Changed sideframe css location to new css on hattrick's site. // // // version:$Id: kiusap_hattrick.user.js,v 1.0 2006/08/29 12:00:00 kiusap Exp $

////////////////////////////////// // EDIT EDIT EDIT EDIT EDIT EDIT EDIT EDIT ///////////////////////////

//sort: indicate here the sorting on the team players' page --'. //-> sort = 0-> sort by Surename //-> sort = 1 -> sort by Lastname //-> sort = 2-> sort by player ID //-> sort = 3 -> sort by Age //-> sort = 4-> sort by TSI //-> sort = 5 -> sort by player number (only supporters)

var sort = 0;

//edit this variable to the amount of pixels you want increase the main frame var myWidth = 200;

//Which should be (in pixels) the width for the friends box? var friendsBoxWidth = 95;

//How many friends would you like to allocate on the box? var numberOfFriends = 16;

//Where do you want the box, at left or right of hattrick's interface? (left: 1, right: 2) var side = 2;

if (document.location.href.match(/blank.html/i)) { //matrix containing the data for your friends (DO NOT EDIT THIS) var v_amics = new Array(numberOfFriends); var amics_lliures = new Array(0); for (i = 0; i < v_amics.length; i++) { v_amics[i] = new Array(4); }

get_htmonkey_values(); get_free_space(); }

//If you dont have your preferred friends box (you just installed the //script or want to replace friends) then read the lines below to edit the //friends box. // //Wanna have links to your friends and their leagues? Edit these lines below. //All values must be enclosed in single (' ') or double (" ") quotes. //*The first Value is a text to be shown on the link to your friend's //team (maybe your friend's team name or simply your friend's name) //*The second Value MUST be your friend's team ID // //The first line adds links to kiusap's (the creator of this script) team //and league. Edit the values you wish and UNCOMMENT (remove the '//' at //the beginning of the line) each line of a friend, ONCE you've edited it. //Just duplicate all the lines you want and modify them to add more friends. //(edit the variable 'numberOfFriends' above). // if (document.location.href.match(/blank.html/i)) { //newFriend ("kiusap", "778431");// the creator of the script //newFriend ("name", "teamID"); //newFriend ("name", "teamID"); //newFriend ("name", "teamID"); ////repeat as many times as you wish } // //If you wish to edit any friend, there are two possible cases: //1.You have edited this script and have the 'newFriend' lines //uncomented (without the initial '//') and your friendss data //in them. Then, modify the data at your will. // //2.You installed a newer version of this script, and you have NOT //your friends data here. Its alright. This script saves //the data in your firefox preferences, which you can view typing //'about:config' in firefoxs address bar. Then, in the filter //input, write 'htmonkey.team'. Youll see then a bunch of lines. //Each one of these lines store some data of your friends, one value //each (name and teamID for all your friends). //Youll have to expand the 'preference name' field to see it //complete. These rows end in teamX.name, teamX.id... and the value //is the data they refer. For editing something, just double-click //the value and enter a new one. // //PLEASE NOTE: //*To delete a friend, his/her name must be set to 'undefined' //without any quotes if you are in case 1. or, if you are in case //2., you need to right-click the name value and 'Reset' it.


// FINISHING EDIT!!! DO NOT EDIT ANYTHING PAST THIS POINT


var sortArray = Array(6); sortArray[0] = 'Surename'; sortArray[1] = 'Lastname'; sortArray[2] = 'PlayerId'; sortArray[3] = 'Age'; sortArray[4] = 'MarketValue'; sortArray[5] = 'PlayerNumber';


if (document.location.href.match(/default.asp/i) || document.location.href.match(/defaultconf.asp/i)) { var allFramesets, thisFrameset; allFramesets = document.evaluate( '//frameset[@cols]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

var colsDefinition; if (side == 1) { document.getElementsByName("Filler_right")[0].setAttribute('src',null); colsDefinition = +(friendsBoxWidth+10)+',' + (746 + myWidth) + ',*'; } else { document.getElementsByName("Filler_left")[0].setAttribute('src',null); colsDefinition = '8,' + (746 + myWidth) + ',*'; } for (var i = 0; i < allFramesets.snapshotLength; i++) { thisFrameset = allFramesets.snapshotItem(i); if (thisFrameset.cols == '*,746,*' || thisFrameset.cols == '5%,745,5%') { thisFrameset.cols = colsDefinition; } } }

if (!document.location.href.match(/header.asp/i) && !document.location.href.match(/menu.asp/i)) { var allWidths, thisWidth; allWidths = document.evaluate( '//*[@width]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < allWidths.snapshotLength; i++) { thisWidth = allWidths.snapshotItem(i); if (thisWidth.width > 350) { thisWidth.width = eval(thisWidth.width) + myWidth; } } }


if (document.location.href.match(/blank/i)) { get_htmonkey_values();//if we added someone right now (no need to refresh) // first, add some CSS to this page. var linkestil = document.createElement('LINK'); linkestil.setAttribute('type', 'text/css'); linkestil.setAttribute('rel', 'stylesheet'); linkestil.setAttribute('href', 'Css/themes/green/main.css'); var dochead = document.getElementsByTagName('HEAD')[0]; dochead.appendChild(linkestil); var estil = document.createElement('STYLE'); estil.setAttribute('type', 'text/css'); var estiltxt = "div.box ul { list-style-type: none; margin: 0; padding: 0;}"; estiltxt += "body {margin: 90px 0 0 0; padding: 0;}"; var divBoxStyle = "border: 1px solid #267F30; padding: 0 0 2px 0; width: "+friendsBoxWidth+"px;"; if (side != 1) divBoxStyle +=" margin: 5px;"; estiltxt += "div.box {"+divBoxStyle+"}"; estiltxt += "div.box h2 { margin: 0 0 3px 0; padding: 0 0 0 10px; background-color: #267F30; color: #fff; }"; estiltxt += "div.box h2 + * {padding-left: 10px; margin: 0;}"; estil.appendChild(document.createTextNode(estiltxt)); dochead.appendChild(estil);

//then, do the hard work //first, the friends box var htlist = document.createElement('UL'); for (i = 0; i < v_amics.length; i++) { if (v_amics[i][0] == undefined || v_amics[i][0] == 0) continue; var item = document.createElement('LI'); var a = document.createElement('A'); a.setAttribute('href', 'teamDetails.asp?teamID='+v_amics[i][1]); a.setAttribute('target', 'main'); a.appendChild(document.createTextNode(v_amics[i][0])); item.appendChild(a); item.appendChild(document.createTextNode(" ")); a = document.createElement('A'); a.setAttribute('href', 'leagueDetails.asp?LeagueLevelUnitID='+v_amics[i][3]); a.setAttribute('target', 'main'); a.appendChild(document.createTextNode(v_amics[i][2])); item.appendChild(a); htlist.appendChild(item); } if (!htlist.hasChildNodes()) { htlist.appendChild(document.createTextNode("Must edit the script to add links here. If you have already edited it, be sure you have removed the initial slashes (\/\/) before each \"newFriend(...)\" line.")); } var box = document.createElement('DIV'); box.setAttribute('class', 'box'); var titbox = document.createElement('H2'); titbox.appendChild(document.createTextNode('FRIENDS')); box.appendChild(titbox); box.appendChild(htlist); var framebody = document.getElementsByTagName('BODY')[0]; framebody.appendChild(box);

// put a link to update && update function var uplink = document.createElement('A'); uplink.setAttribute('href','#'); uplink.addEventListener( 'click', function() { if (!confirm("Only use this option if some of your friends' teams are playing on a different league / division, or if you see an 'undefined' league.\n\nAre you sure you want to update your friends' league details?")) { return; } var quants = 0; for (var i = 0; i < v_amics.length; i++) { if (v_amics[i][1] > 0) { quants++; var id = v_amics[i][1]; GM_xmlhttpRequest({ method: 'GET', url: 'http://'+document.location.hostname+'/Common/teamDetails.asp?outputType=XML&actionType=view&teamID='+id, headers: { 'User-agent': 'HTMonkey '+htmonkey_version, 'Accept': 'text/xml,application/xml', 'Accept-encoding': 'gzip' }, onload: function(responseDetails) { var parser = new DOMParser(); var dom = parser.parseFromString(responseDetails.responseText, 'application/xml'); var leagueid = dom.getElementsByTagName('LeagueLevelUnitID')[0].childNodes[0].nodeValue; var leaguename = dom.getElementsByTagName('LeagueLevelUnitName')[0].childNodes[0].nodeValue; var idj = dom.getElementsByTagName('TeamID')[0].childNodes[0].nodeValue; for (var j = 0; j < v_amics.length; j++) { if (v_amics[j][1] == idj) { GM_setValue('htmonkey.team'+j+'.leagueName', leaguename); GM_setValue('htmonkey.team'+j+'.leagueId', eval(leagueid)); } } quants--; if (quants == 0) { alert('League details update finished! This frame is going to be reloaded now'); document.location.reload(); } } }); } } }, false ); uplink.appendChild(document.createTextNode("Update team league details")); framebody.appendChild(uplink); framebody.appendChild(document.createElement('BR'));

//then, the search form unsafeWindow.location.href = 'javascript:var mytestvar=1;';

if (unsafeWindow.mytestvar)//js enabled, continue. (thanks Jeremy Dunck from GM mailing list) { var frm = document.createElement('FORM'); frm.setAttribute('type', 'get'); frm.setAttribute('action', 'blank.html'); frm.setAttribute('name', 'gm_foo'); frm.setAttribute('id', 'gm_foo'); var inp = document.createElement('INPUT'); inp.setAttribute('name', 'kiuid'); inp.setAttribute('id', 'kiuid'); inp.setAttribute('type', 'text'); inp.setAttribute('style', 'width: 83px; border: solid p1 #000;'); var labinp = document.createElement('LABEL'); labinp.setAttribute('for', 'kiuid'); labinp.appendChild(document.createTextNode("Insert ID: ")); labinp.appendChild(inp); frm.appendChild(labinp); frm.appendChild(document.createElement('BR')); var sel = document.createElement('SELECT'); sel.setAttribute('name', 'kiusel'); sel.setAttribute('id', 'kiusel'); var op1 = document.createElement('OPTION'); op1.setAttribute('value', 'player'); op1.appendChild(document.createTextNode("player")); sel.appendChild(op1); var op2 = document.createElement('OPTION'); op2.setAttribute('value', 'team'); op2.appendChild(document.createTextNode("team")); sel.appendChild(op2); var op3 = document.createElement('OPTION'); op3.setAttribute('value', 'match'); op3.appendChild(document.createTextNode("match")); sel.appendChild(op3); var labsel = document.createElement('LABEL'); labsel.setAttribute('for', 'kiusel'); labsel.appendChild(document.createTextNode("Search for: ")); labsel.appendChild(sel); frm.appendChild(labsel); frm.appendChild(document.createElement('BR')); var labchk = document.createElement('LABEL'); labchk.setAttribute('for', 'kiuchk'); labchk.appendChild(document.createTextNode("Pop-up? ")); var chk = document.createElement('INPUT'); chk.setAttribute('type', 'checkbox'); chk.setAttribute('id', 'kiuchk'); chk.setAttribute('name', 'kiuchk'); chk.setAttribute('value', '1'); labchk.appendChild(chk); frm.appendChild(labchk); frm.appendChild(document.createElement('BR')); var but = document.createElement('INPUT'); but.setAttribute('type', 'submit'); but.setAttribute('value', 'search');

but.addEventListener('click', function(event) { var inp = document.getElementById('kiuid'); var quin = inp.value; var que = document.getElementById('kiusel').value; if (document.getElementById('kiuchk').checked) { void(open('http://'+document.location.hostname+'/Common/'+que+'Details.asp?'+que+'ID='+quin,que+quin,'width=630,height=550,resizable=1,scrollbars=yes')); } else { window.parent.frames[3].location = que+'Details.asp?'+que+'ID='+quin; } inp.value = "";

event.stopPropagation(); event.preventDefault(); }, true);


frm.appendChild(document.createElement('BR')); frm.appendChild(but);

var box2 = document.createElement('DIV'); box2.setAttribute('class', 'box'); var titbox2 = document.createElement('H2'); titbox2.appendChild(document.createTextNode('SEARCH')); box2.appendChild(titbox2); box2.appendChild(frm); framebody.appendChild(box2); } else { framebody.appendChild(document.createTextNode("You've got JavaScript disabled. You won't be able to use the search form unless you enable JavaScript.")); } }

function kiusap_search() { var quin = document.getElementById('kiuid').value; var que = document.getElementById('kiusel').selectedValue; }

var allLinks, thisLink; allLinks = document.evaluate( '//a[@href]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < allLinks.snapshotLength; i++) { thisLink = allLinks.snapshotItem(i); if (thisLink.href.match(/players.asp/i)) { //add sorting //National Teams doesn't support ordering by player number. If so, order by SureName if (thisLink.href.match(/nationalplayers.asp/i) && sort == 5) sort = 0; var myHref = 'OrderBy=' + sortArray[sort];

if (thisLink.href.substr(-1) == '?') { thisLink.href = thisLink.href + myHref; } else { thisLink.href = thisLink.href + '&' + myHref; } } }

function get_htmonkey_values() { for (var i = 0; i < v_amics.length; i++) { v_amics[i][0] = GM_getValue('htmonkey.team'+i+'.name'); v_amics[i][1] = GM_getValue('htmonkey.team'+i+'.id'); v_amics[i][2] = GM_getValue('htmonkey.team'+i+'.leagueName'); v_amics[i][3] = GM_getValue('htmonkey.team'+i+'.leagueId'); } }


//just a function to add your friends to the preferences, for being //easy-readable by the script and easy-editable by you function newFriend(nom, id_equip) { if (amics_lliures.length == 0)//there is no space to store a new friend { return; }

//we have room enough for one friend more. first see if it isn't in the box:

for (var i = 0; i < v_amics.length; i++) { if (v_amics[i][1] == undefined || v_amics[i][1] == 0) continue;//no friend stored in this position if (v_amics[i][1] == id_equip)return;//this friend is repeated. don't do anything }

//if we arrived here, it means we can add our friend. var pos = amics_lliures.shift(); GM_setValue('htmonkey.team'+pos+'.name', nom); GM_setValue('htmonkey.team'+pos+'.id', eval(id_equip)); }

function get_free_space() { for (var i = 0; i < v_amics.length; i++) { if (v_amics[i][0] == undefined) { amics_lliures.push(i); } } }

External Links

Application.png This helper application article is a stub. You can help Hattrick Wiki by expanding it.