Magic for SED

auto food ordering

  1. // ==UserScript==
  2. // @name Magic for SED
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-09-04
  5. // @description auto food ordering
  6. // @author You
  7. // @match https://www.whyq.sg/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=whyq.sg
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create the button element
  16. const button = document.createElement('button');
  17. button.innerText = 'Random';
  18. button.id = 'floatingButton';
  19.  
  20. // Style the button
  21. const style = document.createElement('style');
  22. style.innerHTML = `
  23. #floatingButton {
  24. position: fixed;
  25. top: 10px;
  26. right: 10px;
  27. z-index: 1000;
  28. padding: 10px 20px;
  29. background-color: #007BFF;
  30. color: white;
  31. border: none;
  32. border-radius: 5px;
  33. cursor: pointer;
  34. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  35. }
  36. #floatingButton:hover {
  37. background-color: #0056b3;
  38. }
  39. `;
  40.  
  41. // Append the button and style to the document
  42. document.head.appendChild(style);
  43. document.body.appendChild(button);
  44.  
  45. function getTwoRandomNumbers(upper) {
  46. const random = () => Math.floor(upper * Math.random());
  47. const first = random();
  48. while (true) {
  49. const second = random();
  50. if (first !== second) {
  51. return [first, second];
  52. }
  53. }
  54. }
  55.  
  56. function sleep(ms) {
  57. return new Promise(resolve => setTimeout(resolve, ms));
  58. }
  59.  
  60.  
  61. // Add click event listener to the button
  62. button.addEventListener('click', async () => {
  63. const tabs = [...document.querySelector('.owl-stage-outer').querySelectorAll('.owl-item')];
  64. for (let t = 0; t < tabs.length; t ++) {
  65. tabs[t].querySelector('.meal_date_change').click();
  66.  
  67. const meals = [...document.querySelector('.rakuten_meal_list.active').querySelectorAll('ul')]
  68. .filter(x => !(x.className.includes('cat-481') || x.className.includes('cat-2')));
  69. const [first, second] = getTwoRandomNumbers(meals.length);
  70.  
  71. meals[first].querySelector('button').click();
  72.  
  73. while (true) {
  74. await sleep(500);
  75. const choose_optional = document.querySelector('#choose_optional');
  76. if (choose_optional.style.display === 'block') {
  77. const button = document.querySelector('#add_optional');
  78. button.click();
  79. break;
  80. }
  81. }
  82.  
  83. meals[second].querySelector('button').click();
  84.  
  85. while (true) {
  86. await sleep(500);
  87. const popup = document.querySelector('#pop_notify');
  88. if (popup.style.display === 'block') {
  89. popup.querySelector('button').click();
  90. break;
  91. }
  92. }
  93.  
  94. while (true) {
  95. await sleep(500);
  96. const popup = document.querySelector('#pop_notify');
  97. if (popup.style.display === 'none') {
  98. break;
  99. }
  100. }
  101. }
  102. });
  103. })();