Rox-Turbo commited on
Commit
1df45eb
·
verified ·
1 Parent(s): dc0cfbe

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +35 -26
script.js CHANGED
@@ -824,7 +824,7 @@ const UIController = (() => {
824
  await AnimationController.showSection('success-section', 300);
825
  };
826
 
827
- // Handle No button click (mobile)
828
  const handleNoClick = (e) => {
829
  e.preventDefault();
830
  e.stopPropagation();
@@ -832,21 +832,10 @@ const UIController = (() => {
832
  noClickCount++;
833
  noButtonActivated = true;
834
 
835
- // Grow the Yes button
836
- yesScale = 1 + (noClickCount * 0.2);
837
- const maxScale = 2.5;
838
-
839
- if (yesScale > maxScale) {
840
- yesScale = maxScale;
841
- }
842
-
843
- elements.btnYes.style.transform = `scale(${yesScale})`;
844
- elements.btnYes.style.zIndex = noClickCount + 10;
845
-
846
  // Make No button evade immediately
847
  evadeNoButton();
848
 
849
- // After many clicks, maybe just trigger yes
850
  if (noClickCount >= 15) {
851
  handleYesClick();
852
  }
@@ -913,34 +902,33 @@ const UIController = (() => {
913
  newY = minY + Math.random() * (maxY - minY);
914
  attempts++;
915
 
916
- // Ensure NO button never touches YES button
917
  if (elements.btnYes) {
918
  const yesRect = elements.btnYes.getBoundingClientRect();
919
 
920
- // Calculate the scaled Yes button dimensions
921
- const scaledYesWidth = yesRect.width;
922
- const scaledYesHeight = yesRect.height;
923
 
924
- // Check for rectangle overlap (with safety buffer)
925
- const safetyBuffer = 20; // Extra space to prevent touching
926
  const noLeft = newX;
927
  const noRight = newX + btnWidth;
928
  const noTop = newY;
929
  const noBottom = newY + btnHeight;
930
 
 
931
  const yesLeft = yesRect.left - safetyBuffer;
932
  const yesRight = yesRect.right + safetyBuffer;
933
  const yesTop = yesRect.top - safetyBuffer;
934
  const yesBottom = yesRect.bottom + safetyBuffer;
935
 
936
- // Check if rectangles overlap
937
- const isOverlapping = !(noRight < yesLeft ||
938
- noLeft > yesRight ||
939
- noBottom < yesTop ||
940
- noTop > yesBottom);
941
 
942
- // Only accept position if NOT overlapping
943
- if (!isOverlapping) {
944
  break;
945
  }
946
  } else {
@@ -948,6 +936,27 @@ const UIController = (() => {
948
  }
949
  } while (attempts < maxAttempts);
950
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
951
  // Strictly clamp position within container bounds
952
  const finalX = Math.max(minX, Math.min(maxX, newX));
953
  const finalY = Math.max(minY, Math.min(maxY, newY));
 
824
  await AnimationController.showSection('success-section', 300);
825
  };
826
 
827
+ // Handle No button click
828
  const handleNoClick = (e) => {
829
  e.preventDefault();
830
  e.stopPropagation();
 
832
  noClickCount++;
833
  noButtonActivated = true;
834
 
 
 
 
 
 
 
 
 
 
 
 
835
  // Make No button evade immediately
836
  evadeNoButton();
837
 
838
+ // After many clicks, trigger yes automatically
839
  if (noClickCount >= 15) {
840
  handleYesClick();
841
  }
 
902
  newY = minY + Math.random() * (maxY - minY);
903
  attempts++;
904
 
905
+ // Ensure NO button NEVER touches or overlaps YES button
906
  if (elements.btnYes) {
907
  const yesRect = elements.btnYes.getBoundingClientRect();
908
 
909
+ // Large safety buffer to guarantee no touching (50px minimum gap)
910
+ const safetyBuffer = 50;
 
911
 
912
+ // No button bounds
 
913
  const noLeft = newX;
914
  const noRight = newX + btnWidth;
915
  const noTop = newY;
916
  const noBottom = newY + btnHeight;
917
 
918
+ // Yes button expanded bounds (with safety buffer)
919
  const yesLeft = yesRect.left - safetyBuffer;
920
  const yesRight = yesRect.right + safetyBuffer;
921
  const yesTop = yesRect.top - safetyBuffer;
922
  const yesBottom = yesRect.bottom + safetyBuffer;
923
 
924
+ // Check if NO button would be inside the YES button's exclusion zone
925
+ const isInExclusionZone = (noRight > yesLeft &&
926
+ noLeft < yesRight &&
927
+ noBottom > yesTop &&
928
+ noTop < yesBottom);
929
 
930
+ // Only accept position if OUTSIDE the exclusion zone
931
+ if (!isInExclusionZone) {
932
  break;
933
  }
934
  } else {
 
936
  }
937
  } while (attempts < maxAttempts);
938
 
939
+ // If we couldn't find a valid position after all attempts,
940
+ // force position to bottom-right corner away from Yes button
941
+ if (attempts >= maxAttempts && elements.btnYes) {
942
+ const yesRect = elements.btnYes.getBoundingClientRect();
943
+ // Position in opposite corner from Yes button
944
+ if (yesRect.left < containerRect.left + containerRect.width / 2) {
945
+ // Yes is on left, put No on right
946
+ newX = maxX;
947
+ } else {
948
+ // Yes is on right, put No on left
949
+ newX = minX;
950
+ }
951
+ if (yesRect.top < containerRect.top + containerRect.height / 2) {
952
+ // Yes is on top, put No on bottom
953
+ newY = maxY;
954
+ } else {
955
+ // Yes is on bottom, put No on top
956
+ newY = minY;
957
+ }
958
+ }
959
+
960
  // Strictly clamp position within container bounds
961
  const finalX = Math.max(minX, Math.min(maxX, newX));
962
  const finalY = Math.max(minY, Math.min(maxY, newY));