====== ii-council ======
====== Version 2 ======
Version 2 is just like Version 1, but automatically submits to Buddleia's tracker.
// ==UserScript==
// @name ii-council
// @namespace http://users.pepperfish.net/vivek/
// @description harvest the council status and upload it
// @match http://*.improbableisland.com/runmodule.php?module=counciloffices*
// @version 2
// @author die fledermaus and Full Metal Lion
// @icon http://improbableisland.com/favicon.ico
// @grant none
// ==/UserScript==
// console.log("running council.js");
var maths = Math;
var filters= [ "//div[@class='maincolumn']" ,
"//td[@class='content']" ,
"//fieldset/div[@class='block']" ,
"//body" ];
var divs = null;
var status = /^.*(AceHigh|Cyber City 404|Improbable Central|Kittania|New(?: Pittsburgh|Home)|(?:Pleasantvil|Squat Ho)le):\s*([^()]+)\s+.*\(([0-9,]+) .*?\).*$/mg;
var cities = { "acehigh" : "ah" ,
"cyber city 404" : "cc" ,
"improbable central" : "ic" ,
"kittania" : "kt" ,
"new pittsburgh" : "np" ,
"newhome" : "nh" ,
"pleasantville" : "pv" ,
"squat hole" : "sh" };
var activity = { "peaceful days" : 0,
"quiet times" : 1,
"minor activity" : 2,
"guarded atmosphere" : 3,
"increased activity" : 4,
"assistance required": 5,
"critical situation" : 6,
"interesting times" : 7 };
var iiform_map = { "ic" : "entry.0.group" ,
"cc" : "entry.2.group" ,
"nh" : "entry.4.group" ,
"kt" : "entry.6.group" ,
"np" : "entry.8.group" ,
"pv" : "entry.10.group" ,
"sh" : "entry.12.group" ,
"ah" : "entry.14.group" };
var time = maths.round( Date.now() / 1000 );
for( var x = 0; x < filters.length; x++ )
{
var filter = filters[x];
divs = document.evaluate( filter, document, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null );
if(divs.snapshotLength > 0)
break;
}
// console.log("council.js - inspecting " + divs.snapshotLength + " nodes");
for( var i = 0; i < divs.snapshotLength; i++ )
{
var node = divs.snapshotItem( i );
var text = node.textContent;
var stat = null;
var send = false;
var gsxform = { 'pageNumber' : 0 ,
'submit' : 'Submit',
'backupCache': '' };
var fled = document.createElement( 'form' );
var budd = document.createElement( 'form' );
fled.setAttribute( 'method' , 'post' );
fled.setAttribute( 'enctype', 'application/x-www-form-urlencoded' );
fled.setAttribute( 'action' , 'http://rtfm.etla.org/cgi-bin/iic.cgi' );
fled.setAttribute( 'target' , 'ii-council-upload' );
budd.setAttribute( 'method' , 'post' );
budd.setAttribute( 'enctype', 'application/x-www-form-urlencoded' );
//dd.setAttribute( 'action' , 'https://docs.google.com/spreadsheet/formResponse?formkey=dHpvNXBKdGxuZlV4VV9uRFl4MXlTOUE6MA&theme=0AX42CRMsmRFbUy1iOGYwN2U2Mi1hNWU0LTRlNjEtYWMyOC1lZmU4ODg1ODc1ODI&ifq' );
budd.setAttribute( 'action' , 'https://docs.google.com/spreadsheet/formResponse?formkey=dHVGdnE1QU1BeEdBZm11YnphOGdXSFE6MQ&theme=0AX42CRMsmRFbUy1iOGYwN2U2Mi1hNWU0LTRlNjEtYWMyOC1lZmU4ODg1ODc1ODI&ifq' );
budd.setAttribute( 'target' , 'ii-council-upload' );
var broken = false;
var bleargh = 0;
// console.log( "council.js - comparing [" + text + "] against " + status );
while( stat = status.exec(text) )
{
var city = stat[1];
var desc = stat[2];
var level = activity[ desc.toLowerCase() ];
var wall = stat[3].replace(/,/g,'') * 1;
var code = cities[ city.toLowerCase() ];
// just in case we get a runaway:
if( bleargh++ > 100 )
{
broken = true;
break;
}
// console.log("council.js - " + city + '/' + code + '/' + desc + '/' + level + '/' + wall );
if( code )
{
var input = document.createElement( 'input' );
input.setAttribute( 'type' , 'hidden' );
input.setAttribute( 'value', city + ',' + level + ',' + wall );
input.setAttribute( 'name' , code );
fled.appendChild( input );
send = true;
gsxform[ iiform_map[code] ] =
level + 1 + (((level == 7) && (wall == 0)) ? 1 : 0);
}
}
if( broken )
continue;
for( key in gsxform )
{
var input = document.createElement( 'input' );
input.setAttribute( 'type' , 'hidden' );
input.setAttribute( 'value', gsxform[key] );
input.setAttribute( 'name' , key );
budd.appendChild( input );
}
if( send )
{
var spacer = document.createElement( 'hr' );
var submit = document.createElement( 'input' );
var submi2 = document.createElement( 'input' );
var stamp = document.createElement( 'input' );
node.appendChild( spacer );
stamp.setAttribute( 'type' , 'hidden' );
stamp.setAttribute( 'value', time );
stamp.setAttribute( 'name' , 'time' );
submit.setAttribute( 'type' , 'submit' );
submit.setAttribute( 'value', 'Send to fledermaus' );
fled.appendChild( stamp );
fled.appendChild( submit );
node.appendChild( fled );
submi2.setAttribute( 'type' , 'submit' );
submi2.setAttribute( 'value', 'Send to Buddleia' );
budd.appendChild( submi2 );
node.appendChild( budd );
submi2.click();
}
}
====== Version 1 ======
http://platypus.pepperfish.net/~vivek/ii/ii-council.user.js
// ==UserScript==
// @name ii-council
// @namespace http://users.pepperfish.net/vivek/
// @description harvest the council status and upload it
// @include http://www.improbableisland.com/runmodule.php?module=counciloffices*
// @include http://improbableisland.com/runmodule.php?module=counciloffices*
// ==/UserScript==
// GM_log("running council.js");
var maths = Math;
var filters= [ "//div[@class='maincolumn']" ,
"//td[@class='content']" ,
"//fieldset/div[@class='block']" ,
"//body" ];
var divs = null;
var status = /^.*(AceHigh|Cyber City 404|Improbable Central|Kittania|New(?: Pittsburgh|Home)|(?:Pleasantvil|Squat Ho)le):\s*([^()]+)\s+.*\(([0-9,]+) .*?\).*$/mg;
var cities = { "acehigh" : "ah" ,
"cyber city 404" : "cc" ,
"improbable central" : "ic" ,
"kittania" : "kt" ,
"new pittsburgh" : "np" ,
"newhome" : "nh" ,
"pleasantville" : "pv" ,
"squat hole" : "sh" };
var activity = { "peaceful days" : 0,
"quiet times" : 1,
"minor activity" : 2,
"guarded atmosphere" : 3,
"increased activity" : 4,
"assistance required": 5,
"critical situation" : 6,
"interesting times" : 7 };
var iiform_map = { "ic" : "entry.0.group" ,
"cc" : "entry.2.group" ,
"nh" : "entry.4.group" ,
"kt" : "entry.6.group" ,
"np" : "entry.8.group" ,
"pv" : "entry.10.group" ,
"sh" : "entry.12.group" ,
"ah" : "entry.14.group" };
var time = maths.round( Date.now() / 1000 );
for( var x = 0; x < filters.length; x++ )
{
var filter = filters[x];
divs = document.evaluate( filter, document, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null );
if(divs.snapshotLength > 0)
break;
}
// GM_log("council.js - inspecting " + divs.snapshotLength + " nodes");
for( var i = 0; i < divs.snapshotLength; i++ )
{
var node = divs.snapshotItem( i );
var text = node.textContent;
var stat = null;
var send = false;
var gsxform = { 'pageNumber' : 0 ,
'submit' : 'Submit',
'backupCache': '' };
var fled = document.createElement( 'form' );
var budd = document.createElement( 'form' );
fled.setAttribute( 'method' , 'post' );
fled.setAttribute( 'enctype', 'application/x-www-form-urlencoded' );
fled.setAttribute( 'action' , 'http://rtfm.etla.org/cgi-bin/iic.cgi' );
fled.setAttribute( 'target' , 'ii-council-upload' );
budd.setAttribute( 'method' , 'post' );
budd.setAttribute( 'enctype', 'application/x-www-form-urlencoded' );
//dd.setAttribute( 'action' , 'https://docs.google.com/spreadsheet/formResponse?formkey=dHpvNXBKdGxuZlV4VV9uRFl4MXlTOUE6MA&theme=0AX42CRMsmRFbUy1iOGYwN2U2Mi1hNWU0LTRlNjEtYWMyOC1lZmU4ODg1ODc1ODI&ifq' );
budd.setAttribute( 'action' , 'https://docs.google.com/spreadsheet/formResponse?formkey=dHVGdnE1QU1BeEdBZm11YnphOGdXSFE6MQ&theme=0AX42CRMsmRFbUy1iOGYwN2U2Mi1hNWU0LTRlNjEtYWMyOC1lZmU4ODg1ODc1ODI&ifq' );
budd.setAttribute( 'target' , 'ii-council-upload' );
var broken = false;
var bleargh = 0;
// GM_log( "council.js - comparing [" + text + "] against " + status );
while( stat = status.exec(text) )
{
var city = stat[1];
var desc = stat[2];
var level = activity[ desc.toLowerCase() ];
var wall = stat[3].replace(/,/g,'') * 1;
var code = cities[ city.toLowerCase() ];
// just in case we get a runaway:
if( bleargh++ > 100 )
{
broken = true;
break;
}
// GM_log("council.js - " + city + '/' + code + '/' + desc + '/' + level + '/' + wall );
if( code )
{
var input = document.createElement( 'input' );
input.setAttribute( 'type' , 'hidden' );
input.setAttribute( 'value', city + ',' + level + ',' + wall );
input.setAttribute( 'name' , code );
fled.appendChild( input );
send = true;
gsxform[ iiform_map[code] ] =
level + 1 + (((level == 7) && (wall == 0)) ? 1 : 0);
}
}
if( broken )
continue;
for( key in gsxform )
{
var input = document.createElement( 'input' );
input.setAttribute( 'type' , 'hidden' );
input.setAttribute( 'value', gsxform[key] );
input.setAttribute( 'name' , key );
budd.appendChild( input );
}
if( send )
{
var spacer = document.createElement( 'hr' );
var submit = document.createElement( 'input' );
var submi2 = document.createElement( 'input' );
var stamp = document.createElement( 'input' );
node.appendChild( spacer );
stamp.setAttribute( 'type' , 'hidden' );
stamp.setAttribute( 'value', time );
stamp.setAttribute( 'name' , 'time' );
submit.setAttribute( 'type' , 'submit' );
submit.setAttribute( 'value', 'Send to fledermaus' );
fled.appendChild( stamp );
fled.appendChild( submit );
node.appendChild( fled );
submi2.setAttribute( 'type' , 'submit' );
submi2.setAttribute( 'value', 'Send to Buddleia' );
budd.appendChild( submi2 );
node.appendChild( budd );
}
}