Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] option to add "Browse Scenes/images at current scene/images directory" #5546

Open
sntrenter opened this issue Dec 9, 2024 · 0 comments

Comments

@sntrenter
Copy link

Is your feature request related to a problem? Please describe.
I have a bunch of comics and images that are in a series in their own folder, it is sometimes hard to sort them or view them in a time efficient manor.

Describe the solution you'd like
I would love a button in the carousel or some place that isn't behind so many clicks. I'm not sure of what place would be best though.

Describe alternatives you've considered
I have developed a userscript to do this, but as far as I know it's only possible in the "file info" tab because that is where the link is.

// ==UserScript==
// @name         Browse at folder
// @namespace    http://tampermonkey.net/
// @version      2024-12-09
// @description  Add a button to search for files in the same folder
// @author       sntrenter
// @match        http://localhost:9999/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=undefined.localhost
// @grant        none
// ==/UserScript==
//may need to fix encodings https://www.w3schools.com/tags/ref_urlencode.ASP
(function() {
    'use strict';
    console.log("hello world!");

    // Add a button to search for files in the same folder
    document.body.addEventListener('click', function (event) {
        // File Info tab is clicked
        if (event.target.dataset.rbEventKey === "scene-file-info-panel" || event.target.dataset.rbEventKey === "image-file-info-panel") {
            console.log("hit");
            let type = event.target.dataset.rbEventKey.split("-")[0] + "s";
            console.log(type);

            // Wait for the panel to render
            setTimeout(() => {
                const tabContent = document.querySelector("div.tab-content");
                if (!tabContent) return;

                // Find the file path link
                const fileLink = Array.from(tabContent.querySelectorAll("a"))
                    .find(link => link.href.startsWith("file:///"));

                if (fileLink) {
                    // Extract the folder path
                    const filePath = new URL(fileLink.href).pathname;
                    const folderPath = filePath.substring(0, filePath.lastIndexOf('/')).replace(/%20/g, " ");
                    console.log(folderPath);

                    // Double encode the folder path (but fix escaping issues manually)
                    let adjustedPath = folderPath.replace(/\//g, "\\").replace(/\\/g, "\\\\") + "\\\\";
                    adjustedPath = adjustedPath.replace(/%7B/g,"{").replace(/%7D/g,"}").replace(/%5F/g, "_");
                    const searchParams = `("type":"path","value":"\\"${adjustedPath}\\"","modifier":"INCLUDES")`;

                    console.log(adjustedPath)

                    // Do not double-encode backslashes, encode the whole string correctly
                    const searchURL = `/${type}?c=${encodeURIComponent(searchParams)}&sortby=path`;
                    console.log(searchURL);


                    // Add a hyperlink (styled as a button) to navigate to the search page
                    if (!document.querySelector("#folder-search-button")) {
                        const button = document.createElement("a");
                        button.id = "folder-search-button";
                        button.textContent = "Search Folder";
                        button.href = searchURL; // Set the URL
                        button.style.display = "inline-block";
                        button.style.padding = "10px";
                        button.style.margin = "10px";
                        button.style.backgroundColor = "#007BFF";
                        button.style.color = "white";
                        button.style.textDecoration = "none";
                        button.style.borderRadius = "5px";
                        button.style.textAlign = "center";
                        button.style.cursor = "pointer";

                        button.onmouseenter = () => (button.style.backgroundColor = "#0056b3");
                        button.onmouseleave = () => (button.style.backgroundColor = "#007BFF");

                        tabContent.prepend(button);
                    }
                }
            }, 100); // Allow time for the tab content to load
        }
    });
})();

it should be noted that I haven't done a second pass at this script to clean it up/cover all edge cases.

Additional context
this would be great for people who use tools like gallery-dl or yt-dlp to mass download content in an organized way

I've seen a couple people say it wasn't really possible and I figured it was.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant