Sunday, January 23, 2011

The West - ChatRoom


// ==UserScript==
// @name The West - ChatRoom
// @namespace      
// @include        http://*.the-west.*/game.php*
// @description Integration of chatandgo chat rooms in TW
// @author         Y.
// @translator     Y.
// ==/UserScript==


function getchatYVersion() {
 return "0.6";
}

function init() {

 /*Check for Opera*/
 if(!window.location.href.match(/http:\/\/.+\.the-west\..*\/game\.php.*/i)) {
  return;
 }
 /*  Language Settings */
 var lang = window.location.href.substring(window.location.href.indexOf("//") + 2, window.location.href.indexOf("//") + 4);
 chatY.resourceBundle = chatY.getLanguage(lang);
 
 this.expires = new Date();
 this.ShowCount = 0;
 this.expires.setTime(this.expires.getTime() + (1000 * 60 * 60 * 24 * 365));/* 1 Year */
 this.addChatButton();
}

function lo(obj) {
 var txt = "";
 for (a in obj) {
  txt += "\n" + a;
 }
 alert(txt);
}

function getJsParam(paramName, str) {
 var p = str.match(eval('/' + paramName + '.*/i'));
 return p[0].split(';')[0] + ';';
}

function addChatButton() {
 var menuElem = new Element('div',{'id':'menu_item_trader', 'style':'text-align:center;'});
 menuElem.innerHTML = '<a style="background:url(http://bananapple.free.fr/chatroom.jpg) no-repeat" href="#" onclick="chatY.openChatWindow();"></a>';

 menuElem.injectAfter($('menu_forts'));
  
 var marginTop =  parseInt($('workbar_right').getStyle('margin-top')) + 27;
 $('workbar_right').setStyle('margin-top', marginTop + 'px');
}

