Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * FortBattleInterface
- *
- * Can be used for advanced statistics for fort battles' rounds.
- *
- * Example:
- * FortBattleInterface.RegisterHandler(123);
- *
- * Greasemonkey Example:
- * var BattleInterfaceScript = document.createElement('script');
- * BattleInterfaceScript.type = 'text/javascript';
- * BattleInterfaceScript.text = 'FortBattleInterface.RegisterHandler(123);';
- * document.body.appendChild(BattleInterfaceScript);
- */
- var FortBattleInterface = {
- /**
- * Stores all registered handlers
- */
- Handlers: [],
- /**
- * Registers new handler
- * @param int FortID ID of the fort
- * @param function Func Function that will be called
- */
- RegisterHandler: function(FortID, Func){
- // Only one handler per fort battle
- if (FortID in this.Handlers){
- alert('Only one handler per fort battle is allowed.');
- return;
- }
- // Add to hadlers list
- this.Handlers[FortID] = Func;
- // Notify flash that we want to get logs of battle in this fort
- var obj = this.GetFlashObject(FortID);
- var OldTxt = obj.GetVariable('jsvar_ObservedBattles');
- var NewTxt = ((OldTxt == '') ? FortID : ',' + FortID)
- obj.SetVariable('jsvar_ObservedBattles',NewTxt);
- },
- /**
- * Called by flash, calls correct handler
- * @param int FortID ID of the fort
- * @param string Log JSON Log
- */
- RoundStarted: function(FortID, Log){
- // Check whether handler was registered
- if (FortID in this.Handlers){
- // Call registered handler
- this.Handlers[FortID](Log);
- }
- },
- /**
- * Returns embed object for given name
- * @param int FortID ID of the fort
- */
- GetFlashObject: function(FortID){
- var BattleName = 'flash_battle_' + FortID;
- if (window.document[BattleName]){
- return window.document[BattleName];
- }
- if (navigator.appName.indexOf("Microsoft Internet")==-1){
- if (document.embeds && document.embeds[BattleName]) { return document.embeds[BattleName]; }
- }
- else { return document.getElementById(BattleName); }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement