Guest User

Untitled

a guest
Jan 25th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.25 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Gecko Tools
  3. // @namespace http://www.reddit.com/user/thevdude
  4. // @description A suite of customization options for TagPro
  5. // @include http://tagpro-*.koalabeast.com*
  6. // @include http://tangent.jukejuice.com*
  7. // @include http://oceanic.newcompte.fr:*
  8. // @exclude http://tagpro-*.koalabeast.com/groups/*
  9. // @exclude http://tangent.jukejuice.com/groups/*
  10. // @license GNU General Public License
  11. // @author GeckoPie & pooppants
  12. // @version 1.0.4.1
  13. // @require http://code.jquery.com/jquery-2.1.1.min.js
  14. // @grant GM_getValue
  15. // @grant GM_setValue
  16. // ==/UserScript==
  17. /******************************************
  18. ****** GLOBAL CONFIGURATION SETTINGS ******
  19. *******************************************/
  20.  
  21. var fileref = document.createElement('link');
  22. fileref.setAttribute('rel', 'stylesheet');
  23. fileref.setAttribute('type', 'text/css');
  24. fileref.setAttribute('href', 'http://thevdude.github.io/stylesheets/mm.css');
  25. document.getElementsByTagName('head') [0].appendChild(fileref);
  26.  
  27. window.menuOpen = false;
  28. window.resizeTimer = false;
  29.  
  30. // Load settings from local storage
  31. window.gt_customSounds = true;
  32. if (GM_getValue('gt_customSounds') != undefined) {
  33. gt_customSounds = eval(GM_getValue('gt_customSounds'));
  34. }
  35.  
  36. window.gt_drawTiles = true;
  37. if (GM_getValue('gt_drawTiles') != undefined) {
  38. gt_drawTiles = eval(GM_getValue('gt_drawTiles'));
  39. }
  40.  
  41. window.gt_drawWallpaper = true;
  42. if (GM_getValue('gt_drawWallpaper') != undefined) {
  43. gt_drawWallpaper = eval(GM_getValue('gt_drawWallpaper'));
  44. }
  45.  
  46. window.gt_transparentBackground = false;
  47. if (GM_getValue('gt_transparentBackground') != undefined) {
  48. gt_transparentBackground = eval(GM_getValue('gt_transparentBackground'));
  49. }
  50.  
  51. /*
  52. //TODO: FIX THIS WHEN PATCH IS PUSHED TO MAPTEST! IN THE MEANTIME, SET TO FALSE
  53. window.gt_maximize = false;
  54. if (GM_getValue('gt_maximize') != undefined) {
  55. gt_maximize = eval(GM_getValue('gt_maximize'));
  56. }
  57. */
  58.  
  59. window.gt_maximize = false;
  60. GM_setValue('gt_maximize', false);
  61.  
  62. window.gt_hideBorder = true;
  63. if (GM_getValue('gt_hideBorder') != undefined) {
  64. gt_hideBorder = eval(GM_getValue('gt_hideBorder'));
  65. }
  66.  
  67. window.gt_hideIcons = true;
  68. if (GM_getValue('gt_hideIcons') != undefined) {
  69. gt_hideIcons = eval(GM_getValue('gt_hideIcons'));
  70. }
  71.  
  72. window.gt_showOptions = true;
  73. window.mm_loaded = false;
  74.  
  75. window.mm_draw = false;
  76. if (GM_getValue('mm_draw') != undefined) {
  77. mm_draw = GM_getValue('mm_draw');
  78. }
  79.  
  80. window.mm_storedid = 'vanilla';
  81. if (GM_getValue('mm_storedid') != undefined) {
  82. mm_storedid = GM_getValue('mm_storedid');
  83. }
  84.  
  85. window.mm_files = {};
  86. if (GM_getValue('mm_files') != undefined) {
  87. mm_files = GM_getValue('mm_files');
  88. }
  89.  
  90. window.addEventListener('DOMContentLoaded', function (e) {
  91. /*******************************************
  92. ****** CONSTRUCT THE GECKO TOOLS MENU ******
  93. ********************************************/
  94. // Build the message div
  95. var message_div = document.createElement('div');
  96. message_div.id = 'message_div';
  97. message_div.width = '140px';
  98. message_div.style.opacity = '0.0';
  99. message_div.style.display = 'none';
  100. message_div.style.bottom = '20px';
  101. message_div.style.marginLeft = '50%'
  102. message_div.style.left = '-70px';
  103. message_div.style.position = 'absolute';
  104. message_div.style.backgroundColor = '#070707';
  105. message_div.style.color = '#47953d';
  106. message_div.style.borderRadius = '4px';
  107. message_div.style.padding = '8px';
  108. message_div.innerHTML = 'Files Accepted';
  109. message_div.style.transition = 'opacity 0.25s linear';
  110. document.body.appendChild(message_div);
  111.  
  112. // Build the icon
  113. var gecko_icon = document.createElement('img');
  114. gecko_icon.id = 'gecko_icon'
  115. gecko_icon.src = 'http://i.imgur.com/eenIpmO.png';
  116. gecko_icon.onclick = toggleMenu;
  117. gecko_icon.style.opacity = '0.0';
  118. gecko_icon.onmouseover = function () {
  119. gecko_icon.style.opacity = '1.0';
  120. gecko_icon.style.cursor = 'pointer';
  121. }
  122. gecko_icon.onmouseout = function () {
  123. gecko_icon.style.opacity = menuOpen ? '1.0' : '0.0';
  124. }
  125. gecko_icon.style.transition = 'opacity 0.25s linear';
  126. document.body.appendChild(gecko_icon);
  127.  
  128. // Position the icon
  129. function repositionIcon() {
  130. gecko_icon.style.position = 'absolute';
  131. gecko_icon.style.right = '20px';
  132. gecko_icon.style.bottom = '20px';
  133. }
  134.  
  135. // Build the menu
  136. var gecko_menu = document.createElement('div');
  137. gecko_menu.id = 'gecko_menu';
  138. gecko_menu.style.zIndex = '2';
  139. gecko_menu.style.opacity = '0.0';
  140. gecko_menu.style.backgroundColor = '#7eaeca';
  141. gecko_menu.style.background = 'linear-gradient(#7db5d4,#598ca9)';
  142. gecko_menu.style.borderRadius = '4px';
  143. gecko_menu.style.padding = '0px';
  144. gecko_menu.style.boxShadow = '0px 0px 8px #000000';
  145. gecko_menu.style.transition = 'opacity 0.25s linear';
  146. var inner_div = document.createElement('div');
  147. inner_div.id = 'inner_div';
  148. inner_div.style.margin = '10px';
  149. inner_div.style.display = 'none';
  150. inner_div.innerHTML = '<div style="background-color:#070707;border-radius:4px;width:inherit;height:1em;padding:8px;">' +
  151. '<div id="gt_btn">' +
  152. '<strong>Gecko Tools 1.0.4</strong></div>' +
  153. '<div id="mm_btn">' +
  154. '<strong>Mod Manager</strong></div>' +
  155. '</div>' +
  156. '<br>' +
  157. '<div id="GT_div">' +
  158. '<table class="gt_table">' +
  159. '<tr><td><span style="color:#000000;font-weight:bold;">Custom Sounds</span>' +
  160. '<br><small>Drag and drop your sound files onto the browser window</small></td>' +
  161. '<td width=60>&nbsp;</td>' +
  162. '<td align="right"><span style="color:#47953d;font-weight:bold;background-color:#070707;' +
  163. 'border-radius:16px;padding:8px;cursor:pointer;" id="btn_sounds">On</span></td></tr>' +
  164. '<tr height=8><td></td></tr>' +
  165. '<tr><td><span style="color:#000000;font-weight:bold;">Custom Tiles</span>' +
  166. '<br><small>Drag and drop your tiles onto the browser window</small></td>' +
  167. '<td width=60>&nbsp;</td>' +
  168. '<td align="right"><span style="color:#47953d;font-weight:bold;background-color:#070707;' +
  169. 'border-radius:16px;padding:8px;cursor:pointer;" id="btn_tiles">On</span></td></tr>' +
  170. '<tr height=8><td></td></tr>' +
  171. '<tr><td><span style="color:#000000;font-weight:bold;">Custom Wallpaper</span>' +
  172. '<br><small>Drag and drop your wallpaper onto the browser window</small></td>' +
  173. '<td width=60>&nbsp;</td>' +
  174. '<td align="right"><span style="color:#47953d;font-weight:bold;background-color:#070707;' +
  175. 'border-radius:16px;padding:8px;cursor:pointer;" id="btn_wallpaper">On</span></td></tr>' +
  176. '<tr height=8><td></td></tr>' +
  177. '<tr><td><span style="color:#000000;font-weight:bold;">Transparent Background</span>' +
  178. '<br><small>Removes the black background around the outside of the map</small></td>' +
  179. '<td width=60>&nbsp;</td>' +
  180. '<td align="right"><span style="color:#ff011f;font-weight:bold;background-color:#070707;' +
  181. 'border-radius:16px;padding:8px;cursor:pointer;" id="btn_background">Off</span></td></tr>' +
  182. '<tr height=8><td></td></tr>' +
  183. /*
  184. '<tr><td><span style="color:#000000;font-weight:bold;">Maximize Viewport</span>' +
  185. '<br><small>Stretches the viewport to fill up the entire browser window</small></td>' +
  186. '<td width=60>&nbsp;</td>' +
  187. '<td align="right"><span style="color:#ff011f;font-weight:bold;background-color:#070707;' +
  188. 'border-radius:16px;padding:8px;cursor:pointer;" id="btn_maximize">Off</span></td></tr>' +
  189. '<tr height=8><td></td></tr>' +
  190. */
  191. '<tr><td><span style="color:#000000;font-weight:bold;">Hide Border</span>' +
  192. '<br><small>Hides the border around the viewport, may help FPS</small></td>' +
  193. '<td width=60>&nbsp;</td>' +
  194. '<td align="right"><span style="color:#ff011f;font-weight:bold;background-color:#070707;' +
  195. 'border-radius:16px;padding:8px;cursor:pointer;" id="btn_hideBorder">On</span></td></tr>' +
  196. '<tr height=8><td></td></tr>' +
  197. '<tr><td><span style="color:#000000;font-weight:bold;">Hide Icons</span>' +
  198. '<br><small>Hides the exit, donate, music and sound buttons during game</small></td>' +
  199. '<td width=60>&nbsp;</td>' +
  200. '<td align="right"><span style="color:#ff011f;font-weight:bold;background-color:#070707;' +
  201. 'border-radius:16px;padding:8px;cursor:pointer;" id="btn_hideIcons">On</span></td></tr>' +
  202. '</table></div>' +
  203. '<div id="MM_div" style="display:none;overflow:auto;">' +
  204. '<div class="mods" id="mods"></div>' +
  205. '</div>';
  206. document.body.appendChild(gecko_menu);
  207. gecko_menu.appendChild(inner_div);
  208.  
  209. // Toggle showing gecko tools options:
  210. var gt_btn = document.getElementById('gt_btn');
  211. var GT_div = document.getElementById('GT_div');
  212. gt_btn.onclick = show_GTdiv;
  213. function show_GTdiv() {
  214. gt_showOptions = true;
  215. gt_btn.style.backgroundColor = '#777777';
  216. mm_btn.style.backgroundColor = '#272727';
  217. GT_div.style.display = gt_showOptions ? 'block' : 'none';
  218. MM_div.style.display = gt_showOptions ? 'none' : 'block';
  219. }
  220.  
  221. // Toggle showing Mod Manager screen:
  222. var mm_btn = document.getElementById('mm_btn');
  223. var MM_div = document.getElementById('MM_div');
  224. mm_btn.onclick = show_MMdiv;
  225. function show_MMdiv() {
  226. gt_showOptions = false;
  227. mm_btn.style.backgroundColor = '#777777';
  228. gt_btn.style.backgroundColor = '#272727';
  229. var MM_height = $('#GT_div').height();
  230. GT_div.style.display = gt_showOptions ? 'block' : 'none';
  231. MM_div.style.display = gt_showOptions ? 'none' : 'block';
  232. MM_div.style.height = MM_height + 'px';
  233. if (!mm_loaded) {
  234. mm_loadMods();
  235. }
  236. }
  237.  
  238. // Populate the Mod Manager list:
  239. function mm_loadMods() {
  240. mm_loaded = true;
  241. var tpmmServer = 'http://tagpro-mod-manager.herokuapp.com';
  242. $.getJSON(''+ tpmmServer + '/mods', function (data) {
  243. var mods,
  244. ul;
  245. mods = data;
  246. ul = document.getElementById('mods');
  247. var mm_author,
  248. mm_author_text,
  249. mm_div,
  250. mm_img,
  251. mm_li,
  252. mm_mod,
  253. mm_sid,
  254. mm_title,
  255. mm_title_text,
  256. _i,
  257. _len,
  258. _results;
  259. mm_sid = mm_storedid;
  260. _results = [];
  261. for (_i = 0, _len = mods.length; _i < _len; _i++) {
  262. mod = mods[_i];
  263. li = document.createElement('li');
  264. li.dataset.modid = mod._id !== '5292f07824c79b0b50000001' ? mod._id : 'vanilla';
  265. if (mm_sid === li.dataset.modid) {
  266. li.className = 'mod sidmatch';
  267. } else {
  268. li.className = 'mod';
  269. }
  270. ul.appendChild(li);
  271. mm_div = document.createElement('div');
  272. mm_div.className = 'modinfo';
  273. mm_title = document.createElement('div');
  274. mm_title.className = 'modtitle';
  275. mm_div.appendChild(mm_title);
  276. mm_title_text = document.createTextNode(mod.name);
  277. mm_title.appendChild(mm_title_text);
  278. mm_author = document.createElement('div');
  279. mm_author.className = 'modauthor';
  280. mm_div.appendChild(mm_author);
  281. mm_author_text = document.createTextNode('By ' + mod.author);
  282. mm_author.appendChild(mm_author_text);
  283. li.appendChild(mm_div);
  284. mm_img = document.createElement('img');
  285. mm_img.src = mod.thumbnail;
  286. li.appendChild(mm_img);
  287. _results.push(li.addEventListener('click', function () {
  288. mm_sid = this.dataset.modid;
  289. mm_draw = true;
  290. $.getJSON(tpmmServer + '/files/' + this.dataset.modid, function (m_data) {
  291. GM_setValue('mm_files', JSON.stringify(m_data.files));
  292. GM_setValue('mm_storedid', mm_sid);
  293. GM_setValue('mm_draw', true);
  294. updateTilesMM();
  295. });
  296. var ele,
  297. _j,
  298. _len1,
  299. _ref;
  300. _ref = document.getElementsByClassName('mod');
  301. for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
  302. ele = _ref[_j];
  303. ele.dataset.modid == mm_sid ? ele.className = 'mod sidmatch' : ele.className = 'mod';
  304. }
  305. }));
  306. }
  307. });
  308. }
  309.  
  310. // Position the menu
  311. function repositionMenu() {
  312. gecko_menu.style.position = 'absolute';
  313. gecko_menu.style.right = (gecko_icon.width * 0.9 + 20) + 'px';
  314. gecko_menu.style.bottom = (gecko_icon.height * 0.9 + 20) + 'px';
  315. }
  316.  
  317. // Toggle the menu
  318. function toggleMenu() {
  319. menuOpen = !menuOpen;
  320. if (menuOpen) {
  321. showMenu();
  322. } else {
  323. hideMenu();
  324. }
  325. }
  326. function showMenu() {
  327. gecko_icon.style.cursor = 'pointer';
  328. gecko_menu.style.opacity = '1.0';
  329. gecko_icon.style.opacity = '1.0';
  330. inner_div.style.display = 'inline-block';
  331. }
  332. function hideMenu() {
  333. gecko_icon.style.cursor = 'default';
  334. gecko_menu.style.opacity = '0.0';
  335. gecko_icon.style.opacity = '0.0';
  336. inner_div.style.display = 'none';
  337. }
  338.  
  339. // Add drag-and-drop functionality
  340. function handleDragOver(e) {
  341. e.stopPropagation();
  342. e.preventDefault();
  343. e.dataTransfer.dropEffect = 'copy';
  344. }
  345. function handleFileSelect(e) {
  346. e.stopPropagation();
  347. e.preventDefault();
  348. var files = e.dataTransfer.files;
  349. var tileTypes = [
  350. ];
  351. var soundTypes = [
  352. ];
  353. for (var i = 0, file; file = files[i]; i++) {
  354. if (file.type.match('image.*')) {
  355. var reader = new FileReader();
  356. // Determine what kind of tile it is
  357. var name = escape(file.name);
  358. if (name.match(/[tiles|splats|speedpad|speedpadred|speedpadblue|portal]\.png/)) {
  359. mm_draw = false;
  360. GM_setValue('mm_draw', false);
  361. var regex = /(.*)\.png/;
  362. var tileType = regex.exec(name) [1];
  363. tileTypes.push(tileType);
  364. eval('reader.onload = (function(thisFile) {' +
  365. 'return function(x) {' +
  366. 'GM_setValue(\'gt_' + tileType + '\', x.target.result);' +
  367. '};' +
  368. '})(file);');
  369. } else {
  370. // It must be a wallpaper, load it as a wallpaper
  371. reader.onload = (function (thisFile) {
  372. return function (x) {
  373. GM_setValue('gt_wallpaper', x.target.result);
  374. setTimeout(function () {
  375. updateWallpaper();
  376. }, 200);
  377. };
  378. }) (file);
  379. }
  380. reader.readAsDataURL(file);
  381. } else {
  382. // Most likely a sound file
  383. var name = escape(file.name);
  384. if (name.match(/[burst|alert|cheering|drop|sigh|powerup|pop|click|explosion|countdown|friendlydrop|friendlyalert|alertlong|go|degreeup|teleport]\.[mp3|m4a|ogg]/)) {
  385. var reader = new FileReader();
  386. var regex = /(.*)\.[mp3|m4a|ogg]/;
  387. var soundType = regex.exec(name) [1];
  388. soundTypes.push(soundType);
  389. eval('reader.onload = (function(thisFile) {' +
  390. 'return function(x) {' +
  391. 'GM_setValue(\'gt_' + soundType + '\', x.target.result);' +
  392. '};' +
  393. '})(file);');
  394. reader.readAsDataURL(file);
  395. }
  396. }
  397. }
  398. //Call update on all items dropped
  399. tileTypes.length > 0 && setTimeout(function () {
  400. updateTiles();
  401. }, 100);
  402. soundTypes.length > 0 && setTimeout(function () {
  403. updateSounds();
  404. }, 100);
  405. if (tileTypes.length > 0 || soundTypes.length > 0) {
  406. message_div.style.display = 'inline-block';
  407. setTimeout(function () {
  408. message_div.style.opacity = '1.0';
  409. }, 10);
  410. setTimeout(function () {
  411. message_div.style.opacity = '0.0';
  412. setTimeout(function () {
  413. message_div.style.display = 'none';
  414. }, 250);
  415. }, 1250);
  416. }
  417. }
  418. document.documentElement.addEventListener('dragover', handleDragOver, false);
  419. document.documentElement.addEventListener('drop', handleFileSelect, false);
  420. // Toggle tiles button:
  421. var btn_tiles = document.getElementById('btn_tiles');
  422. btn_tiles.onclick = toggle_btnTiles;
  423. function toggle_btnTiles() {
  424. gt_drawTiles = !gt_drawTiles;
  425. GM_setValue('gt_drawTiles', gt_drawTiles.toString());
  426. update_btnTiles();
  427. updateTiles();
  428. }
  429. function update_btnTiles() {
  430. btn_tiles.innerHTML = gt_drawTiles == true ? 'On' : 'Off';
  431. btn_tiles.style.color = gt_drawTiles == true ? '#47953d' : '#ff011f';
  432. }
  433.  
  434. // Update the tiles:
  435. function updateTiles() {
  436. if (gt_drawTiles && GM_getValue('gt_drawTiles') && !mm_draw) {
  437. if (document.getElementById('tiles')) {
  438. var tileTypes = [
  439. 'tiles',
  440. 'splats',
  441. 'speedpad',
  442. 'speedpadred',
  443. 'speedpadblue',
  444. 'portal'
  445. ];
  446. for (var i = 0; i < tileTypes.length; i++) {
  447. if (document.getElementById(tileTypes[i])) {
  448. document.getElementById(tileTypes[i]).src = '';
  449. document.getElementById(tileTypes[i]).src = (gt_drawTiles && GM_getValue('gt_' + tileTypes[i])) ? GM_getValue('gt_' + tileTypes[i]) : 'http://' + document.location.hostname + '/images/' + tileTypes[i] + '.png';
  450. }
  451. }
  452. setTimeout(unsafeWindow.tagpro.api.redrawBackground, 100);
  453. }
  454. }
  455. }
  456.  
  457. // Update the tiles with mod manager:
  458. function updateTilesMM() {
  459. if (gt_drawTiles && GM_getValue('mm_files') && mm_draw) {
  460. files = JSON.parse(GM_getValue('mm_files'));
  461. if (document.getElementById('tiles')) {
  462. var tileTypes = [
  463. 'tiles',
  464. 'splats',
  465. 'speedpad',
  466. 'speedpadred',
  467. 'speedpadblue',
  468. 'portal'
  469. ];
  470. for (i in tileTypes) {
  471. if (document.getElementById(tileTypes[i])) {
  472. document.getElementById(tileTypes[i]).src = '';
  473. document.getElementById(tileTypes[i]).src = files[tileTypes[i]] != undefined ? files[tileTypes[i]] : 'http://' + document.location.hostname + '/images/' + tileTypes[i] + '.png';
  474. }
  475. }
  476. setTimeout(unsafeWindow.tagpro.api.redrawBackground, 100);
  477. }
  478. }
  479. }
  480.  
  481. // Toggle sounds button:
  482. var btn_sounds = document.getElementById('btn_sounds');
  483. btn_sounds.onclick = toggle_btnSounds;
  484. function toggle_btnSounds() {
  485. gt_customSounds = !gt_customSounds;
  486. GM_setValue('gt_customSounds', gt_customSounds.toString());
  487. update_btnSounds();
  488. updateSounds();
  489. }
  490. function update_btnSounds() {
  491. btn_sounds.innerHTML = gt_customSounds == true ? 'On' : 'Off';
  492. btn_sounds.style.color = gt_customSounds == true ? '#47953d' : '#ff011f';
  493. }
  494.  
  495. // Update the sounds
  496. function updateSounds() {
  497. if (document.getElementById('countdown')) {
  498. var soundTypes = [
  499. 'burst',
  500. 'alert',
  501. 'cheering',
  502. 'drop',
  503. 'sigh',
  504. 'powerup',
  505. 'pop',
  506. 'click',
  507. 'explosion',
  508. 'countdown',
  509. 'friendlydrop',
  510. 'friendlyalert',
  511. 'alertlong',
  512. 'go',
  513. 'degreeup',
  514. 'teleport'
  515. ];
  516. for (var i = 0; i < soundTypes.length; i++) {
  517. if (document.getElementById(soundTypes[i])) {
  518. if (gt_customSounds && GM_getValue('gt_' + soundTypes[i]) != undefined) {
  519. var newSource = document.createElement('source');
  520. newSource.src = GM_getValue('gt_' + soundTypes[i]);
  521. var regex = /data:(.*);base64/;
  522. var type = regex.exec(newSource.src) [1];
  523. newSource.type = type;
  524. var audioTag = eval('document.getElementsByTagName("audio").' + soundTypes[i]);
  525. audioTag.innerHTML = '';
  526. audioTag.appendChild(newSource);
  527. audioTag.load();
  528. } else {
  529. var audioTag = eval('document.getElementsByTagName("audio").' + soundTypes[i]);
  530. audioTag.innerHTML = '<source type="audio/mp3" src="http://' + document.location.hostname + '/sounds/' + soundTypes[i] + '.mp3"></source><source type="audio/m4a" src="http://' + document.location.hostname + '/sounds/' + soundTypes[i] + '.m4a"></source><source type="audio/ogg" src="http://' + document.location.hostname + '/sounds/' + soundTypes[i] + '.ogg"></source>';
  531. audioTag.load();
  532. }
  533. }
  534. }
  535. }
  536. }
  537.  
  538. // Toggle wallpaper button:
  539. var btn_wallpaper = document.getElementById('btn_wallpaper');
  540. btn_wallpaper.onclick = toggle_btnWallpaper;
  541. function toggle_btnWallpaper() {
  542. gt_drawWallpaper = !gt_drawWallpaper;
  543. GM_setValue('gt_drawWallpaper', gt_drawWallpaper.toString());
  544. update_btnWallpaper();
  545. updateWallpaper();
  546. }
  547. function update_btnWallpaper() {
  548. btn_wallpaper.innerHTML = gt_drawWallpaper == true ? 'On' : 'Off';
  549. btn_wallpaper.style.color = gt_drawWallpaper == true ? '#47953d' : '#ff011f';
  550. }
  551.  
  552. // Update the wallpaper
  553. function updateWallpaper() {
  554. if (gt_drawWallpaper && GM_getValue('gt_wallpaper')) {
  555. document.documentElement.style.background = 'url(' + GM_getValue('gt_wallpaper') + ')';
  556. } else {
  557. document.documentElement.style.background = 'url("http://' + document.location.hostname + '/images/background.jpg")';
  558. }
  559. document.documentElement.style.backgroundRepeat = 'no-repeat';
  560. document.documentElement.style.backgroundAttachment = 'fixed';
  561. document.documentElement.style.backgroundPosition = 'center center';
  562. document.documentElement.style.backgroundSize = 'cover';
  563. }
  564.  
  565. // Toggle background button:
  566. var btn_background = document.getElementById('btn_background');
  567. btn_background.onclick = toggle_btnBackground;
  568. function toggle_btnBackground() {
  569. gt_transparentBackground = !gt_transparentBackground;
  570. GM_setValue('gt_transparentBackground', gt_transparentBackground.toString());
  571. update_btnBackground();
  572. }
  573. function update_btnBackground() {
  574. btn_background.innerHTML = gt_transparentBackground == true ? 'On' : 'Off';
  575. btn_background.style.color = gt_transparentBackground == true ? '#47953d' : '#ff011f';
  576. updateBackground();
  577. }
  578. function updateBackground() {
  579. if (document.getElementById('viewPortDiv')) {
  580. var vp = document.getElementById('viewPort');
  581. vp.style.backgroundColor = gt_transparentBackground ? 'rgba(0,0,0,0)' : 'black';
  582. var vpd = document.getElementById('viewPortDiv');
  583. vpd.style.backgroundColor = gt_transparentBackground ? 'rgba(0,0,0,0)' : 'black';
  584. }
  585. }
  586.  
  587. /*
  588.  
  589. //TODO: FIX MAXIMIZE, NEED THE LATEST PATCH TO BE ON MAPTEST
  590.  
  591. // Toggle maximize button:
  592. var btn_maximize = document.getElementById('btn_maximize');
  593. btn_maximize.onclick = toggle_btnMaximize;
  594. function toggle_btnMaximize() {
  595. gt_maximize = !gt_maximize;
  596. GM_setValue('gt_maximize', gt_maximize.toString());
  597. update_btnMaximize();
  598. updateMaximize();
  599. }
  600. function update_btnMaximize() {
  601. btn_maximize.innerHTML = gt_maximize == true ? 'On' : 'Off';
  602. btn_maximize.style.color = gt_maximize == true ? '#47953d' : '#ff011f';
  603. }
  604. function updateMaximize() {
  605. if (document.getElementById('viewPort')) {
  606. var vp = document.getElementById('viewPort');
  607. var vpd = document.getElementById('viewPortDiv');
  608. var vw = vpd.width;
  609. var vh = vpd.height;
  610. if (gt_maximize) {
  611. // Stetch to fit while maintaining aspect ratio
  612. var w = window.innerWidth;
  613. var h = window.innerHeight;
  614. var ratio = w / h;
  615. if (ratio > vw / vh) {
  616. // Width dominates, the top/bottom will have to be clipped
  617. vp.style.width = w + 'px';
  618. vp.style.height = w * (vh / vw) + 'px';
  619. vp.style.marginLeft = '0px';
  620. vp.style.marginTop = (window.innerHeight - parseInt(vp.style.height)) / 2 + 'px';
  621. vpd.style.width = w + 'px';
  622. vpd.style.height = w * (vh / vw) + 'px';
  623. vpd.style.marginLeft = '0px';
  624. vpd.style.marginTop = (window.innerHeight - parseInt(vp.style.height)) / 2 + 'px';
  625. } else {
  626. // Height dominates, the left/right will have to be clipped
  627. vp.style.height = h + 'px';
  628. vp.style.width = h * (vw / vh) + 'px';
  629. vp.style.marginTop = '0px';
  630. vp.style.marginLeft = (window.innerWidth - parseInt(vp.style.width)) / 2 + 'px';
  631. vpd.style.height = h + 'px';
  632. vpd.style.width = h * (vw / vh) + 'px';
  633. vpd.style.marginTop = '0px';
  634. vpd.style.marginLeft = (window.innerWidth - parseInt(vp.style.width)) / 2 + 'px';
  635. }
  636. vp.style.border = 'none';
  637. } else {
  638. // Revert back to normal
  639. vp.style.width = vw + 'px';
  640. vp.style.height = vh + 'px';
  641. vp.style.border = '10px solid white';
  642. vp.style.marginTop = (window.innerHeight - (vh + 20)) / 2 + 'px';
  643. vp.style.marginLeft = (window.innerWidth - (vw + 20)) / 2 + 'px';
  644. }
  645. }
  646. }
  647.  
  648. */
  649.  
  650. // Toggle border button:
  651. var btn_hideBorder = document.getElementById('btn_hideBorder');
  652. btn_hideBorder.onclick = toggle_btnHideBorder;
  653. function toggle_btnHideBorder() {
  654. gt_hideBorder = !gt_hideBorder;
  655. GM_setValue('gt_hideBorder', gt_hideBorder.toString());
  656. update_btnHideBorder();
  657. updateHideBorder();
  658. }
  659. function update_btnHideBorder() {
  660. btn_hideBorder.innerHTML = gt_hideBorder == true ? 'On' : 'Off';
  661. btn_hideBorder.style.color = gt_hideBorder == true ? '#47953d' : '#ff011f';
  662. }
  663.  
  664. // Update the border
  665. function updateHideBorder() {
  666. if (document.getElementById('viewPortDiv')){
  667. var vpd = document.getElementById('viewPortDiv');
  668. gt_hideBorder ? vpd.style.border = 'none' : vpd.style.border = '10px solid white';
  669. }
  670. }
  671.  
  672. // Toggle icons button:
  673. var btn_hideIcons = document.getElementById('btn_hideIcons');
  674. btn_hideIcons.onclick = toggle_btnHideIcons;
  675. function toggle_btnHideIcons() {
  676. gt_hideIcons = !gt_hideIcons;
  677. GM_setValue('gt_hideIcons', gt_hideIcons.toString());
  678. update_btnHideIcons();
  679. updateHideIcons();
  680. }
  681. function update_btnHideIcons() {
  682. btn_hideIcons.innerHTML = gt_hideIcons == true ? 'On' : 'Off';
  683. btn_hideIcons.style.color = gt_hideIcons == true ? '#47953d' : '#ff011f';
  684. }
  685.  
  686. // Update the icons
  687. function updateHideIcons() {
  688. if (gt_hideIcons) {
  689. if (document.getElementById('soundEffects')) {
  690. document.getElementById('soundEffects').style.visibility = 'hidden';
  691. document.getElementById('soundEffects').style.display = 'none';
  692. }
  693. if (document.getElementById('soundMusic')) {
  694. document.getElementById('soundMusic').style.visibility = 'hidden';
  695. document.getElementById('soundMusic').style.display = 'none';
  696. }
  697. if (document.getElementById('exit')) {
  698. document.getElementById('exit').style.visibility = 'hidden';
  699. document.getElementById('exit').style.display = 'none';
  700. }
  701. if (document.getElementById('donate')) {
  702. document.getElementById('donate').style.visibility = 'hidden';
  703. document.getElementById('donate').style.display = 'none';
  704. }
  705. } else {
  706. if (document.getElementById('soundEffects')) {
  707. document.getElementById('soundEffects').style.visibility = 'visible';
  708. document.getElementById('soundEffects').style.display = 'inline-block';
  709. }
  710. if (document.getElementById('soundMusic')) {
  711. document.getElementById('soundMusic').style.visibility = 'visible';
  712. document.getElementById('soundMusic').style.display = 'inline-block';
  713. }
  714. if (document.getElementById('exit')) {
  715. document.getElementById('exit').style.visibility = 'visible';
  716. document.getElementById('exit').style.display = 'inline-block';
  717. }
  718. if (document.getElementById('donate')) {
  719. document.getElementById('donate').style.visibility = 'visible';
  720. document.getElementById('donate').style.display = 'inline-block';
  721. }
  722. }
  723. }
  724.  
  725. // Position menu and load initial button states
  726. setTimeout(function () {
  727. repositionIcon();
  728. repositionMenu();
  729. update_btnTiles();
  730. updateTiles();
  731. updateTilesMM();
  732. update_btnSounds();
  733. updateSounds();
  734. update_btnWallpaper();
  735. update_btnBackground();
  736. updateBackground();
  737. updateWallpaper();
  738. update_btnHideIcons();
  739. updateHideIcons();
  740. update_btnHideBorder();
  741. setTimeout(updateHideBorder, 1000);
  742. }, 100);
  743.  
  744. // Handle resize event
  745. window.onresize = function () {
  746. repositionIcon();
  747. repositionMenu();
  748. if (resizeTimer) {
  749. clearTimeout(resizeTimer);
  750. resizeTimer = false;
  751. }
  752. resizeTimer = setTimeout(function () {
  753. updateHideBorder();
  754. resizeTimer = false;
  755. tagpro.ui.resize();
  756. }, 1100);
  757. }
  758. });
Add Comment
Please, Sign In to add comment