Last active
June 7, 2021 12:30
-
-
Save kototoibashi/62d2929de0dfd4126e45e93d38822d64 to your computer and use it in GitHub Desktop.
Pixivの検索画面でサムネイルにカーソル乗せたときに拡大画像を表示するUserScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name PIXIV hover | |
// @version 1 | |
// @include https://www.pixiv.net/* | |
// @grant none | |
// ==/UserScript== | |
let current_url = "" | |
let applied = {} | |
const thumbnail_style = "max-height: 30vh;max-width: 20vw;z-index: 9999999;" | |
const init = () => { | |
if(current_url != window.location.href){applied = {}} | |
const img_elems = Array.from(document.querySelectorAll("img")).filter(x => /i\.pximg\.net.*c\/\d+x\d+[^\/]+\/.*[img-master|custom-thumb]/.test(x.src)) | |
current_url = window.location.href | |
img_elems.forEach(x => { | |
if(applied[x.src]){return} | |
const img_url = x.src.replace(/c\/\d+x\d+[^\/]+\//,"").replace("custom-thumb","img-master").replace("square","master").replace("custom","master") | |
console.log(img_url) | |
const elem = document.createElement("img") | |
applied[x.src] = true | |
x.addEventListener("mouseenter", | |
function (event) { | |
elem.src = img_url | |
const left = event.pageX | |
const top = event.pageY | |
elem.setAttribute("style", `position: absolute;top: ${top+10}px;left: ${left+10}px;${thumbnail_style}`); | |
if(elem.parentNode) {return} | |
document.body.appendChild(elem) | |
// 少し待ってからリセット | |
setTimeout(() => {elem.remove()}, 5000); | |
} | |
) | |
x.addEventListener("mouseout", | |
function (event) { | |
setTimeout(() => {elem.remove()}, 100); | |
} | |
) | |
}) | |
} | |
setTimeout( () => setInterval(init, 1000), 700) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment