User:Dictature/Game Bar script

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to: navigation, search
This is documentation for personal use. Take advantage of it as you wish.

http://img88.imageshack.us/img88/4439/40002791.png
I'm running a poorly commented userscript to insert RuneScape Game Bar data into RuneScape toolbar. The script requires configuring Game Bar settings on runescape.com, and uses the cookies set by that page. Login is needed only for changing the settings.

Requirements[edit | edit source]

  • Webserver with PHP and cURL
  • Browser with user JavaScript feature (jQuery must be available for the user scripts)
    • Tested with Opera only, Chrome/Firefox would probably require some tweaking
User script
if(/http:\/\/(www\.|)runescape\.com(\/l\=\d|)\/(c\=.{11}\/|)game\.ws/gi.test(location.href)){
$(function(){
function getCookie(x){a=document.cookie.split(';');var b,c,e;d=0;for(i=0;i<a.length;i++){b=a[i].split('=');e=b[0].replace(/^\s+|\s+$/g,'');if(e==x){d=1;if(b.length>1)c=unescape(b[1].replace(/^\s+|\s+$/g,''));return c;break}b=null;e=''}if(!d)return null}
if(getCookie('toolbar_code')&&getCookie('toolbar_hash')){
$frame=$('<iframe/>').attr({
src:'http://localhost/rs?c='+getCookie('toolbar_code')+'&h='+getCookie('toolbar_hash')+'&f='+getCookie('toolbar_activity_filter'),
frameborder:0,
scrolling:'auto',
longdesc:'RuneScape Game Bar.',
}).css({
height:'55px',width:'100%',
background:'url(http://localhost/rs/menu_bg.jpg) center bottom repeat-x'//NOTE: menu_bg.jpg = http://www.runescape.com/img/game/menu_bg.jpg
});
$frame.appendTo('body');
}})};
http://localhost/rs/index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<?php
$ch = curl_init();
curl_setopt($ch,CURLOPT_USERAGENT,'Opera/9.80 (Windows NT 6.1; U; IBM EVV/3.0/EAK01AG9/LE; fi) Presto/2.10.229 Version/11.61');
curl_setopt($ch,CURLOPT_POST,0);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Cookie: toolbar_code='.$_GET['c'].'; toolbar_hash='.$_GET['h'].'; toolbar_activity_filter='.$_GET['f']));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_FAILONERROR,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,0);curl_setopt($ch,CURLOPT_TIMEOUT,0);
curl_setopt($ch,CURLOPT_URL,'http://services.runescape.com/m=toolbar/geupdate.ws');$data1=curl_exec($ch);
curl_setopt($ch,CURLOPT_URL,'http://services.runescape.com/m=toolbar/friendlist.ws');$data2=curl_exec($ch);
curl_setopt($ch,CURLOPT_URL,'http://services.runescape.com/m=toolbar/activities.ws');$data3=curl_exec($ch);
curl_close($ch);
$data = addslashes(preg_replace('/CAPTION/','CAPTIO',preg_replace('/(\<\!\[CDATA\[|\]{2}>)/','',preg_replace('/[\n\r]/','',$data1.$data2.$data3))));
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr"><head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body{margin:0;background:rgba(0,0,0,.3);}
* {color:white;font:8px small fonts;}
#gamebar ul {margin:0;padding:0;width:100%;}
#gamebar ul img {max-height:10px;vertical-align:bottom;}
#gamebar li {padding-left:3px;display:inline-block;vertical-align:top;list-style-type:none;}
#gamebar ul .main {margin-left:3px;text-shadow:#fff 0 0 4px;border-left:2px solid #eee;font-weight:bold;}
#gamebar ul .main:first-child {padding-left:0;border:0;}
#gamebar ul a {text-decoration:none;}
#gamebar ul a:hover {text-decoration:underline;}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(function(){
$data = $('<?=$data?>');
$data.find('button').each(function(){
$listItem = $('<li/>').addClass('main').append($('<img/>').attr('src',$(this).find('button_icon_url').text())).append($(this).find('default_button_text').text());
$('#gamebar>ul').append($listItem);
if($(this).find('with_dropdown').length){
$(this).parent().find('menu_item').each(function(){
$('<li/>').append($('<a/>').attr({href:$(this).find('url').text().replace(/\ufffd/g,'+'),target:'_blank'}).append($('<img/>').attr('src',$(this).find('icon_url').text())).append($(this).find('captio').text().replace(/\ufffd/g,' '))).appendTo('#gamebar>ul');
})}});
});
</script>
</head>
<body>
<div id="content">
<div id="gamebar"><ul /></div>
</div>
</body></html>