Advertisement
Guest User

MOBYMAX UNLIMITED TIME

a guest
Nov 9th, 2017
2,426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.10 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Moby Hax by GamingandmorewithChris 67
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.0
  5. // @description Your gametime will never run out with this on!
  6. // @author GamingandmorewithChris 67@youtube.com
  7. // @match http://www.mobymax.com/MM/MS/labstart
  8. // @grant none
  9. // ==/UserScript==
  10. var sGames = {
  11. gameStudentId:0,
  12. refreshDialogFooterId:0,
  13. refreshInterval:(9999999999900 * 1000), //every sec
  14. totalTimerSec:0,
  15. totalTimer:0,
  16. timeTotal:0,
  17. timeUsed:0,
  18. gameId:0,
  19. gameType:0,
  20. gameWidth:0,
  21. gameHeight:0,
  22. footerHeight:0,
  23. resize:0,
  24. showGTDialog: function(id) {
  25.  
  26. function gameTimeDetail() {
  27. dialog.open('gameTimeDetail', {
  28. requestUrl: 'MT/games/gameTimeDetail/{0}'.toUrl(id),
  29. afterOpen: function() {
  30. var gameTimeDialogTitle = $(".gameTimeDetail-wrapper .gameTimeDetail-content .gTimeStudentNameTitle").html();
  31. $(".gameTimeDetail-wrapper .gameTimeDetail-content .gTimeStudentNameTitle").remove();
  32. $(".gameTimeDetail-wrapper .gameTimeDetail-header .gameTimeDetail-title").html(gameTimeDialogTitle);
  33. }
  34. });
  35. }
  36.  
  37. // Load js files in the order they are defined and trigger popup.
  38. var filesJs = [
  39. '/MM/js/d3.js',
  40. '/MM/js/generic/chart.js',
  41. '/MM/js/MT/games/chart.js'
  42. ];
  43.  
  44. function loadJs(url, callback) {
  45. var oScript = document.createElement('script');
  46. oScript.type = 'text/javascript';
  47. oScript.src = url;
  48. oScript.onload = function () {
  49. callback(url);
  50. };
  51. oScript.onreadystatechange = function () {
  52. if (this.readyState == 'loaded' || this.readyState == 'complete') {
  53. callback(url);
  54. }
  55. };
  56. document.getElementsByTagName("head")[0].appendChild(oScript);
  57. }
  58.  
  59. function load(i) {
  60. loadJs(filesJs[i], function () {
  61. i++;
  62. if (filesJs.length > i) {
  63. load(i);
  64. } else {
  65. gameTimeDetail();
  66. }
  67. });
  68. }
  69.  
  70. load(0);
  71.  
  72. },
  73. showGamesDialog: function(id) {
  74. dialog.close('student-games-dialog');
  75. dialog.open('student-games-dialog', {
  76. requestUrl: 'MT/games/getStudentGames/{0}/{1}'.toUrl(id,sGames.getBrowserVars())
  77. });
  78. },
  79. showGameStoreDialog: function(id) {
  80. dialog.open('student-games-dialog');
  81. sGames.openStore();
  82. },
  83.  
  84. openStore: function() {
  85. $('#lab-overlay').css('z-index','99998').show();
  86. $('#loading').css('z-index','99999').show();
  87. $.get('MT/games/getStudentGames/{0}/{1}/{2}'.toUrl(-1,sGames.getBrowserVars(),1), function(response) {
  88. $("#student-games-dialog-content-html").html(response);
  89. if($('.gameStore-remainingCredits').length!==0) {
  90. $('#student-games-dialog-content-html .student-games-wrap').css('overflow', 'hidden');
  91. }else {
  92. $('#student-games-dialog-content-html .student-games-wrap').css('overflow-y', 'auto');
  93. }
  94. $('#lab-overlay, #loading').hide();
  95. });
  96. },
  97. openStudentGames: function() {
  98. $('#lab-overlay').css('z-index','99998').show();
  99. $('#loading').css('z-index','99999').show();
  100. $.get('MT/games/getStudentGames/{0}/{1}'.toUrl(-1,sGames.getBrowserVars()), function(response) {
  101. $("#student-games-dialog-content-html").html(response);
  102. $('#lab-overlay, #loading').hide();
  103. });
  104. },
  105. getBrowserVars: function() {
  106. var browserVer = 0;
  107. var browserType = "";
  108. var hasFlash = (sGames.hasFlash())?1:0;
  109.  
  110. if ($.browser.msie) {
  111. browserVer = parseInt($.browser.version, 10);
  112. browserType = "ie";
  113. }
  114. if($.browser.mozilla === true) {
  115. browserVer = parseInt($.browser.version, 10);
  116. browserType = "mozz";
  117. }
  118. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
  119. browserVer = parseInt($.browser.version, 10);
  120. browserType = "mob";
  121. }
  122. if( /chrom(e|ium)/.test(navigator.userAgent.toLowerCase())) {
  123. browserVer = parseInt($.browser.version, 10);
  124. browserType = "chrome";
  125. }
  126.  
  127. return "{0}_{1}_{2}".format(hasFlash, browserType, browserVer);
  128. },
  129. unlockGame: function(gId) {
  130. $('#student-games-dialog-content-html').append('<div id="overlay"></div>')
  131. $('#lab-overlay').css('z-index','99998').show();
  132. $('#loading').css('z-index','99999').show();
  133. $.post('MT/games/addStudentGame'.toUrl(), {data:{gId:gId}}, function(response) {
  134. $('#student-games-dialog-content-html #overlay').remove();
  135. $('#lab-overlay, #loading').hide();
  136. if(response.removeStar) {
  137. $(".ls-icon .game-unlock-available").remove();
  138. sGames.openStore();
  139. }
  140. $('[onclick="sGames.unlockGame('+gId+')"]').text('Game Unlocked').removeAttr('onclick').css('cursor', 'auto');
  141. }, 'json');
  142.  
  143. },
  144. startGame: function(gameId, studentId) {
  145. $.post('MT/games/getStudentStatus'.toUrl(), {
  146. data:{
  147. 'studentID': studentId,
  148. 'sortType': 'first',
  149. 'returnType': 'sec'
  150. }
  151. }, function(response) {
  152. if(response.time < 60) {
  153. clearInterval(sGames.refreshDialogFooterId);
  154. sGames.refreshDialogFooterId = null;
  155.  
  156. 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!");
  157. return;
  158. }
  159. dialog.close('student-games-dialog');
  160. sGames.gameId = gameId;
  161. sGames.showGame();
  162. }, "json");
  163. },
  164.  
  165. showGame: function() {
  166. dialog.open('gameDialogBox', {
  167. requestUrl: 'MT/games/getStudentGamesDetails/{0}/{1}'.toUrl(sGames.gameId,-1),
  168. requestData: {
  169. resize: ((app.isMobile != '') && ($(document).width() <= 600))?1:0
  170. },
  171. afterOpen: function() {
  172. //set header
  173. var gameTimeDialogTitle = $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxTitle").html();
  174. $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxTitle").remove();
  175. $(".gameDialogBox-wrapper .gameDialogBox-header .gameDialogBox-title").html(gameTimeDialogTitle);
  176.  
  177. //set footer
  178. var gameTimeDialogFooter = $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxFooter").html();
  179. $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxFooter").remove();
  180. $(".gameDialogBox-wrapper .gameDialogBox-footer").html(gameTimeDialogFooter);
  181.  
  182. $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxGameRun").remove();
  183.  
  184. //get dimensions
  185. var gameTimeDialogDimensions = $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxParams").html().split("_");
  186. $(".gameDialogBox-wrapper .gameDialogBox-content .gameBoxParams").remove();
  187.  
  188. //add this height to dialog
  189. var addThisToFooter = parseInt($(".gameDialogBox-footer .gameBoxFooterInner").outerHeight(true))+(parseInt($(".gameDialogBox-wrapper").css("borderTop-width"))*2)+parseInt($(".gameDialogBox-header").outerHeight(true));
  190. sGames.adjustDimensions(parseInt(gameTimeDialogDimensions[0]), parseInt(gameTimeDialogDimensions[1]), parseInt(gameTimeDialogDimensions[2]),parseInt(addThisToFooter));
  191.  
  192. if(gameTimeDialogDimensions[3] == 'resized') {
  193. $(".gameDialogBox-wrapper").addClass('resized');
  194. $(".gameBoxContentGameObject").bind('load', function(){
  195. if($(".gameBoxContentGameObject").attr('src') != "about:blank") {
  196. if($(".gameBoxContentGameObject").contents().find("#novelgames_flashGame").attr('width') != parseInt(gameTimeDialogDimensions[2])) {
  197. $(".gameBoxContentGameObject").contents().find("#novelgames_flashGame").attr('width', parseInt(gameTimeDialogDimensions[2])).attr('height', parseInt(gameTimeDialogDimensions[1]));
  198. $(".gameBoxContentGameObject").contents().find("#novelgames_flashGame embed").attr('width', parseInt(gameTimeDialogDimensions[2])).attr('height', parseInt(gameTimeDialogDimensions[1]));
  199. }
  200. }
  201. });
  202. }
  203.  
  204. /*
  205. var boxWidth = 410;
  206. var boxRatio = (sGames.gameWidth - boxWidth) * 100 / sGames.gameWidth;
  207. var boxHeight = sGames.gameHeight - (sGames.gameHeight * boxRatio / 100);
  208. var gRatio = 20 * 100 / boxWidth;
  209. var gWidth = boxWidth - (boxWidth * gRatio / 100);
  210. var gHeight = boxHeight - (boxHeight * gRatio / 100);
  211. */
  212. }
  213. });
  214. },
  215.  
  216. startTimer: function(timeGame, timeGameTotal, studentId) {
  217. sGames.gameStudentId = studentId;
  218. sGames.timeTotal = timeGame;
  219. sGames.timeUsed = 0;
  220. sGames.totalTimerSec = 0;
  221. sGames.refreshDialogFooterId = setInterval("sGames.timerLogic()", sGames.refreshInterval); // every one sec
  222. },
  223. closeDialogBox: function(showAlert) {
  224. clearInterval(sGames.refreshDialogFooterId);
  225. sGames.refreshDialogFooterId = null;
  226.  
  227. dialog.close("gameDialogBox", {
  228. afterClose: function() {
  229. var rightNow = new Date();
  230. $(".gameBoxContent .gameBoxContentGameObject").attr("src", "about:blank");
  231. $.post('MT/games/updateStudentLeftTime'.toUrl(), {
  232. data:{
  233. 'studentId': sGames.gameStudentId,
  234. 'remainingTime': sGames.totalTimerSec,
  235. 'totalTime': sGames.totalTimer,
  236. 'clientDT': rightNow
  237. }
  238. }, function(response) {
  239. sGames.totalTimerSec = 0;
  240. sGames.totalTimer = 0;
  241. if(showAlert === true) {
  242. alert("You’ve used up all your Game Time!");
  243. }
  244. });
  245. }
  246. });
  247. },
  248. timerLogic: function() {
  249. if(navigator.onLine) {
  250. //modify timers
  251. if(sGames.totalTimerSec >= sGames.timeTotal) {
  252. sGames.closeDialogBox(true);
  253. return;
  254. }
  255. sGames.totalTimerSec++;
  256. sGames.totalTimer++;
  257. if(sGames.totalTimerSec >= 60) {
  258. sGames.totalTimerSec = 0;
  259. sGames.timeTotal = sGames.timeTotal - 60;
  260. sGames.timeUsed = sGames.timeUsed+60;
  261.  
  262. //verify student time
  263. if(sGames.timeTotal <= 0) {
  264. sGames.totalTimerSec = 60;
  265. sGames.closeDialogBox(true);
  266. } else {
  267. //update db with refreshInterval
  268. $.post('MT/games/updateStudentPlayedTime'.toUrl(), {
  269. data:{
  270. 'studentId': sGames.gameStudentId
  271. }
  272. }, function(response) {
  273. //update game dialog footer
  274. $(".gameDialogBox-wrapper .gameDialogBox-footer .gameBoxFooterInner .timeUsed-timeBox").html(Math.floor(sGames.timeUsed/60));
  275. $(".gameDialogBox-wrapper .gameDialogBox-footer .gameBoxFooterInner .timeLeft-timeBox").html(Math.floor(sGames.timeTotal/60));
  276. }, "json");
  277. }
  278. }
  279. } else {
  280. window.location.reload();
  281. }
  282.  
  283. },
  284. adjustDimensions: function(gType, gHeight, gWidth, magix) {
  285. var sGameType = gType;
  286. var gameHeight = gHeight;
  287. var gameWidth = gWidth;
  288. var dialogHeight = 0;
  289. var dialogWidth = 0;
  290. var dialogWidthAbs = "100%";
  291. var ieChaosVal = 0;
  292.  
  293. if ($.browser.msie && parseInt($.browser.version, 10) === 7) {
  294. ieChaosVal = 8;
  295. dialogWidthAbs = "110%";
  296. } else if($.browser.msie && parseInt($.browser.version, 10) === 8) {
  297. ieChaosVal = 7;
  298. dialogWidthAbs = "110%";
  299. } else if($.browser.msie && parseInt($.browser.version, 10) === 9) {
  300. ieChaosVal = 2;
  301. }
  302. magix = magix-ieChaosVal;
  303.  
  304. //adjust dialog and iframe dimensions
  305. dialogHeight = gameHeight + magix; // do u believe in magix...
  306. dialogWidth = gameWidth;
  307. $(".gameDialogBox-wrapper").css({
  308. "width":dialogWidth + "px",
  309. "height":dialogHeight + "px",
  310. "margin-left":"-{0}px".format(Math.floor((dialogWidth/2)+1))
  311. });
  312.  
  313. $(".gameBoxContent .gameBoxContentGameObject").css({
  314. "height":gameHeight + "px",
  315. "width":dialogWidthAbs,
  316. "border":'0'
  317. });
  318.  
  319. //after dialog rezise, update it again, height might have changed
  320. var updatedResizeVal = parseInt($(".gameDialogBox-footer .gameBoxFooterInner").outerHeight(true))+(parseInt($(".gameDialogBox-wrapper").css("borderTop-width"))*2)+parseInt($(".gameDialogBox-header").outerHeight(true));
  321. $(".gameDialogBox-wrapper").css("height",gameHeight+updatedResizeVal-ieChaosVal);
  322. },
  323. hasFlash: function() {
  324. // return (typeof navigator.plugins == "undefined" || navigator.plugins.length == 0)?!!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash")):navigator.plugins["Shockwave Flash"];
  325. var hasFlash = false;
  326. try {
  327. var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
  328. if(fo) hasFlash = true;
  329. }catch(e){
  330. if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true;
  331. }
  332. return hasFlash;
  333. },
  334. onOrientationChange: function() {
  335. if ($('#gameDialogBox').is(':visible') && (sGames.gameId > 0)) {
  336. setTimeout(sGames.showGame, 300);
  337. }
  338. }
  339. };
  340.  
  341. $(function(){
  342. $(window).bind( 'orientationchange', sGames.onOrientationChange);
  343. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement