Advertisement
Guest User

Untitled

a guest
May 8th, 2014
1,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.04 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Gecko Tools
  3. // @namespace http://www.reddit.com/user/GekkoPie
  4. // @description A suite of customization options for TagPro
  5. // @include http://tagpro-*.koalabeast.com:*
  6. // @include http://tangent.jukejuice.com*
  7. // @include http://secant.jukejuice.com:*
  8. // @include http://maptest.newcompte.fr:*
  9. // @include http://justletme.be:*
  10. // @license GNU General Public License
  11. // @author GeckoPie
  12. // @version 1.0.0
  13. // ==/UserScript==
  14.  
  15. /******************************************
  16. ****** GLOBAL CONFIGURATION SETTINGS ******
  17. *******************************************/
  18. window.menuOpen = false;
  19. window.resizeTimer = false;
  20.  
  21. // Load settings from local storage
  22. window.gt_customSounds = true;
  23. if (GM_getValue('gt_customSounds') != undefined) {
  24. gt_customSounds = eval(GM_getValue('gt_customSounds'));
  25. }
  26.  
  27. window.gt_drawTiles = true;
  28. if (GM_getValue('gt_drawTiles') != undefined) {
  29. gt_drawTiles = eval(GM_getValue('gt_drawTiles'));
  30. }
  31.  
  32. window.gt_drawWallpaper = true;
  33. if (GM_getValue('gt_drawWallpaper') != undefined) {
  34. gt_drawWallpaper = eval(GM_getValue('gt_drawWallpaper'));
  35. }
  36.  
  37. window.gt_transparentBackground = false;
  38. if (GM_getValue('gt_transparentBackground') != undefined) {
  39. gt_transparentBackground = eval(GM_getValue('gt_transparentBackground'));
  40. }
  41.  
  42. window.gt_maximize= false;
  43. if (GM_getValue('gt_maximize') != undefined) {
  44. gt_maximize = eval(GM_getValue('gt_maximize'));
  45. }
  46.  
  47. window.gt_hideIcons = true;
  48. if (GM_getValue('gt_hideIcons') != undefined) {
  49. gt_hideIcons = eval(GM_getValue('gt_hideIcons'));
  50. }
  51.  
  52. window.addEventListener('DOMContentLoaded', function(e) {
  53.  
  54. /*******************************************
  55. ****** CONSTRUCT THE GECKO TOOLS MENU ******
  56. ********************************************/
  57.  
  58. // Build the message div
  59. var message_div = document.createElement("div");
  60. message_div.width = "140px";
  61. message_div.style.opacity = "0.0";
  62. message_div.style.display = "none";
  63. message_div.style.bottom = "20px";
  64. message_div.style.marginLeft = "50%"
  65. message_div.style.left = "-70px";
  66. message_div.style.position = "absolute";
  67. message_div.style.backgroundColor = "#070707";
  68. message_div.style.color="#47953d";
  69. message_div.style.borderRadius="4px";
  70. message_div.style.padding="8px";
  71. message_div.innerHTML = "Files Accepted";
  72. message_div.style.transition="opacity 0.25s linear";
  73. document.body.appendChild(message_div);
  74.  
  75.  
  76. // Build the icon
  77. var gecko_icon = document.createElement("img");
  78. gecko_icon.src = "http://i.imgur.com/eenIpmO.png";
  79. gecko_icon.onclick=toggleMenu;
  80. gecko_icon.style.opacity="0.0";
  81. gecko_icon.onmouseover= function(){gecko_icon.style.opacity="1.0";gecko_icon.style.cursor="pointer";}
  82. gecko_icon.onmouseout = function(){gecko_icon.style.opacity= menuOpen ? "1.0" : "0.0";}
  83. gecko_icon.style.transition="opacity 0.25s linear";
  84. document.body.appendChild(gecko_icon);
  85.  
  86.  
  87. // Position the icon
  88. function repositionIcon() {
  89. gecko_icon.style.position="absolute";
  90. gecko_icon.style.right = "20px";
  91. gecko_icon.style.bottom = "20px";
  92. }
  93.  
  94. // Build the menu
  95. var gecko_menu = document.createElement("div");
  96. gecko_menu.style.opacity="0.0";
  97. gecko_menu.style.backgroundColor="#7eaeca";
  98. gecko_menu.style.background="linear-gradient(#7db5d4,#598ca9)";
  99. gecko_menu.style.borderRadius="4px";
  100. gecko_menu.style.padding="0px";
  101. gecko_menu.style.boxShadow="0px 0px 8px #000000";
  102. gecko_menu.style.transition="opacity 0.25s linear";
  103.  
  104. var inner_div = document.createElement("div");
  105. inner_div.style.margin="10px";
  106. inner_div.style.display="none";
  107. inner_div.innerHTML="<div style=\"background-color:#070707;border-radius:4px;width:inherit;padding:8px;\">" +
  108. "<strong style=\"color:#47953d;\">Gecko Tools 1.0.0</strong></div>" +
  109. "<br>" +
  110. "<table>" +
  111.  
  112. "<tr><td><span style=\"color:#000000;font-weight:bold;\">Custom Sounds</span>" +
  113. "<br><small>Drag and drop your sound files onto the browser window</small></td>" +
  114. "<td width=60>&nbsp;</td>" +
  115. "<td align=\"right\"><span style=\"color:#47953d;font-weight:bold;background-color:#070707;" +
  116. "border-radius:16px;padding:8px;cursor:pointer;\" id=\"btn_sounds\">On</span></td></tr>" +
  117.  
  118. "<tr height=8><td></td></tr>" +
  119.  
  120. "<tr><td><span style=\"color:#000000;font-weight:bold;\">Custom Tiles</span>" +
  121. "<br><small>Drag and drop your tiles onto the browser window</small></td>" +
  122. "<td width=60>&nbsp;</td>" +
  123. "<td align=\"right\"><span style=\"color:#47953d;font-weight:bold;background-color:#070707;" +
  124. "border-radius:16px;padding:8px;cursor:pointer;\" id=\"btn_tiles\">On</span></td></tr>" +
  125.  
  126. "<tr height=8><td></td></tr>" +
  127.  
  128. "<tr><td><span style=\"color:#000000;font-weight:bold;\">Custom Wallpaper</span>" +
  129. "<br><small>Drag and drop your wallpaper onto the browser window</small></td>" +
  130. "<td width=60>&nbsp;</td>" +
  131. "<td align=\"right\"><span style=\"color:#47953d;font-weight:bold;background-color:#070707;" +
  132. "border-radius:16px;padding:8px;cursor:pointer;\" id=\"btn_wallpaper\">On</span></td></tr>" +
  133.  
  134. "<tr height=8><td></td></tr>" +
  135.  
  136. "<tr><td><span style=\"color:#000000;font-weight:bold;\">Transparent Background</span>" +
  137. "<br><small>Removes the black background around the outside of the map</small></td>" +
  138. "<td width=60>&nbsp;</td>" +
  139. "<td align=\"right\"><span style=\"color:#ff011f;font-weight:bold;background-color:#070707;" +
  140. "border-radius:16px;padding:8px;cursor:pointer;\" id=\"btn_background\">Off</span></td></tr>" +
  141.  
  142. "<tr height=8><td></td></tr>" +
  143.  
  144. "<tr><td><span style=\"color:#000000;font-weight:bold;\">Maximize Viewport</span>" +
  145. "<br><small>Stretches the viewport to fill up the entire browser window</small></td>" +
  146. "<td width=60>&nbsp;</td>" +
  147. "<td align=\"right\"><span style=\"color:#ff011f;font-weight:bold;background-color:#070707;" +
  148. "border-radius:16px;padding:8px;cursor:pointer;\" id=\"btn_maximize\">Off</span></td></tr>" +
  149.  
  150. "<tr height=8><td></td></tr>" +
  151.  
  152. "<tr><td><span style=\"color:#000000;font-weight:bold;\">Hide Icons</span>" +
  153. "<br><small>Hides the exit, donate, music and sound buttons during game</small></td>" +
  154. "<td width=60>&nbsp;</td>" +
  155. "<td align=\"right\"><span style=\"color:#ff011f;font-weight:bold;background-color:#070707;" +
  156. "border-radius:16px;padding:8px;cursor:pointer;\" id=\"btn_hideIcons\">On</span></td></tr>" +
  157.  
  158. "</table>";
  159.  
  160. document.body.appendChild(gecko_menu);
  161. gecko_menu.appendChild(inner_div);
  162.  
  163. // Position the menu
  164. function repositionMenu() {
  165. gecko_menu.style.position="absolute";
  166. gecko_menu.style.right = (gecko_icon.width*0.9 + 20) + "px";
  167. gecko_menu.style.bottom = (gecko_icon.height*0.9 + 20) + "px";
  168. }
  169.  
  170. // Toggle the menu
  171. function toggleMenu() {
  172. menuOpen = !menuOpen;
  173. if (menuOpen) {
  174. showMenu();
  175. } else {
  176. hideMenu();
  177. }
  178. }
  179.  
  180. function showMenu() {
  181. gecko_icon.style.cursor="pointer";
  182. gecko_menu.style.opacity = "1.0";
  183. gecko_icon.style.opacity="1.0";
  184. inner_div.style.display="inline-block";
  185. }
  186.  
  187. function hideMenu() {
  188. gecko_icon.style.cursor="default";
  189. gecko_menu.style.opacity="0.0";
  190. gecko_icon.style.opacity="0.0";
  191. inner_div.style.display="none";
  192. }
  193.  
  194. // Add drag-and-drop functionality
  195. function handleDragOver(e) {
  196. e.stopPropagation();
  197. e.preventDefault();
  198. e.dataTransfer.dropEffect = 'copy';
  199. }
  200. function handleFileSelect(e) {
  201. e.stopPropagation();
  202. e.preventDefault();
  203.  
  204. var files = e.dataTransfer.files;
  205. var tileTypes = [];
  206. var soundTypes = [];
  207. for(var i = 0, file; file = files[i]; i++) {
  208. if(file.type.match('image.*')) {
  209. var reader = new FileReader();
  210.  
  211. // Determine what kind of tile it is
  212. var name = escape(file.name);
  213. if (name.match(/[tiles|splats|speedpad|speedpadred|speedpadblue|portal]\.png/)) {
  214. var regex = /(.*)\.png/;
  215. var tileType = regex.exec(name)[1];
  216. tileTypes.push(tileType);
  217. eval("reader.onload = (function(thisFile) {"+
  218. "return function(x) {"+
  219. "GM_setValue('gt_" + tileType + "', x.target.result);"+
  220. "};"+
  221. "})(file);");
  222. } else {
  223. // It must be a wallpaper, load it as a wallpaper
  224. reader.onload = (function(thisFile) {
  225. return function(x) {
  226. GM_setValue('gt_wallpaper', x.target.result);
  227. setTimeout(function(){updateWallpaper();},2e2);
  228. };
  229. })(file);
  230. }
  231. reader.readAsDataURL(file);
  232. } else {
  233.  
  234. // Most likely a sound file
  235. var name = escape(file.name);
  236. if (name.match(/[burst|alert|cheering|drop|sigh|powerup|pop|click|explosion|countdown|friendlydrop|friendlyalert|alertlong|go|degreeup|teleport]\.[mp3|m4a|ogg]/)) {
  237. var reader = new FileReader();
  238. var regex = /(.*)\.[mp3|m4a|ogg]/;
  239. var soundType = regex.exec(name)[1];
  240. soundTypes.push(soundType);
  241. eval("reader.onload = (function(thisFile) {"+
  242. "return function(x) {"+
  243. "GM_setValue('gt_" + soundType + "', x.target.result);"+
  244. "};"+
  245. "})(file);");
  246. reader.readAsDataURL(file);
  247. }
  248. }
  249. }
  250. //Call update on all items dropped
  251. tileTypes.length > 0 && setTimeout(function(){updateTiles();},1e2);
  252. soundTypes.length > 0 && setTimeout(function(){updateSounds();},1e2);
  253. if (tileTypes.length > 0 || soundTypes.length > 0) {
  254. message_div.style.display = "inline-block";
  255. setTimeout(function() {message_div.style.opacity = "1.0";},10);
  256. setTimeout(function() {
  257. message_div.style.opacity = "0.0";
  258. setTimeout(function() {
  259. message_div.style.display = "none";
  260. },0.25e3);
  261. }, 1.25e3);
  262. }
  263.  
  264. }
  265. document.documentElement.addEventListener('dragover', handleDragOver, false);
  266. document.documentElement.addEventListener('drop', handleFileSelect, false);
  267.  
  268. // Toggle tiles button:
  269. var btn_tiles = document.getElementById("btn_tiles");
  270. btn_tiles.onclick=toggle_btnTiles;
  271. function toggle_btnTiles(){
  272. gt_drawTiles = !gt_drawTiles;
  273. GM_setValue('gt_drawTiles',gt_drawTiles.toString());
  274. update_btnTiles();
  275. updateTiles();
  276. }
  277. function update_btnTiles() {
  278. btn_tiles.innerHTML = gt_drawTiles == true ? "On" : "Off";
  279. btn_tiles.style.color = gt_drawTiles == true ? "#47953d" : "#ff011f";
  280. }
  281. // Update the tiles:
  282. function updateTiles() {
  283. if (document.getElementById('tiles')) {
  284. var tileTypes = ['tiles','splats','speedpad','speedpadred','speedpadblue','portal'];
  285. for (var i=0; i<tileTypes.length; i++) {
  286. if(document.getElementById(tileTypes[i])) {
  287. document.getElementById(tileTypes[i]).src = "";
  288. 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";
  289. }
  290. }
  291. setTimeout(unsafeWindow.tagpro.api.redrawBackground,1e2);
  292. }
  293. }
  294.  
  295. // Toggle sounds button:
  296. var btn_sounds = document.getElementById("btn_sounds");
  297. btn_sounds.onclick=toggle_btnSounds;
  298. function toggle_btnSounds(){
  299. gt_customSounds = !gt_customSounds;
  300. GM_setValue('gt_customSounds',gt_customSounds.toString());
  301. update_btnSounds();
  302. updateSounds();
  303. }
  304. function update_btnSounds() {
  305. btn_sounds.innerHTML = gt_customSounds == true ? "On" : "Off";
  306. btn_sounds.style.color = gt_customSounds == true ? "#47953d" : "#ff011f";
  307. }
  308. // Update the sounds
  309. function updateSounds() {
  310. if (document.getElementById('countdown')) {
  311. var soundTypes = ['burst', 'alert', 'cheering', 'drop', 'sigh', 'powerup', 'pop', 'click', 'explosion', 'countdown', 'friendlydrop', 'friendlyalert', 'alertlong', 'go', 'degreeup', 'teleport'];
  312. for (var i=0; i<soundTypes.length; i++) {
  313. if(document.getElementById(soundTypes[i])) {
  314. if (gt_customSounds && GM_getValue('gt_' + soundTypes[i]) != undefined) {
  315. var newSource = document.createElement('source');
  316. newSource.src = GM_getValue('gt_' + soundTypes[i]);
  317. var regex = /data:(.*);base64/;
  318. var type = regex.exec(newSource.src)[1];
  319. newSource.type = type;
  320. var audioTag = eval("document.getElementsByTagName(\"audio\")." + soundTypes[i]);
  321. audioTag.innerHTML = "";
  322. audioTag.appendChild(newSource);
  323. audioTag.load();
  324. } else {
  325. var audioTag = eval("document.getElementsByTagName(\"audio\")." + soundTypes[i]);
  326. 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>";
  327. audioTag.load();
  328. }
  329. }
  330. }
  331. }
  332. }
  333.  
  334. // Toggle wallpaper button:
  335. var btn_wallpaper = document.getElementById("btn_wallpaper");
  336. btn_wallpaper.onclick=toggle_btnWallpaper;
  337. function toggle_btnWallpaper(){
  338. gt_drawWallpaper = !gt_drawWallpaper;
  339. GM_setValue('gt_drawWallpaper',gt_drawWallpaper.toString());
  340. update_btnWallpaper();
  341. updateWallpaper();
  342. }
  343. function update_btnWallpaper() {
  344. btn_wallpaper.innerHTML = gt_drawWallpaper == true ? "On" : "Off";
  345. btn_wallpaper.style.color = gt_drawWallpaper == true ? "#47953d" : "#ff011f";
  346. }
  347. // Update the wallpaper
  348. function updateWallpaper() {
  349. if (gt_drawWallpaper && GM_getValue('gt_wallpaper')) {
  350. document.documentElement.style.background = "url(" + GM_getValue('gt_wallpaper') + ")";
  351. } else {
  352. document.documentElement.style.background = "url(\"http://" + document.location.hostname + "/images/background.jpg\")";
  353. }
  354. document.documentElement.style.backgroundRepeat = "no-repeat";
  355. document.documentElement.style.backgroundAttachment = "fixed";
  356. document.documentElement.style.backgroundPosition = "center center";
  357. document.documentElement.style.backgroundSize = "cover";
  358. }
  359.  
  360. // Toggle background button:
  361. var btn_background = document.getElementById("btn_background");
  362. btn_background.onclick=toggle_btnBackground;
  363. function toggle_btnBackground(){
  364. gt_transparentBackground = !gt_transparentBackground;
  365. GM_setValue('gt_transparentBackground',gt_transparentBackground.toString());
  366. update_btnBackground();
  367. }
  368. function update_btnBackground() {
  369. btn_background.innerHTML = gt_transparentBackground == true ? "On" : "Off";
  370. btn_background.style.color = gt_transparentBackground == true ? "#47953d" : "#ff011f";
  371. updateBackground();
  372. }
  373. function updateBackground() {
  374. if (document.getElementById("viewPort")) {
  375. var vp = document.getElementById("viewPort");
  376. vp.style.backgroundColor = gt_transparentBackground ? "rgba(0,0,0,0)" : "black";
  377. }
  378. }
  379.  
  380. // Toggle maximize button:
  381. var btn_maximize = document.getElementById("btn_maximize");
  382. btn_maximize.onclick=toggle_btnMaximize;
  383. function toggle_btnMaximize(){
  384. gt_maximize = !gt_maximize;
  385. GM_setValue('gt_maximize',gt_maximize.toString());
  386. update_btnMaximize();
  387. updateMaximize();
  388. }
  389. function update_btnMaximize() {
  390. btn_maximize.innerHTML = gt_maximize == true ? "On" : "Off";
  391. btn_maximize.style.color = gt_maximize == true ? "#47953d" : "#ff011f";
  392. }
  393. function updateMaximize() {
  394. if (document.getElementById("viewPort")) {
  395. var vp = document.getElementById("viewPort");
  396. var vw = vp.width;
  397. var vh = vp.height;
  398. if (gt_maximize) {
  399. // Stetch to fit while maintaining aspect ratio
  400. var w = window.innerWidth;
  401. var h = window.innerHeight;
  402. var ratio = w/h;
  403. if (ratio > vw/vh) {
  404. // Width dominates, the top/bottom will have to be clipped
  405. vp.style.width = w + "px";
  406. vp.style.height = w*(vh/vw) + "px";
  407. vp.style.marginLeft = "0px";
  408. vp.style.marginTop = (window.innerHeight - parseInt(vp.style.height))/2 + "px";
  409. } else {
  410. // Height dominates, the left/right will have to be clipped
  411. vp.style.height = h + "px";
  412. vp.style.width = h*(vw/vh) + "px";
  413. vp.style.marginTop = "0px";
  414. vp.style.marginLeft = (window.innerWidth - parseInt(vp.style.width))/2 + "px";
  415. }
  416. vp.style.border = "none";
  417. } else {
  418. // Revert back to normal
  419. vp.style.width = vw + "px";
  420. vp.style.height = vh + "px";
  421. vp.style.border = "10px solid white";
  422. vp.style.marginTop = (window.innerHeight - (vh + 20))/2 + "px";
  423. vp.style.marginLeft = (window.innerWidth - (vw + 20))/2 + "px";
  424. }
  425. }
  426. }
  427.  
  428. // Toggle icons button:
  429. var btn_hideIcons = document.getElementById("btn_hideIcons");
  430. btn_hideIcons.onclick=toggle_btnHideIcons;
  431. function toggle_btnHideIcons(){
  432. gt_hideIcons = !gt_hideIcons;
  433. GM_setValue('gt_hideIcons',gt_hideIcons.toString());
  434. update_btnHideIcons();
  435. updateHideIcons();
  436. }
  437. function update_btnHideIcons() {
  438. btn_hideIcons.innerHTML = gt_hideIcons == true ? "On" : "Off";
  439. btn_hideIcons.style.color = gt_hideIcons == true ? "#47953d" : "#ff011f";
  440. }
  441. // Update the icons
  442. function updateHideIcons() {
  443. if (gt_hideIcons) {
  444. if (document.getElementById("soundEffects")) {
  445. document.getElementById("soundEffects").style.visibility="hidden";
  446. document.getElementById("soundEffects").style.display="none";
  447. }
  448. if (document.getElementById("soundMusic")) {
  449. document.getElementById("soundMusic").style.visibility="hidden";
  450. document.getElementById("soundMusic").style.display="none";
  451. }
  452. if (document.getElementById("exit")) {
  453. document.getElementById("exit").style.visibility="hidden";
  454. document.getElementById("exit").style.display="none";
  455. }
  456. if (document.getElementById("donate")) {
  457. document.getElementById("donate").style.visibility="hidden";
  458. document.getElementById("donate").style.display="none";
  459. }
  460. } else {
  461. if (document.getElementById("soundEffects")) {
  462. document.getElementById("soundEffects").style.visibility="visible";
  463. document.getElementById("soundEffects").style.display="inline-block";
  464. }
  465. if (document.getElementById("soundMusic")) {
  466. document.getElementById("soundMusic").style.visibility="visible";
  467. document.getElementById("soundMusic").style.display="inline-block";
  468. }
  469. if (document.getElementById("exit")) {
  470. document.getElementById("exit").style.visibility="visible";
  471. document.getElementById("exit").style.display="inline-block";
  472. }
  473. if (document.getElementById("donate")) {
  474. document.getElementById("donate").style.visibility="visible";
  475. document.getElementById("donate").style.display="inline-block";
  476. }
  477. }
  478. }
  479.  
  480. // Position menu and load initial button states
  481. setTimeout(function() {
  482. repositionIcon();
  483. repositionMenu();
  484. update_btnTiles();
  485. updateTiles();
  486. update_btnSounds();
  487. updateSounds();
  488. update_btnWallpaper();
  489. update_btnBackground();
  490. updateBackground();
  491. updateWallpaper();
  492. update_btnHideIcons();
  493. updateHideIcons();
  494. update_btnMaximize();
  495. setTimeout(updateMaximize,1e3);
  496. }, 1e2);
  497.  
  498. // Handle resize event
  499. window.onresize=function(){
  500. repositionIcon();
  501. repositionMenu();
  502.  
  503. if (resizeTimer) {
  504. clearTimeout(resizeTimer);
  505. resizeTimer = false;
  506. }
  507. resizeTimer = setTimeout(function() {
  508. updateMaximize();
  509. resizeTimer = false;
  510. }, 1100);
  511. }
  512.  
  513. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement