k11235

Недоделанный шаблонер

Apr 8th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. // ==UserScript==
  2. // @name pixelplanet.fun template
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.0.1
  5. // @description try to take over the world!
  6. // @include https://pixelplanet.fun/*
  7. // @author LohPidr
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /*
  12. Картинка
  13. https://raw.githubusercontent.com/TheGorox/pixelPlanetTemplate/master/images/anime.png
  14. */
  15.  
  16. var x;
  17. var y;
  18. var zoom;
  19.  
  20. var tplbox__body;
  21. var tplbox__titletext;
  22. var tplbox__url;
  23. var tplbox__transparency;
  24. var tplbox__visibility;
  25. var gameWindow;
  26.  
  27. var storage_hidden;
  28. var storage_url;
  29. var storage_transparency;
  30. var storage_showtemplate;
  31.  
  32. var template;
  33.  
  34. window.addEventListener('load', function () {
  35.  
  36. storage_hidden = localStorage.getItem('tplbox.hidden') || 0;
  37. storage_url = localStorage.getItem('tplbox.url') || '';
  38. storage_transparency = localStorage.getItem('tplbox.transparency') || 0.5;
  39. storage_showtemplate = localStorage.getItem('tplbox.showtemplate') || 1;
  40.  
  41. if(storage_url != '') {
  42. template = new Image();
  43. template.setAttribute('style', 'position: absolute; left: 0; top: 0; pointer-events: none; image-rendering: optimizeSpeed;');
  44. template.src = storage_url;
  45. document.body.appendChild(template);
  46. }
  47.  
  48. var tplbox = document.createElement('div');
  49. tplbox.setAttribute('class', 'tplbox');
  50. tplbox.setAttribute('style', 'position: absolute; right: 0.9em; bottom: 0.9em; border: 1px solid #666; background: rgba(0,0,0,0.3); border-radius: 2px; padding: 5px; font-size: 0.9em;');
  51. tplbox.innerHTML = '<div class="tplbox__title" style="text-align:right;"><b class="tplbox__titletext" style="cursor:pointer;">Hide</b></div><div class="tplbox__body" style="border-top: 1px solid #666; padding-top: 5px; margin-top:5px;"><div style="margin-bottom:5px;">Template url: <input type="text" class="tplbox__url" style="background: rgba(255,255,255,0.5); width: 180px;"></div><div style="margin-bottom:5px;">Transparency: <input type="range" class="tplbox__transparency" min="0" max="100" style="width: 160px;"></div><div style="margin-bottom:5px;">Visibility: <input type="checkbox" class="tplbox__visibility"></div></div>';
  52. document.body.appendChild(tplbox);
  53.  
  54. tplbox__body = document.querySelector('.tplbox__body');
  55. tplbox__titletext = document.querySelector('.tplbox__titletext');
  56. tplbox__url = document.querySelector('.tplbox__url');
  57. tplbox__transparency = document.querySelector('.tplbox__transparency');
  58. tplbox__visibility = document.querySelector('.tplbox__visibility');
  59. gameWindow = document.getElementById('gameWindow');
  60.  
  61. if(storage_hidden == 1) {
  62. tplbox__body.style.display = 'none';
  63. tplbox__titletext.innerHTML = 'Show';
  64. }
  65.  
  66. tplbox__url.value = storage_url;
  67. tplbox__transparency.value = storage_transparency * 100;
  68. tplbox__visibility.checked = (storage_showtemplate==1);
  69.  
  70. tplbox__titletext.addEventListener('click', TplboxToggle);
  71. tplbox__url.addEventListener('change', UrlChange);
  72. tplbox__transparency.addEventListener('change', TransparencyChange);
  73. tplbox__visibility.addEventListener('change', TransparencyChange);
  74.  
  75. gameWindow.addEventListener('mouseup', Sized);
  76. gameWindow.addEventListener('wheel', Sized);
  77. window.addEventListener('hashchange', Sized);
  78. Sized();
  79.  
  80.  
  81. }, false);
  82.  
  83.  
  84. var ShowImage = function() {
  85. if(storage_url == '') return;
  86.  
  87. template.style.opacity = (storage_showtemplate==1) ? storage_transparency : 0;
  88. template.style.transform = 'scale('+zoom+')';
  89.  
  90. var offsetX = window.innerWidth / 2;
  91. var offsetY = window.innerHeight / 2;
  92.  
  93. /*
  94. Не ебу что тут делать
  95. */
  96.  
  97. template.style.left = offsetX + 'px';
  98. template.style.top = offsetY + 'px';
  99.  
  100.  
  101. }
  102.  
  103.  
  104. var TplboxToggle = function() {
  105. if(tplbox__body.style.display == 'none') {
  106. tplbox__body.style.display = '';
  107. tplbox__titletext.innerHTML = 'Hide';
  108. localStorage.setItem('tplbox.hidden', 0);
  109. } else {
  110. tplbox__body.style.display = 'none';
  111. tplbox__titletext.innerHTML = 'Show';
  112. localStorage.setItem('tplbox.hidden', 1);
  113. }
  114. };
  115.  
  116. var UrlChange = function(e) {
  117. storage_url = e.target.value;
  118. localStorage.setItem('tplbox.url', storage_url);
  119. ShowImage();
  120. };
  121.  
  122. var TransparencyChange = function() {
  123. storage_transparency = tplbox__transparency.value / 100;
  124. storage_showtemplate = tplbox__visibility.checked ? 1 : 0;
  125. localStorage.setItem('tplbox.transparency', storage_transparency);
  126. localStorage.setItem('tplbox.showtemplate', storage_showtemplate);
  127. template.style.opacity = storage_showtemplate ? storage_transparency : 0;
  128. };
  129.  
  130. function Sized() {
  131. let hashstr = window.location.hash.substr(1).split(',');
  132. x = parseInt(hashstr[0]);
  133. y = parseInt(hashstr[1]);
  134. zoom = Math.pow(2, hashstr[2] / 10);
  135. ShowImage();
  136. }
Advertisement
Add Comment
Please, Sign In to add comment