civitai.com fast react

2/12/2024, 2:44:50 AM

ของเมื่อวันที่ 13-02-2024 ดู เวอร์ชันล่าสุด

// ==UserScript==
// @name        civitai.com fast react
// @namespace   Violentmonkey Scripts
// @match       https://civitai.com/posts/*
// @match       https://civitai.com/search/images
// @grant       none
// @version     1.0
// @author      tryitandsee
// @license     MIT
// @description 2/12/2024, 2:44:50 AM
// ==/UserScript==


// Should I use elementFromPoint or keep track of IMG tags as the mouseenter/mouseexit them?
// mousemove seems inefficient but it works and works with infinite scroll
let mouseX, mouseY;
document.addEventListener('mousemove', function(event) {
  mouseX = event.clientX;
  mouseY = event.clientY;
});


document.addEventListener('keydown', function(event) {
  if (!['1', '2', '3', '4'].includes(event.key)) {
    console.log('ZZ wrong keydown', event.key);
    return;
  }

  const $img = document.elementFromPoint(mouseX, mouseY);

  // Check if the found element is an <img> tag
  if ($img.tagName.toLowerCase() === 'img') {
    console.log('ZZ Found <img> tag:', $img);
  } else {
    console.log('ZZ No <img> tag found under the cursor.', $img);
    return;
  }

  const $control = $img.nextElementSibling;
  if ($control.childNodes.length != 6) {
    $control.childNodes[0].click();
    return;
  }

  const numberPressed = parseInt(event.key, 10);
  $control.childNodes[numberPressed].click();
});