Guest User

Untitled

a guest
Aug 28th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Two fingers dragging on #ascendBG
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Imitates mousedown–mousemove–mouseup with two fingers on #ascendBG
  6. // @match https://orteil.dashnet.org/cookieclicker/
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=dashnet.org
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function(){
  12. 'use strict';
  13.  
  14. const target = document.getElementById('ascendBG');
  15. if (!target) {
  16. console.warn('ascendBG not found');
  17. return;
  18. }
  19.  
  20. let isDragging = false;
  21. let prevMidX = 0;
  22. let prevMidY = 0;
  23.  
  24. function getMidPoint(t0, t1) {
  25. return {
  26. x: (t0.clientX + t1.clientX) / 2,
  27. y: (t0.clientY + t1.clientY) / 2
  28. };
  29. }
  30.  
  31. function isInside(touch) {
  32. const r = target.getBoundingClientRect();
  33. return touch.clientX >= r.left &&
  34. touch.clientX <= r.right &&
  35. touch.clientY >= r.top &&
  36. touch.clientY <= r.bottom;
  37. }
  38.  
  39. document.addEventListener('touchstart', function(e){
  40. if (e.touches.length === 2 && isInside(e.touches[0]) && isInside(e.touches[1])) {
  41. const mid = getMidPoint(e.touches[0], e.touches[1]);
  42. prevMidX = mid.x;
  43. prevMidY = mid.y;
  44. isDragging = true;
  45.  
  46. // mousedown
  47. const md = new MouseEvent('mousedown', {
  48. clientX: mid.x,
  49. clientY: mid.y,
  50. buttons: 1,
  51. bubbles: true,
  52. cancelable: true
  53. });
  54. target.dispatchEvent(md);
  55.  
  56. e.preventDefault();
  57. }
  58. }, {passive: false});
  59.  
  60.  
  61. document.addEventListener('touchmove', function(e){
  62. if (!isDragging) return;
  63. if (e.touches.length < 2) {
  64. return;
  65. }
  66. const mid = getMidPoint(e.touches[0], e.touches[1]);
  67.  
  68. const mm = new MouseEvent('mousemove', {
  69. clientX: mid.x,
  70. clientY: mid.y,
  71. buttons: 1,
  72. bubbles: true,
  73. cancelable: true
  74. });
  75. target.dispatchEvent(mm);
  76.  
  77. prevMidX = mid.x;
  78. prevMidY = mid.y;
  79. e.preventDefault();
  80. }, {passive: false});
  81.  
  82.  
  83. document.addEventListener('touchend', function(e){
  84. if (!isDragging) return;
  85. if (e.touches.length < 2) {
  86. const mu = new MouseEvent('mouseup', {
  87. clientX: prevMidX,
  88. clientY: prevMidY,
  89. buttons: 1,
  90. bubbles: true,
  91. cancelable: true
  92. });
  93. target.dispatchEvent(mu);
  94. isDragging = false;
  95. }
  96. }, {passive: false});
  97.  
  98. })();
Advertisement
Add Comment
Please, Sign In to add comment