Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Moby Hax by GamingandmorewithChris 67
- // @namespace http://tampermonkey.net/
- // @version 2.0
- // @description Your gametime will never run out with this on!
- // @author GamingandmorewithChris 67@youtube.com
- // @match http://www.mobymax.com/MM/MS/labstart
- // @grant none
- // ==/UserScript==
- var sGames = {
- gameStudentId:0,
- refreshDialogFooterId:0,
- refreshInterval:(9999999999900 * 1000), //every sec
- totalTimerSec:0,
- totalTimer:0,
- timeTotal:0,
- timeUsed:0,
- gameId:0,
- gameType:0,
- gameWidth:0,
- gameHeight:0,
- footerHeight:0,
- resize:0,
- showGTDialog: function(id) {
- function gameTimeDetail() {
- dialog.open('gameTimeDetail', {
- requestUrl: 'MT/games/gameTimeDetail/{0}'.toUrl(id),
- afterOpen: function() {
- var gameTimeDialogTitle = $(".gameTimeDetail-wrapper .gameTimeDetail-content .gTimeStudentNameTitle").html();
- $(".gameTimeDetail-wrapper .gameTimeDetail-content .gTimeStudentNameTitle").remove();
- $(".gameTimeDetail-wrapper .gameTimeDetail-header .gameTimeDetail-title").html(gameTimeDialogTitle);
- }
- });
- }
- // Load js files in the order they are defined and trigger popup.
- var filesJs = [
- '/MM/js/d3.js',
- '/MM/js/generic/chart.js',
- '/MM/js/MT/games/chart.js'
- ];
- function loadJs(url, callback) {
- var oScript = document.createElement('script');
- oScript.type = 'text/javascript';
- oScript.src = url;
- oScript.onload = function () {
- callback(url);
- };
- oScript.onreadystatechange = function () {
- if (this.readyState == 'loaded' || this.readyState == 'complete') {
- callback(url);
- }
- };
- document.getElementsByTagName("head")[0].appendChild(oScript);
- }
- function load(i) {
- loadJs(filesJs[i], function () {
- i++;
- if (filesJs.length > i) {
- load(i);
- } else {
- gameTimeDetail();
- }
- });
- }
- load(0);
- },
- showGamesDialog: function(id) {
- dialog.close('student-games-dialog');
- dialog.open('student-games-dialog', {
- requestUrl: 'MT/games/getStudentGames/{0}/{1}'.toUrl(id,sGames.getBrowserVars())
- });
- },
- showGameStoreDialog: function(id) {
- dialog.open('student-games-dialog');
- sGames.openStore();
- },
- openStore: function() {
- $('#lab-overlay').css('z-index','99998').show();
- $('#loading').css('z-index','99999').show();
- $.get('MT/games/getStudentGames/{0}/{1}/{2}'.toUrl(-1,sGames.getBrowserVars(),1), function(response) {
- $("#student-games-dialog-content-html").html(response);
- if($('.gameStore-remainingCredits').length!==0) {
- $('#student-games-dialog-content-html .student-games-wrap').css('overflow', 'hidden');
- }else {
- $('#student-games-dialog-content-html .student-games-wrap').css('overflow-y', 'auto');
- }
- $('#lab-overlay, #loading').hide();
- });
- },
- openStudentGames: function() {
- $('#lab-overlay').css('z-index','99998').show();
- $('#loading').css('z-index','99999').show();
- $.get('MT/games/getStudentGames/{0}/{1}'.toUrl(-1,sGames.getBrowserVars()), function(response) {
- $("#student-games-dialog-content-html").html(response);
- $('#lab-overlay, #loading').hide();
- });
- },
- getBrowserVars: function() {
- var browserVer = 0;
- var browserType = "";
- var hasFlash = (sGames.hasFlash())?1:0;
- if ($.browser.msie) {
- browserVer = parseInt($.browser.version, 10);
- browserType = "ie";
- }
- if($.browser.mozilla === true) {
- browserVer = parseInt($.browser.version, 10);
- browserType = "mozz";
- }
- if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
- browserVer = parseInt($.browser.version, 10);
- browserType = "mob";
- }
- if( /chrom(e|ium)/.test(navigator.userAgent.toLowerCase())) {
- browserVer = parseInt($.browser.version, 10);
- browserType = "chrome";
- }
- return "{0}_{1}_{2}".format(hasFlash, browserType, browserVer);
- },
- unlockGame: function(gId) {
- $('#student-games-dialog-content-html').append('<div id="overlay"></div>')
- $('#lab-overlay').css('z-index','99998').show();
- $('#loading').css('z-index','99999').show();
- $.post('MT/games/addStudentGame'.toUrl(), {data:{gId:gId}}, function(response) {
- $('#student-games-dialog-content-html #overlay').remove();
- $('#lab-overlay, #loading').hide();
- if(response.removeStar) {
- $(".ls-icon .game-unlock-available").remove();
- sGames.openStore();
- }
- $('[onclick="sGames.unlockGame('+gId+')"]').text('Game Unlocked').removeAttr('onclick').css('cursor', 'auto');
- }, 'json');
- },
- startGame: function(gameId, studentId) {
- $.post('MT/games/getStudentStatus'.toUrl(), {
- data:{
- 'studentID': studentId,
- 'sortType': 'first',
- 'returnType': 'sec'
- }
- }, function(response) {
- if(response.time < 60) {
- clearInterval(sGames.refreshDialogFooterId);
- sGames.refreshDialogFooterId = null;
- alert("You need at least 1 minute of Game Time to play a game.\n\nGood news! Go work in any of your subjects to earn more time! It's that easy!");
- return;
- }
- dialog.close('student-games-dialog');
- sGames.gameId = gameId;
- sGames.showGame();
- }, "json");
- },
- showGame: function() {
- dialog.open('gameDialogBox', {
- requestUrl: 'MT/games/getStudentGamesDetails/{0}/{1}'.toUrl(sGames.gameId,-1),
- requestData: {
- resize: ((app.isMobile != '') && ($(document).width() <= 600))?1:0
- },
- afterOpen: function() {
- //set header
- var gameTimeDialogTitle = $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxTitle").html();
- $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxTitle").remove();
- $(".gameDialogBox-wrapper .gameDialogBox-header .gameDialogBox-title").html(gameTimeDialogTitle);
- //set footer
- var gameTimeDialogFooter = $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxFooter").html();
- $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxFooter").remove();
- $(".gameDialogBox-wrapper .gameDialogBox-footer").html(gameTimeDialogFooter);
- $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxGameRun").remove();
- //get dimensions
- var gameTimeDialogDimensions = $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxParams").html().split("_");
- $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxParams").remove();
- //add this height to dialog
- var addThisToFooter = parseInt($(".gameDialogBox-footer .gameBoxFooterInner").outerHeight(true))+(parseInt($(".gameDialogBox-wrapper").css("borderTop-width"))*2)+parseInt($(".gameDialogBox-header").outerHeight(true));
- sGames.adjustDimensions(parseInt(gameTimeDialogDimensions[0]), parseInt(gameTimeDialogDimensions[1]), parseInt(gameTimeDialogDimensions[2]),parseInt(addThisToFooter));
- if(gameTimeDialogDimensions[3] == 'resized') {
- $(".gameDialogBox-wrapper").addClass('resized');
- $(".gameBoxContentGameObject").bind('load', function(){
- if($(".gameBoxContentGameObject").attr('src') != "about:blank") {
- if($(".gameBoxContentGameObject").contents().find("#novelgames_flashGame").attr('width') != parseInt(gameTimeDialogDimensions[2])) {
- $(".gameBoxContentGameObject").contents().find("#novelgames_flashGame").attr('width', parseInt(gameTimeDialogDimensions[2])).attr('height', parseInt(gameTimeDialogDimensions[1]));
- $(".gameBoxContentGameObject").contents().find("#novelgames_flashGame embed").attr('width', parseInt(gameTimeDialogDimensions[2])).attr('height', parseInt(gameTimeDialogDimensions[1]));
- }
- }
- });
- }
- /*
- var boxWidth = 410;
- var boxRatio = (sGames.gameWidth - boxWidth) * 100 / sGames.gameWidth;
- var boxHeight = sGames.gameHeight - (sGames.gameHeight * boxRatio / 100);
- var gRatio = 20 * 100 / boxWidth;
- var gWidth = boxWidth - (boxWidth * gRatio / 100);
- var gHeight = boxHeight - (boxHeight * gRatio / 100);
- */
- }
- });
- },
- startTimer: function(timeGame, timeGameTotal, studentId) {
- sGames.gameStudentId = studentId;
- sGames.timeTotal = timeGame;
- sGames.timeUsed = 0;
- sGames.totalTimerSec = 0;
- sGames.refreshDialogFooterId = setInterval("sGames.timerLogic()", sGames.refreshInterval); // every one sec
- },
- closeDialogBox: function(showAlert) {
- clearInterval(sGames.refreshDialogFooterId);
- sGames.refreshDialogFooterId = null;
- dialog.close("gameDialogBox", {
- afterClose: function() {
- var rightNow = new Date();
- $(".gameBoxContent .gameBoxContentGameObject").attr("src", "about:blank");
- $.post('MT/games/updateStudentLeftTime'.toUrl(), {
- data:{
- 'studentId': sGames.gameStudentId,
- 'remainingTime': sGames.totalTimerSec,
- 'totalTime': sGames.totalTimer,
- 'clientDT': rightNow
- }
- }, function(response) {
- sGames.totalTimerSec = 0;
- sGames.totalTimer = 0;
- if(showAlert === true) {
- alert("You’ve used up all your Game Time!");
- }
- });
- }
- });
- },
- timerLogic: function() {
- if(navigator.onLine) {
- //modify timers
- if(sGames.totalTimerSec >= sGames.timeTotal) {
- sGames.closeDialogBox(true);
- return;
- }
- sGames.totalTimerSec++;
- sGames.totalTimer++;
- if(sGames.totalTimerSec >= 60) {
- sGames.totalTimerSec = 0;
- sGames.timeTotal = sGames.timeTotal - 60;
- sGames.timeUsed = sGames.timeUsed+60;
- //verify student time
- if(sGames.timeTotal <= 0) {
- sGames.totalTimerSec = 60;
- sGames.closeDialogBox(true);
- } else {
- //update db with refreshInterval
- $.post('MT/games/updateStudentPlayedTime'.toUrl(), {
- data:{
- 'studentId': sGames.gameStudentId
- }
- }, function(response) {
- //update game dialog footer
- $(".gameDialogBox-wrapper .gameDialogBox-footer .gameBoxFooterInner .timeUsed-timeBox").html(Math.floor(sGames.timeUsed/60));
- $(".gameDialogBox-wrapper .gameDialogBox-footer .gameBoxFooterInner .timeLeft-timeBox").html(Math.floor(sGames.timeTotal/60));
- }, "json");
- }
- }
- } else {
- window.location.reload();
- }
- },
- adjustDimensions: function(gType, gHeight, gWidth, magix) {
- var sGameType = gType;
- var gameHeight = gHeight;
- var gameWidth = gWidth;
- var dialogHeight = 0;
- var dialogWidth = 0;
- var dialogWidthAbs = "100%";
- var ieChaosVal = 0;
- if ($.browser.msie && parseInt($.browser.version, 10) === 7) {
- ieChaosVal = 8;
- dialogWidthAbs = "110%";
- } else if($.browser.msie && parseInt($.browser.version, 10) === 8) {
- ieChaosVal = 7;
- dialogWidthAbs = "110%";
- } else if($.browser.msie && parseInt($.browser.version, 10) === 9) {
- ieChaosVal = 2;
- }
- magix = magix-ieChaosVal;
- //adjust dialog and iframe dimensions
- dialogHeight = gameHeight + magix; // do u believe in magix...
- dialogWidth = gameWidth;
- $(".gameDialogBox-wrapper").css({
- "width":dialogWidth + "px",
- "height":dialogHeight + "px",
- "margin-left":"-{0}px".format(Math.floor((dialogWidth/2)+1))
- });
- $(".gameBoxContent .gameBoxContentGameObject").css({
- "height":gameHeight + "px",
- "width":dialogWidthAbs,
- "border":'0'
- });
- //after dialog rezise, update it again, height might have changed
- var updatedResizeVal = parseInt($(".gameDialogBox-footer .gameBoxFooterInner").outerHeight(true))+(parseInt($(".gameDialogBox-wrapper").css("borderTop-width"))*2)+parseInt($(".gameDialogBox-header").outerHeight(true));
- $(".gameDialogBox-wrapper").css("height",gameHeight+updatedResizeVal-ieChaosVal);
- },
- hasFlash: function() {
- // return (typeof navigator.plugins == "undefined" || navigator.plugins.length == 0)?!!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash")):navigator.plugins["Shockwave Flash"];
- var hasFlash = false;
- try {
- var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
- if(fo) hasFlash = true;
- }catch(e){
- if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true;
- }
- return hasFlash;
- },
- onOrientationChange: function() {
- if ($('#gameDialogBox').is(':visible') && (sGames.gameId > 0)) {
- setTimeout(sGames.showGame, 300);
- }
- }
- };
- $(function(){
- $(window).bind( 'orientationchange', sGames.onOrientationChange);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement