Guest User

Untitled

a guest
Aug 28th, 2025
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Dragging in pantheon Cookie Clicker [mobile]
  3. // @namespace http://tampermonkey.net/
  4. // @version 2025-07-25
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://orteil.dashnet.org/cookieclicker/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=dashnet.org
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const longPressDuration = 500;
  16. const moveThreshold = 10;
  17. let timerId = null;
  18. let startX = 0;
  19. let startY = 0;
  20. let isHolding = false;
  21.  
  22. function dispatchMouseEvent(target, type, clientX, clientY) {
  23. target.dispatchEvent(new MouseEvent(type, {
  24. bubbles: true,
  25. cancelable: true,
  26. view: window,
  27. clientX,
  28. clientY
  29. }));
  30. }
  31.  
  32. function handleStart(e) {
  33. const target = e.target;
  34.  
  35. if (!(target.id && target.id.startsWith('templeGodDrag'))) return;
  36.  
  37. if (isHolding) return;
  38.  
  39. if (e.type.startsWith('touch')) {
  40. startX = e.touches[0].clientX;
  41. startY = e.touches[0].clientY;
  42. } else {
  43. startX = e.clientX;
  44. startY = e.clientY;
  45. }
  46.  
  47. isHolding = true;
  48.  
  49. timerId = setTimeout(() => {
  50. dispatchMouseEvent(target, 'mousedown', startX, startY);
  51. }, longPressDuration);
  52. }
  53.  
  54. function handleMove(e) {
  55. if (!isHolding || !timerId) return;
  56.  
  57. let currentX, currentY;
  58. if (e.type.startsWith('touch')) {
  59. currentX = e.touches[0].clientX;
  60. currentY = e.touches[0].clientY;
  61. } else {
  62. currentX = e.clientX;
  63. currentY = e.clientY;
  64. }
  65.  
  66. if (Math.abs(currentX - startX) > moveThreshold || Math.abs(currentY - startY) > moveThreshold) {
  67. clearTimeout(timerId);
  68. timerId = null;
  69. isHolding = false;
  70. }
  71. }
  72.  
  73. function handleEnd(e) {
  74. if (timerId) {
  75. clearTimeout(timerId);
  76. timerId = null;
  77. }
  78. isHolding = false;
  79. }
  80.  
  81. document.addEventListener('mousedown', handleStart);
  82. document.addEventListener('touchstart', handleStart);
  83. document.addEventListener('touchmove', handleMove);
  84. document.addEventListener('mousemove', handleMove);
  85. document.addEventListener('mouseup', handleEnd);
  86. document.addEventListener('touchend', handleEnd);
  87. })();
Advertisement
Add Comment
Please, Sign In to add comment