🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2026/01/25 21:11:52
🔄 下次更新时间:2026/01/25 22:11:52
手动刷新缓存

GitHub Image Previewer

Previews various image formats, including JPG, PNG, GIF, BMP, TIFF, WebP, SVG, and ICO.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         GitHub Image Previewer
// @description  Previews various image formats, including JPG, PNG, GIF, BMP, TIFF, WebP, SVG, and ICO.
// @icon         https://github.githubassets.com/favicons/favicon-dark.svg
// @version      1.2
// @author       afkarxyz
// @namespace    https://github.com/afkarxyz/userscripts/
// @supportURL   https://github.com/afkarxyz/userscripts/issues
// @license      MIT
// @match        https://github.com/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    const GitHubImagePreviewer = {
        supportedImageFormats: /\.(jpe?g|png|gif|bmp|ico|tiff?|webp|svg)$/i,
        imagePreviewContainer: null,
        imagePreviewElement: null,
        imagePreviewTitle: null,
        imagePreviewMetadata: null,

        init() {
            this.createImagePreviewElements();
            this.attachImagePreviewListeners();
            this.disableGitHubTooltips();
        },

        createImagePreviewElements() {
            this.imagePreviewContainer = document.createElement('div');
            this.imagePreviewContainer.style.cssText = `
                position: fixed;
                z-index: 9999;
                background: white;
                border: 1px solid #d1d5da;
                border-radius: 3px;
                box-shadow: 0 1px 5px rgba(27,31,35,0.15);
                display: none;
                padding: 10px;
                max-width: 300px;
                max-height: 300px;
                color: #24292e;
            `;

            this.imagePreviewTitle = document.createElement('div');
            this.imagePreviewTitle.style.cssText = `
                font-weight: bold;
                margin-bottom: 5px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            `;

            this.imagePreviewElement = document.createElement('img');
            this.imagePreviewElement.style.cssText = `
                max-width: 100%;
                max-height: 200px;
                display: block;
                margin: 0 auto;
                background-image: linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
                      linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
                      linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
                      linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
                background-size: 20px 20px;
                background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
            `;

            this.imagePreviewMetadata = document.createElement('div');
            this.imagePreviewMetadata.style.cssText = `
                font-size: 12px;
                color: #586069;
                margin-top: 5px;
                text-align: center;
            `;

            this.imagePreviewContainer.appendChild(this.imagePreviewTitle);
            this.imagePreviewContainer.appendChild(this.imagePreviewElement);
            this.imagePreviewContainer.appendChild(this.imagePreviewMetadata);
            document.body.appendChild(this.imagePreviewContainer);
        },

        attachImagePreviewListeners() {
            document.addEventListener('mouseover', this.handleImageMouseOver.bind(this));
            document.addEventListener('mouseout', this.handleImageMouseOut.bind(this));
            document.addEventListener('mousemove', this.handleImageMouseMove.bind(this));
        },

        disableGitHubTooltips() {
            const style = document.createElement('style');
            style.textContent = `
                .tooltipped::before, .tooltipped::after {
                    display: none !important;
                }
            `;
            document.head.appendChild(style);
        },

        handleImageMouseOver(event) {
            const target = event.target.closest('a');
            if (target && this.supportedImageFormats.test(target.href)) {
                if (target.hasAttribute('title')) {
                    target.dataset.originalTitle = target.getAttribute('title');
                    target.removeAttribute('title');
                }
                this.showImagePreview(target);
            }
        },

        handleImageMouseOut() {
            this.hideImagePreview();
        },

        handleImageMouseMove(event) {
            if (this.imagePreviewContainer.style.display !== 'none') {
                const mouseX = event.clientX;
                const mouseY = event.clientY;
                const viewportWidth = window.innerWidth;
                const viewportHeight = window.innerHeight;
                const previewWidth = this.imagePreviewContainer.offsetWidth;
                const previewHeight = this.imagePreviewContainer.offsetHeight;
                
                let x = mouseX + 15;
                let y = mouseY + 15;
                
                if (x + previewWidth > viewportWidth) {
                    x = mouseX - previewWidth - 15;
                }
                
                if (y + previewHeight > viewportHeight) {
                    y = mouseY - previewHeight - 15;
                }
                
                this.imagePreviewContainer.style.left = `${x}px`;
                this.imagePreviewContainer.style.top = `${y}px`;
            }
        },

        showImagePreview(target) {
            const imageUrl = target.href.replace('/blob/', '/raw/');
            this.imagePreviewTitle.textContent = target.dataset.originalTitle || target.getAttribute('title') || target.textContent;
            this.imagePreviewElement.src = imageUrl;
            this.imagePreviewContainer.style.display = 'block';

            this.imagePreviewElement.onload = this.updateImageMetadata.bind(this);
        },

        hideImagePreview() {
            this.imagePreviewContainer.style.display = 'none';
        },

        updateImageMetadata() {
            const width = this.imagePreviewElement.naturalWidth;
            const height = this.imagePreviewElement.naturalHeight;
            this.imagePreviewMetadata.textContent = `${width} x ${height} px`;
        },
    };

    GitHubImagePreviewer.init();
})();