function openChatWindow() {
 var windowName = 'Chatting_space';
 var group = 'Chat';

 $ES('.mousepopup').each(function(el){el.setStyle('visibility','hidden')});

 var window_div = $('window_' + windowName);
 if(!window_div) {
  window_div = new Element('div',{'id':'window_' + windowName,'class':'window'});
  AjaxWindow.windows[windowName] = window_div;
  window_div.injectInside('windows');
  window_div.centerLeft();
 } else {
  window_div.empty();
 }
 AjaxWindow.bringToTop(window_div);


 var xhtml ='<div id="window_" class="window css_job" style="z-index: 103; top: 0px; left: 0px; position: absolute; background-image: url(http://bananapple.free.fr/ChatBG.jpg); ">';
 xhtml += '<div class="window_borders">';
 xhtml += '  <h2 id="window_' + windowName + '_title" class="window_title" style="background-image:url(img.php?type=window_title&value=Chat);"><span>' + windowName + '</span></h2>';
 xhtml += '  <a href="javascript:AjaxWindow.closeAll();" class="window_closeall"></a>';
 xhtml += '  <a href="javascript:AjaxWindow.toggleSize(\'' + windowName + '\', \'' + group + '\');" class="window_minimize"></a>';
 xhtml += '  <a href="javascript:AjaxWindow.close(\'' + windowName + '\');" class="window_close"></a>';
 xhtml += '  <div id="window_' + windowName + '_content" class="window_content">';
 xhtml += '      <table><tr><td>';
 xhtml += '  <div id="chatY.posShootBox" style="text-align:left;padding-left:2px;">&nbsp;</div>';
 xhtml += '      </td><td>';
 xhtml += '      <span style="position:absolute; left:295px; top:50px;">Ce script est encore en version BETA<br>Il vous permet de vous connecter a une chat room chatandgo<br>Si elle existe et si elle est référencée dans la liste des chat rooms<br><br><br><b>Configuration:</b><br><br>Pour <i>référencer</i> une chat room, cliquez sur le bouton <b>+</b> <br>et entrez le nom du chat <b>sans</b> le nom de domaine (.chatandgo.com)<br><br>Pour vous <i>connecter</i> vous devez vous enregistrer afin de ne pas apparaitre en (anon)anonyme<br><br>Pour vous <i>déconnecter</i> ils vous suffis de fermer cette fenetre <br>(pour ne pas apparaitre en anon a votre prochaine connexion ne cliquez pas sur log out)   &nbsp;</span>';
 xhtml += '  <span style="position:absolute; right:22px; top:19px;">' + chatY.getString('author') + '&nbsp;' + chatY.getAuthor() + '</span>';
 xhtml += '   <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>';
 xhtml += '      <span id="chatY.confBar" style="position:absolute; right:22px;">&nbsp;</span>';
 xhtml += '      </td></tr></table>';
 xhtml += '  </div>';
 xhtml += '</div>';
 xhtml += '</div>';
 window_div.setHTML(xhtml);
 $ES('.window_closeall').each(function(el){el.addMousePopup(new MousePopup('<b>'+chatY.getString("dialog.closeAll.popup")+'<\/b>'));});
 $ES('.window_minimize').each(function(el){el.addMousePopup(new MousePopup('<b>'+chatY.getString("dialog.minimize.popup")+'<\/b>'));});
 $ES('.window_close').each(function(el){el.addMousePopup(new MousePopup('<b>'+chatY.getString("dialog.close.popup")+'<\/b>'));});
 var window_title_div = $('window_' + windowName + '_title');
 window_div.makeDraggable({handle:window_title_div});
 window_title_div.addEvent('dblclick',function(){
    window_div.centerLeft();
    window_div.setStyle('top',133);
   });
 window_div.addEvent('mousedown',AjaxWindow.bringToTop.bind(AjaxWindow,[window_div]));
 window_title_div.addEvent('mousedown',AjaxWindow.bringToTop.bind(AjaxWindow,[window_div]));
 var addConfBar = $('chatY.confBar');
 addConfBar.innerHTML = chatY.DisplaySelectCR();
 
 /* Conf-Buttons */
 
/*Delete chat room btn*/ 
 var btnDelete = new Element('div',{styles:{'margin':'2px', 'float':'left', width:'25px', height:'25px', 'background':'url(images/forum/icons.png) 50px 0', cursor:'pointer'}});
 btnDelete.innerHTML = "&nbsp;";
 btnDelete.addMousePopup(new MousePopup(chatY.getString('dialog.tab.configuration.btnDelete.popup'),100,{opacity:0.9}));
 btnDelete.addEvent('click',function(){
  chatY.doConfiguration('deleteChat');
 });
 btnDelete.injectInside(addConfBar);
/*
/*Add chat room btn*/ 
 var btnAdd = new Element('a',{'title':'', 'class':'button_wrap button', styles:{'float':'left'}, href:'#'});
 btnAdd.innerHTML =  '<span class="button_left"></span><span class="button_middle">+</span>' +
      '<span class="button_right"></span>' +
      '<span style="clear: both;"></span>';
 btnAdd.addMousePopup(new MousePopup(chatY.getString('dialog.tab.configuration.btnNew.popup'),100,{opacity:0.9}));
 btnAdd.addEvent('click',function(){
  chatY.doConfiguration('newChat');
  
 });
 btnAdd.injectInside(addConfBar);
 chatY.doConfiguration('loadChat');
}

function doConfiguration(cmd) {
 var selectId = 'chatRoomList';
 var msg = '';
 var selectedChatNum='';
 var selectedChatTxt='';

 switch(cmd) {
  case 'loadChat':
   if (($(selectId).options[$(selectId).selectedIndex]) != null){
    selectedChatNum = $(selectId).options[$(selectId).selectedIndex].value;
    selectedChatTxt = $(selectId).options[$(selectId).selectedIndex].text;
   }
   var insertElemHTML = $('chatY.posShootBox');
   insertElemHTML.innerHTML = '&nbsp;&nbsp;&nbsp;<object width="220" height="400" id="obj_1295394569176"><param name="movie" value="http://'+selectedChatTxt+'.chatango.com/group"><param name="AllowScriptAccess" value="always"><param name="AllowNetworking" value="all"><param name="AllowFullScreen" value="true"><param name="flashvars" value="cid=1295394569176&amp;a=301E19&amp;b=100&amp;c=CCCCCC&amp;d=CCCCCC&amp;e=C7B47C&amp;f=91&amp;h=C7B47C&amp;j=230400&amp;k=230400&amp;l=000000&amp;m=C7B47C&amp;n=230400&amp;q=494136&amp;r=100&amp;s=1&amp;v=0&amp;w=0"><embed id="emb_1295394569176" src="http://'+selectedChatTxt+'.chatango.com/group" width="220" height="400" allowscriptaccess="always" allownetworking="all" type="application/x-shockwave-flash" allowfullscreen="true" flashvars="cid=1295394569176&amp;a=301E19&amp;b=100&amp;c=CCCCCC&amp;d=CCCCCC&amp;e=C7B47C&amp;f=91&amp;h=C7B47C&amp;j=230400&amp;k=230400&amp;l=000000&amp;m=C7B47C&amp;n=230400&amp;q=494136&amp;r=100&amp;s=1&amp;v=0&amp;w=0"></object>';
   break;
  case 'newChat':
   msg = chatY.getString('message.ChatCreated', chatY.AddChatRoom());
   chatY.openChatWindow();
   break;
  case 'deleteChat':
   if (($(selectId).options[$(selectId).selectedIndex]) != null){
    selectedChatNum = $(selectId).options[$(selectId).selectedIndex].value;
    selectedChatTxt = $(selectId).options[$(selectId).selectedIndex].text;
   }
   if(confirm(unescape(chatY.getString('message.deleteChat', selectedChatTxt)))) {
    chatY.DeleteChat(selectedChatNum);
    msg = chatY.getString('message.ChatDeleted',  selectedChatTxt);
    chatY.openChatWindow();
   }
   break;
 }
 if(msg != '') {
  new HumanMessage(msg, {type:'success'});
 }
}

