gurochan - image hover

Image hover for gurochan

目前為 2024-04-24 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        gurochan - image hover
// @match       https://boards.guro.cx/*
// @grant       none
// @version     1.0
// @author      -
// @grant       GM_addStyle
// @description Image hover for gurochan
// @namespace https://greasyfork.org/users/1292388
// ==/UserScript==

let img = document.createElement('img')
img.id = 'hoverImage'

document['body'].append(img)

document.addEventListener('mouseover', function(event) {
  if (event.target.classList.contains('post-image')) {
    document.getElementById('hoverImage').classList.add('active');
    img.src = event.target.parentNode.href
  }
});

document.addEventListener('mouseout', function(event) {
  if (event.target.classList.contains('post-image')) {
    document.getElementById('hoverImage').classList.remove('active');
    img.src = ''
  }
});


document.addEventListener('mousemove', (e) => {
  const targetX = e.clientX+20
  const targetY = e.clientY/2
  const scrollbarWidth = 18

  if (targetX + img.offsetWidth > (window.innerWidth - scrollbarWidth)) {
    img.style.left = (window.innerWidth - img.offsetWidth - scrollbarWidth) + 'px';
  }
  else {
    img.style.left = targetX + 'px';
  }

  if (targetY + img.offsetHeight > window.innerHeight) {
    img.style.top = (window.innerHeight - img.offsetHeight) + 'px';
  }
  else {
    img.style.top = targetY + 'px';
  }
});

GM_addStyle(`

  #hoverImage {
    position: fixed;
    pointer-events: none;
    max-width: 100vw;
    max-height: 100vh;
    z-index: 1000;
  }

  #hoverImage:not(.active) {
    display: none;
  }

`)