Hover Image Overlay for Designcontest.com

Bringing back the hover on entries to overlay the whole image

目前為 2024-10-17 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hover Image Overlay for Designcontest.com
// @namespace    https://greasyfork.org/en/users/781396-yad
// @version      1.12
// @description  Bringing back the hover on entries to overlay the whole image
// @author       YAD
// @match        https://*.designcontest.com/*/entries/*
// @icon         https://designcontest.nyc3.digitaloceanspaces.com/images/favicon.png
// @license      MIT
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    GM_addStyle(`
        #image-overlay {
            position: fixed;
            display: none;
            border: 2px solid black;
            z-index: 1000;
            width: 420px;
            height: 420px;
            background-color: white;
            overflow: hidden;
            display: flex;
            justify-content: center;
            align-items: center;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        #image-overlay img {
            max-width: 100%;
            max-height: 100%;
        }
    `);

    const overlay = document.createElement('div');
    overlay.id = 'image-overlay';
    const overlayImage = document.createElement('img');
    overlay.appendChild(overlayImage);
    document.body.appendChild(overlay);

    // Function to adjust overlay position based on mouse position
    function adjustOverlayPosition(event) {
        const margin = 20;
        const overlayWidth = 400;
        const overlayHeight = 400;
        let left = event.clientX + margin;
        let top = event.clientY + margin;

        // Adjust position based on mouse position and viewport
        if (left + overlayWidth > window.innerWidth) {
            left = event.clientX - overlayWidth - margin;
        }
        if (top + overlayHeight > window.innerHeight) {
            top = event.clientY - overlayHeight - margin;
        }

        overlay.style.left = `${left}px`;
        overlay.style.top = `${top}px`;
    }

    // Event listener for mouseover on images
    document.addEventListener('mouseover', event => {
        const img = event.target;
        if (img.tagName === 'IMG' && img.src.includes('big_')) {
            overlayImage.src = img.src.replace('big_', '');
            overlay.style.display = 'flex';
            adjustOverlayPosition(event);
        }
    });

    // Event listener for mousemove to adjust overlay position
    document.addEventListener('mousemove', event => {
        if (overlay.style.display === 'flex') {
            adjustOverlayPosition(event);
        }
    });

    // Event listener for mouseout from images or overlay
    document.addEventListener('mouseout', event => {
        const img = event.target;
        if (img.tagName === 'IMG' && img.src.includes('big_')) {
            overlay.style.display = 'none';
        }
    });

    // Event listener for mouseleave from overlay
    overlay.addEventListener('mouseleave', () => {
        overlay.style.display = 'none';
    });
})();