Greasy Fork is available in English.

叔叔不约自动离开

0.5离开

// ==UserScript==
// @name         叔叔不约自动离开
// @namespace    自动离开
// @version      1.3
// @description  0.5离开
// @match        *://www.shushubuyue.net/*
// @license MIT
// ==/UserScript==


(function() {
  'use strict';






// 创建 MutationObserver 实例
var observer = new MutationObserver(function(mutationsList) {
  for (var mutation of mutationsList) {
    if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
      // 在变化发生时检查目标元素并进行点击
      checkAndClickElements();
    }
  }
});

// 配置 MutationObserver
var observerConfig = {
  childList: true,
  subtree: true
};

// 启动 MutationObserver 监视
observer.observe(document.body, observerConfig);

// 检查目标元素并进行点击
var isClickInProgress = false; // 标记点击是否正在进行中

function checkAndClickElements() {
  // 如果点击正在进行中,则直接返回
  if (isClickInProgress) {
    return;
  }

  // 设置点击进行中的标记
  isClickInProgress = true;

  var leaveElement = getElementByText('span.chat-control[href="#"]', '离开');
  if (leaveElement) {
    // 等待2000毫秒后点击 "离开" 元素
    setTimeout(function() {
      leaveElement.click();
      console.log('已点击 "离开" 元素');

      // 等待500毫秒后点击 "重新开始" 元素
      setTimeout(function() {
        var restartElement = getElementByText('span.chat-control[href="#"]', '重新开始');
        if (restartElement) {
          restartElement.click();
          console.log('已点击 "重新开始" 元素');
        }

        // 重置点击标记
        isClickInProgress = false;
      }, 500); // 延迟时间,单位:毫秒

    }, 1000); // 延迟时间,单位:毫秒
  } else {
    // 重置点击标记
    isClickInProgress = false;
  }
}

// 根据元素的文本内容选择元素
function getElementByText(selector, text) {
  var elements = document.querySelectorAll(selector);
  for (var i = 0; i < elements.length; i++) {
    if (elements[i].innerText.includes(text)) {
      return elements[i];
    }
  }
  return null;
}




})();