Greasy Fork is available in English.

bilibili评论区图片快捷切换

按esc或者backspace,或者鼠标点击空白处,快捷关闭b站评论区图片。按左右键或<>键切换图片,或滑动鼠标滚轮切换图片,按住alt停止滚轮切换。该脚本使用chatgpt完成。

// ==UserScript==
// @name         bilibili评论区图片快捷切换
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  按esc或者backspace,或者鼠标点击空白处,快捷关闭b站评论区图片。按左右键或<>键切换图片,或滑动鼠标滚轮切换图片,按住alt停止滚轮切换。该脚本使用chatgpt完成。
// @author       coccvo
// @match        https://www.bilibili.com/video/*
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAAG1BMVEUAoNb////5/f7q+PzI6/ek3vGA0Os7t+AXqtoAacFbAAAAi0lEQVR42o2R3QqDIQxDE/uX93/isVVB3GTfuYo9IDQFSZobF+sBkiNVzomXckxhBSzj72xT0NWm5wq28MgCUJk5QziJEYUvKgZC+IECBVQeFFAQ5DxwQQBkPDABU3iuPdJ3YdVbddiF+sMOT8TIbq7DJjjsM++wiYM/4rL5tatru9d79AUPwknwwgt7fAWIfqzpTgAAAABJRU5ErkJggg==
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
  document.body.addEventListener('keydown', function(event) {
    // 检查按下的键是否为backspace或esc
    if (event.key === 'Backspace' || event.key === 'Escape' || event.key === '~') {
      // 查找评论区图片关闭按钮并模拟点击
      const closeButton = document.querySelector('.svg-icon.close.use-color');
      if (closeButton) {
        closeButton.click();
      }
    }
    if (event.key === 'ArrowRight' || event.key === '.') {
      // 模拟点击右箭头
      const rightArrow = document.querySelector('.operation-btn-icon.next-image');
      if (rightArrow) {
        rightArrow.click();
      }
    }
    if (event.key === 'ArrowLeft' || event.key === ',') {
      // 模拟点击左箭头
      const leftArrow = document.querySelector('.operation-btn-icon.last-image');
      if (leftArrow) {
        leftArrow.click();
      }
    }
  });
  document.body.addEventListener('wheel', function(event) {
  // 检查滚轮滚动方向
   if (event.deltaY > 0 && !event.altKey) {
    // 模拟点击右箭头
    const rightArrow = document.querySelector('.operation-btn-icon.next-image');
    if (rightArrow) {
      rightArrow.click();
    }
  } else if (event.deltaY < 0 && !event.altKey) {
    // 模拟点击左箭头
    const leftArrow = document.querySelector('.operation-btn-icon.last-image');
    if (leftArrow) {
      leftArrow.click();
    }
  }
});
document.body.addEventListener('click', function(event) {
  //点击空白处关闭图片
  if (event.target.closest('.show-image-wrap') &&
      document.querySelector('.operation-btn-icon.close-container') &&
      !event.target.closest('.operation-btn-icon.close-container') &&
      !event.target.closest('.show-image-wrap img')) { // 添加条件
    const closeButton = document.querySelector('.operation-btn-icon.close-container');
    if (closeButton) {
      closeButton.click();
    }
  } else if (!event.target.closest('.show-image-wrap')) {
    // 如果在非看图界面点击,则不执行任何操作
  }
});
})();