View Individual: View image attachments in page

If an attachment on a profile is an image, add a viewer to it so you don't have to download it.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         View Individual: View image attachments in page
// @namespace    https://github.com/nate-kean/
// @version      2025.11.9
// @description  If an attachment on a profile is an image, add a viewer to it so you don't have to download it.
// @author       Nate Kean
// @match        https://jamesriver.fellowshiponego.com/members/view/*
// @match        https://jamesriver.fellowshiponego.com/members/edit/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fellowshiponego.com
// @grant        none
// @license      MIT
// @run-at       document-end
// @require      https://cdnjs.cloudflare.com/ajax/libs/viewerjs/1.11.7/viewer.min.js
// ==/UserScript==

(function() {
    const extensions = ["jpeg", "jpg", "png", "gif", "bmp", "webp"];
    const selector = `
        #memberDocumentsList a.fileDownloadLink,
        #memberEditDocumentsList a.fileDownloadLink
    `;

    document.head.insertAdjacentHTML("beforeend", `
        <link
            rel="stylesheet"
            href="https://cdnjs.cloudflare.com/ajax/libs/viewerjs/1.11.7/viewer.min.css"
            integrity="sha512-vRbASHFS0JiM4xwX/iqr9mrD/pXGnOP2CLdmXSSNAjLdgQVFyt4qI+BIoUW7/81uSuKRj0cWv3Dov8vVQOTHLw=="
            crossorigin="anonymous" referrerpolicy="no-referrer"
        />
    `);

    for (const a of document.querySelectorAll(selector)) {
        const ext = a.textContent.trim().split(".").at(-1);
        if (!extensions.includes(ext)) continue;

        const icon = a.querySelector("i");
        icon.classList.remove("glyphicon-cloud-download");
        icon.classList.add("glyphicon-search");

        a.addEventListener("click", evt => {
            evt.preventDefault();
            let img = a.querySelector("img");
            if (img === null) {
                img = document.createElement("img");
                img.src = a.href;
                img.setAttribute("style", "display: none;");
                a.appendChild(img);
                a.viewer = new Viewer(img);
            }
            a.viewer.show(true);
        });
    }
})();