Advertisement
NewBestPastebins

Untitled

Jun 24th, 2024
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. var tspan = document.querySelector('tspan');
  2. var span = document.querySelector('.number');
  3. var factor = 1.003;
  4.  
  5. var dropdownButton = document.createElement('button');
  6. dropdownButton.textContent = 'Dropdown';
  7. dropdownButton.style.position = 'absolute';
  8. dropdownButton.style.top = '100px';
  9. dropdownButton.style.right = '100px';
  10.  
  11. var dropdownMenu = document.createElement('div');
  12. dropdownMenu.style.position = 'absolute';
  13. dropdownMenu.style.top = '120px';
  14. dropdownMenu.style.right = '100px';
  15. dropdownMenu.style.display = 'none';
  16. dropdownMenu.style.height = '400px';
  17. dropdownMenu.style.width = '400px';
  18. dropdownMenu.style.backgroundColor = 'white';
  19. dropdownMenu.style.border = '1px solid black';
  20.  
  21. var incrementButton = document.createElement('button');
  22. incrementButton.textContent = 'Increment';
  23. incrementButton.style.display = 'block';
  24. incrementButton.style.width = '100%';
  25. incrementButton.onclick = function() {
  26. var tspanValue = parseInt(tspan.textContent);
  27. tspan.textContent = tspanValue + 1;
  28. var num = parseInt(span.textContent) + Math.round(210 * factor);
  29. span.textContent = num;
  30. factor *= 1.003;
  31. };
  32.  
  33. var changeXPButton = document.createElement('button');
  34. changeXPButton.textContent = 'Change XP';
  35. changeXPButton.style.display = 'block';
  36. changeXPButton.style.width = '100%';
  37. changeXPButton.onclick = function() {
  38. var currentXP = parseInt(span.textContent);
  39. var xpInput = document.createElement('input');
  40. xpInput.type = 'text';
  41. xpInput.placeholder = 'Enter new XP';
  42. xpInput.style.display = 'block';
  43. xpInput.style.width = '100%';
  44. dropdownMenu.appendChild(xpInput);
  45.  
  46. xpInput.onkeydown = function(event) {
  47. if (event.key === 'Enter') {
  48. span.textContent = currentXP + parseInt(xpInput.value);
  49. dropdownMenu.removeChild(xpInput);
  50. }
  51. };
  52.  
  53. xpInput.onblur = function() {
  54. span.textContent = currentXP + parseInt(xpInput.value);
  55. dropdownMenu.removeChild(xpInput);
  56. };
  57. };
  58.  
  59. var changeLevelButton = document.createElement('button');
  60. changeLevelButton.textContent = 'Change Level';
  61. changeLevelButton.style.display = 'block';
  62. changeLevelButton.style.width = '100%';
  63. changeLevelButton.onclick = function() {
  64. var levelInput = document.createElement('input');
  65. levelInput.type = 'text';
  66. levelInput.placeholder = 'Enter new level';
  67. levelInput.style.display = 'block';
  68. levelInput.style.width = '100%';
  69. dropdownMenu.appendChild(levelInput);
  70.  
  71. levelInput.onkeydown = function(event) {
  72. if (event.key === 'Enter') {
  73. tspan.textContent = levelInput.value;
  74. dropdownMenu.removeChild(levelInput);
  75. }
  76. };
  77.  
  78. levelInput.onblur = function() {
  79. tspan.textContent = levelInput.value;
  80. dropdownMenu.removeChild(levelInput);
  81. };
  82. };
  83.  
  84. dropdownButton.onclick = function() {
  85. if (dropdownMenu.style.display === 'none') {
  86. dropdownMenu.style.display = 'block';
  87. } else {
  88. dropdownMenu.style.display = 'none';
  89. }
  90. };
  91.  
  92. document.body.appendChild(dropdownButton);
  93. document.body.appendChild(dropdownMenu);
  94. dropdownMenu.appendChild(incrementButton);
  95. dropdownMenu.appendChild(changeXPButton);
  96. dropdownMenu.appendChild(changeLevelButton);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement