Uhmegle AutoSkip with Persistent Country List and Disconnect Detection (Randomized Intervals)

Auto-skip chats based on country (persisted) and if "You have disconnected" appears, simulate an ESC key press after a randomized delay.

  1. // ==UserScript==
  2. // @name Uhmegle AutoSkip with Persistent Country List and Disconnect Detection (Randomized Intervals)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.1
  5. // @description Auto-skip chats based on country (persisted) and if "You have disconnected" appears, simulate an ESC key press after a randomized delay.
  6. // @match *://uhmegle.com/*
  7. // @grant none
  8. // @license GNU GPLv3
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // -------------------------------
  15. // Persistent Country List Settings
  16. // -------------------------------
  17.  
  18. const storageKey = 'uhmegleAutoSkipCountries';
  19.  
  20. // Retrieve stored auto-skip country settings or initialize as empty.
  21. let autoSkipCountries = JSON.parse(localStorage.getItem(storageKey)) || {};
  22.  
  23. // Save changes to localStorage.
  24. function saveAutoSkipCountries() {
  25. localStorage.setItem(storageKey, JSON.stringify(autoSkipCountries));
  26. }
  27.  
  28. // Create and style a panel for the country list.
  29. const panel = document.createElement('div');
  30. panel.style.position = 'fixed';
  31. panel.style.top = '10px';
  32. panel.style.right = '10px';
  33. panel.style.backgroundColor = 'white';
  34. panel.style.border = '1px solid #ccc';
  35. panel.style.padding = '10px';
  36. panel.style.zIndex = 10000;
  37. panel.style.maxHeight = '300px';
  38. panel.style.overflowY = 'auto';
  39. panel.innerHTML = '<h4>AutoSkip Countries</h4><div id="countryList"></div>';
  40. document.body.appendChild(panel);
  41.  
  42. // Update the panel with the list of countries and their auto-skip checkbox.
  43. function updateCountryListUI() {
  44. const listDiv = document.getElementById('countryList');
  45. listDiv.innerHTML = '';
  46. for (const country in autoSkipCountries) {
  47. const label = document.createElement('label');
  48. label.style.display = 'block';
  49. label.style.marginBottom = '5px';
  50. const checkbox = document.createElement('input');
  51. checkbox.type = 'checkbox';
  52. checkbox.checked = autoSkipCountries[country];
  53. checkbox.addEventListener('change', function() {
  54. autoSkipCountries[country] = this.checked;
  55. saveAutoSkipCountries();
  56. });
  57. label.appendChild(checkbox);
  58. label.appendChild(document.createTextNode(' ' + country));
  59. listDiv.appendChild(label);
  60. }
  61. }
  62.  
  63. updateCountryListUI();
  64.  
  65. // -------------------------------
  66. // ESC Key Simulation Functions
  67. // -------------------------------
  68.  
  69. // Function to simulate one ESC key press.
  70. function simulateEsc() {
  71. const escEvent = new KeyboardEvent('keydown', {
  72. key: 'Escape',
  73. code: 'Escape',
  74. keyCode: 27,
  75. which: 27,
  76. bubbles: true,
  77. cancelable: true
  78. });
  79. document.dispatchEvent(escEvent);
  80. }
  81.  
  82. // Function to simulate two ESC key presses.
  83. function simulateSkip() {
  84. console.log('Simulating ESC key presses for auto-skip...');
  85. simulateEsc();
  86. // Random delay between 400ms and 600ms.
  87. const randomDelay = 400 + Math.random() * 200;
  88. setTimeout(simulateEsc, randomDelay);
  89. }
  90.  
  91. // -------------------------------
  92. // Monitor for Country Changes
  93. // -------------------------------
  94.  
  95. let lastCountry = '';
  96.  
  97. function checkCountry() {
  98. const countryElem = document.getElementById('countryName');
  99. if (countryElem) {
  100. const currentCountry = countryElem.textContent.trim();
  101. if (currentCountry && currentCountry !== lastCountry) {
  102. lastCountry = currentCountry;
  103. // Add new country if not already present.
  104. if (!(currentCountry in autoSkipCountries)) {
  105. autoSkipCountries[currentCountry] = false; // default auto-skip off
  106. saveAutoSkipCountries();
  107. updateCountryListUI();
  108. }
  109. // If auto-skip is enabled for this country, simulate the skip.
  110. if (autoSkipCountries[currentCountry]) {
  111. simulateSkip();
  112. }
  113. }
  114. }
  115. }
  116.  
  117. // Use a recursive function to randomize interval between country checks.
  118. function scheduleCountryCheck() {
  119. checkCountry();
  120. const nextDelay = 800 + Math.random() * 400; // 800ms to 1200ms
  121. setTimeout(scheduleCountryCheck, nextDelay);
  122. }
  123. scheduleCountryCheck();
  124.  
  125. // Also observe DOM changes in case the country element is loaded dynamically.
  126. const countryObserver = new MutationObserver(checkCountry);
  127. countryObserver.observe(document.body, { childList: true, subtree: true });
  128.  
  129. // -------------------------------
  130. // Monitor for "You have disconnected" Text
  131. // -------------------------------
  132.  
  133. let disconnectTriggered = false;
  134. function checkForDisconnect() {
  135. // Check if the phrase "You have disconnected" appears anywhere in the visible text.
  136. const pageText = document.body.innerText || "";
  137. const found = pageText.includes("You have disconnected");
  138. if (found && !disconnectTriggered) {
  139. disconnectTriggered = true;
  140. console.log('"You have disconnected" detected. Simulating ESC key press after a random delay...');
  141. // Random delay between 400ms and 600ms before simulating an ESC key press.
  142. const randomDelay = 400 + Math.random() * 200;
  143. setTimeout(simulateEsc, randomDelay);
  144. } else if (!found && disconnectTriggered) {
  145. disconnectTriggered = false;
  146. }
  147. }
  148.  
  149. // Recursive check for disconnect with random interval.
  150. function scheduleDisconnectCheck() {
  151. checkForDisconnect();
  152. const nextDelay = 800 + Math.random() * 400;
  153. setTimeout(scheduleDisconnectCheck, nextDelay);
  154. }
  155. scheduleDisconnectCheck();
  156.  
  157. // -------------------------------
  158. // End of Script
  159. // -------------------------------
  160. })();