Tools+

Add a draggable handle to #tools on PixelPlace

  1. // ==UserScript==
  2. // @name Tools+
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024/11/17
  5. // @description Add a draggable handle to #tools on PixelPlace
  6. // @author Realwdpcker on Pixelplace
  7. // @match pixelplace.io/*
  8. // @icon https://i.imgur.com/2hE2enW.png
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. const makeDraggable = (element, handle) => {
  16. let offsetX = 0, offsetY = 0, isDragging = false;
  17.  
  18. const mouseDownHandler = (e) => {
  19. isDragging = true;
  20. offsetX = e.clientX - element.getBoundingClientRect().left;
  21. offsetY = e.clientY - element.getBoundingClientRect().top;
  22. document.addEventListener('mousemove', mouseMoveHandler);
  23. document.addEventListener('mouseup', mouseUpHandler);
  24. };
  25.  
  26. const mouseMoveHandler = (e) => {
  27. if (!isDragging) return;
  28. element.style.position = 'absolute';
  29. element.style.left = `${e.clientX - offsetX}px`;
  30. element.style.top = `${e.clientY - offsetY}px`;
  31. handle.style.cursor = 'grabbing';
  32. };
  33.  
  34. const mouseUpHandler = () => {
  35. isDragging = false;
  36. handle.style.cursor = 'grab';
  37. document.removeEventListener('mousemove', mouseMoveHandler);
  38. document.removeEventListener('mouseup', mouseUpHandler);
  39. };
  40.  
  41. handle.style.cursor = 'grab';
  42. handle.addEventListener('mousedown', mouseDownHandler);
  43. };
  44.  
  45. const waitForElement = (selector, callback) => {
  46. const interval = setInterval(() => {
  47. const element = document.querySelector(selector);
  48. if (element) {
  49. clearInterval(interval);
  50. callback(element);
  51. }
  52. }, 100);
  53. };
  54.  
  55. waitForElement('#tools', (tools) => {
  56. // Create the draggable handle
  57. const handle = document.createElement('div');
  58. handle.style.position = 'absolute';
  59. handle.style.top = '5px';
  60. handle.style.right = '-15px';
  61. handle.style.width = '20px';
  62. handle.style.height = '20px';
  63. handle.style.padding = '12px';
  64. handle.style.background = '#828282';
  65. handle.style.border = '2px solid #fff';
  66. handle.style.borderRadius = '15px';
  67. handle.style.cursor = 'grab';
  68. handle.style.display = 'flex';
  69. handle.style.alignItems = 'center';
  70. handle.style.justifyContent = 'center';
  71. handle.style.zIndex = '1000';
  72. handle.style.boxShadow = '0px 0px 5px 0px rgba(0, 0, 0, 0.75)'; // Box shadow added here
  73. handle.title = 'Drag Me!';
  74.  
  75. // Create the image
  76. const img = document.createElement('img');
  77. img.src = 'https://i.imgur.com/DDjMbDW.png'; // Replace with your image URL
  78. img.alt = 'Drag Icon';
  79. img.style.width = '18px'; // Adjust as needed
  80. img.style.height = '18px'; // Adjust as needed
  81. img.style.pointerEvents = 'none'; // Ensures the image doesn't block drag events
  82.  
  83. // Append the image to the handle
  84. handle.appendChild(img);
  85.  
  86. // Add handle to #tools
  87. tools.style.position = 'absolute';
  88. tools.appendChild(handle);
  89.  
  90. // Make draggable using the handle
  91. makeDraggable(tools, handle);
  92. });
  93. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址