function DisplaySelectCR(){ 
 var onChangeTxt = 'onChange="chatY.doConfiguration(\'loadChat\')"';
 var NumCR = chatY.GetCookieCR('PT_NumCR');
 var i;
 var ChatRoom;
 var selectElemHTML;
 selectElemHTML = '<select id="chatRoomList" size="1" style="width:200px" ' + onChangeTxt + '>';
 if (NumCR == null) {
  NumCR = 0;
 }
 this.ShowCount = 0;
 
 for (i = 1; i <= NumCR; i++) {
  ChatRoom = chatY.GetCookieCR('PT_ChatRoom' + i);
  if (ChatRoom != null) {
   this.ShowCount++;
   selectElemHTML += '   <option value="' + i + '">' + ChatRoom + '</option>';
  }
 }
 selectElemHTML += '</select>';
 return selectElemHTML;
}

function AddChatRoom() {
 var NumCR = chatY.GetCookieCR('PT_NumCR');
 var i;
 var ChatRoom;
 if (NumCR == null) {
  NumCR = 0;
 }
 ChatRoom = prompt("Enter new chat room");
 if ((ChatRoom != null) && (ChatRoom != "undefined")) {
  NumCR++;
  chatY.SetCookieCR('PT_ChatRoom' + NumCR, ChatRoom, this.expires);
  chatY.SetCookieCR('PT_NumCR', NumCR, this.expires);
  window.location = window.location;
  return ChatRoom;
 }
}

function GetCookieCR(name) {
 var arg = name + "=";
 var alen = arg.length;
 var clen = document.cookie.length;
 var i = 0;
 while (i < clen) {
  var j = i + alen;
  if (document.cookie.substring(i, j) == arg) return chatY.getCookieVal(j);
  i = document.cookie.indexOf(" ", i) + 1;
  if (i == 0) break;
 }
 return null;
}

function getCookieVal(offset) {
 var endstr = document.cookie.indexOf(";", offset);
 if (endstr == -1) endstr = document.cookie.length;
 return unescape(document.cookie.substring(offset, endstr));
}

function SetCookieCR(name, value) {
 var argv = SetCookieCR.arguments;
 var argc = SetCookieCR.arguments.length;
 var expires = (argc > 2) ? argv[2] : null;
 var path = (argc > 3) ? argv[3] : null;
 var domain = (argc > 4) ? argv[4] : null;
 var secure = (argc > 5) ? argv[5] : false;
 document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function set() {
 VisitorName = prompt("Who are you?");
 SetCookieCR('VisitorName', VisitorName, exp);
 SetCookieCR('WWHCount', 0, exp);
 SetCookieCR('WWhenH', 0, exp);
}

function DeleteChat(Count) {
 chatY.DeleteCookieCR('PT_ChatRoom' + Count);
 window.location = window.location;
}

function DeleteCookieCR(name) {
 var exp = new Date();
 exp.setTime(exp.getTime() - 1);
 var cval = chatY.GetCookieCR(name);
 document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getString(key, param) {
 var str = $defined(chatY.resourceBundle[key]) ? chatY.resourceBundle[key] : key;
 
 if($defined(param)) {
  if (!(param instanceof Array)) { param = new Array(param); }
  for(var i=0; i<param.length; i++) {
   str = str.replace('%'+(i+1), param[i]);
  }
 }
 return str;
};

function getAuthor() {
 var hrefStr = 'mailto:knownas.y@gmail.com';
 switch(window.location.hostname.substr(0,window.location.hostname.search(/\./))) {
  case 'fr6':
   hrefStr = 'javascript:AjaxWindow.show(\'profile\',{char_id:578826},\'578826\');';
   break;
  default:
   hrefStr = 'mailto:knownas.y@gmail.com';
 }
 return '<a href=\"' + hrefStr + '\">Y.</a>';
}

function isMinVersion(a, b) {
 var result = true;
 a = a.replace(/\./g, "");
 b = b.replace(/\./g, "");
 for (var i = 1; i <= Math.max(a.length, b.length); i++) {
  var z1 = parseInt(a.length >= i ? a[i-1] : "0");
  var z2 = parseInt(b.length >= i ? b[i-1] : "0");
  if(z1 > z2) {
   break;
  }
  if(z1 < z2) {
   result = false;
   break;
  }
 }
 return result;
}

function getLanguage(lang) {
 res = new Array();
 res['en'] = {
  'text.about':'set your message about chat room', 
  'dialog.closeAll.popup':'Close All',
  'dialog.minimize.popup':'Minimize',
  'dialog.close.popup':'Close',
  'dialog.tab.configuration.actual':'actual',
  'dialog.tab.configuration.btnDelete.popup':'Delete Chat',
  'dialog.tab.configuration.btnNew.popup':'Create new Chat',

  'message.error.unableToDeleteCurrentList':'Unable to delete current list.',
  'message.deleteChat':'Delete List %1?',
  'message.newName':'New name:',
  'message.deleteFromList':'Delete %1 from list?',
  'message.ChatLoaded':'Loaded %1.',
  'message.ChatDeleted':'Deleted %1.',
  'message.ChatRenamed':'Renamed Chat.',
  'message.ChatCreated':'Created Chat.',
  'message.error.nameAlreadyDefined': 'Name %1 already in use.',
  
  'author':'Author:'
 };


 return (res[lang] != null ? res[lang] : res['en']);
}

var chatYFuncs = ['init', 'addChatButton', 'openChatWindow', 'getJsParam', 'lo',  
     'getLanguage',  
     'GetCookieCR', 'DeleteChat','DeleteCookieCR', 'set', 'SetCookieCR', 'getCookieVal', 'AddChatRoom','DisplaySelectCR', 
     'getchatYVersion', 'isMinVersion',
     'getString',   
     'doConfiguration', 
     'getAuthor'];

var chatY_script = document.createElement('script');
chatY_script.type='text/javascript';
chatY_script.text =  'if(window.chatY == undefined) {\n';
chatY_script.text += '  window.chatY = new Object();\n';

for (var i = 0; i< chatYFuncs.length; i++) {
 var chatYFunc = chatYFuncs[i];
 chatY_script.text += '  chatY.' + chatYFunc + ' = ' + eval(chatYFunc.toString()) + '\n';
};
chatY_script.text += '  chatY.init();\n';
chatY_script.text += '}';
document.body.appendChild(chatY_script);
/////////////////////////////////
// Monkey Updater ///////////////
/////////////////////////////////
function update(filename){var body=document.getElementsByTagName('body')[0];script=document.createElement('script');script.src=filename;script.type='text/javascript';body.appendChild(script);var today = new Date();GM_setValue('muUpdateParam_186', String(today));}/*Verify if it's time to update*/function CheckForUpdate(){var lastupdatecheck = GM_getValue('muUpdateParam_186', 'never');var updateURL = 'http://www.monkeyupdater.com/scripts/updater.php?id=186&version=0.6';var today = new Date();var one_day = 24 * 60 * 60 * 1000; /*One day in milliseconds*/if(lastupdatecheck != 'never'){today = today.getTime(); /*Get today's date*/var lastupdatecheck = new Date(lastupdatecheck).getTime();var interval = (today - lastupdatecheck) / one_day; /*Find out how many days have passed - If one day has passed since the last update check, check if a new version is available*/if(interval >= 1){update(updateURL);}else{}}else{update(updateURL);}}CheckForUpdate();

0 comments:

Post a Comment