GithubHelp home page GithubHelp logo

Comments (2)

Spicadox avatar Spicadox commented on May 31, 2024 1

I guess not, unless you're willing to use my cookie file, then I could dm you my cookie file.

After looking into it more, I found that my script file may also be contributing to the issue. I may be grasping at straws and since you haven't reproduced the issue you probably won't know, but my script basically ensures the image quality is at the highest plus with cookies there would be more images and content populating the page. As such, for a huge webpage with lots of images, I'm guessing this could cause an issue since removing either my cookies or script in the command(so either less data being saved or a very large image is perhaps causing issue) won't result in the error?

edit: Manually running each part of my script on chrome and then using the single file extension seems to work though so I'm at a lost

edit2: Sorry for being a pain but setting images to a smaller size of max height of 720 fixed the issue so I am guessing large image(s) is causing issue with base64 string being too large?

Script in question(not great with javascript, but it's been doing it's job fine on other smaller pages):

// ==UserScript==
// @name         Change images' resolution
// @version      1.0
// @description  [SingleFile] Replace img url with a higher resolution version
// ==/UserScript==



(() => {
    // Get the image element that has a src attribute and an empty alt(use to ignore profile images)
    const imgElementsSelector = "img[src]:not([src=''])";

    // Regex grouping[0] is the original string
    // Group[1] is the entire string before =s where everything after the domain name is between 30-85 characters
    // Group[2] will be used and set to 0 to obtain the max resolution of the image
    const pattern = "(https:\/\/yt3\.(ggpht|googleusercontent)\.com\/.{30,85})(=[a-z]{1})(.*)";

    const DELAY = 10000;

    function waitForElm(selector) {
        return new Promise(resolve => {
            if (document.querySelector(selector)) {
                return resolve(document.querySelector(selector));
            }

            const observer = new MutationObserver(mutations => {
                if (document.querySelector(selector)) {
                    resolve(document.querySelector(selector));
                    observer.disconnect();
                }
            });

            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
        });
    }

    function unCollapse() {
        // uncollapse show perks info on membership pages(to show stamps)
        try {
            document.querySelector("ytd-sponsorships-expandable-perks-renderer.style-scope.ytd-section-list-renderer").removeAttribute("is-collapsed");
            console.log("Uncollapsed")
            changeImageQuality()
        } catch (error) {
            console.log("Unable to find or remove show perk info button");
            console.error(error);
        }
    }
    function changeImageQuality() {
        // Only want images in the content element
        let content = document.getElementById("contents").getElementsByClassName("style-scope ytd-section-list-renderer")
        for (let i = 0; i < content.length; i++) {
            content[i].querySelectorAll(imgElementsSelector).forEach(element => {
                try {
                    let img_src = element.getAttribute("src");
                    group_match = img_src.match(pattern);
                    new_img_src = group_match[1] + '=s0';
                    element.setAttribute("src", new_img_src);
                } catch (error) {
                    console.log("Encountered Error");
                    console.error(error);
                }
            })
        }
    }
    dispatchEvent(new CustomEvent("single-file-user-script-init"));
    addEventListener("single-file-on-before-capture-request",  async event => {
        //Wait for the element before uncollapse 
        try {
            waitForElm('ytd-sponsorships-expandable-perks-renderer.style-scope.ytd-section-list-renderer').then((elm) => {
                console.log('Element is ready');
                unCollapse()
            });
        } catch (error) {
            console.error(error)
        }
        //Remove multi-image box items
        try {
            //remove the image icon on the bottom right of the images
            document.querySelectorAll("yt-icon.style-scope.ytd-backstage-image-renderer").forEach(element => {
                element.remove();
            })
            //remove the right arrow container and all
            document.querySelectorAll("div.arrow-container.style-scope.ytd-post-multi-image-renderer").forEach(element => {
                element.remove();
            })
            //remove the box container
            document.querySelectorAll(".style-scope ytd-post-multi-image-renderer #items").forEach(element => {
                element.removeAttribute("class");
            })
        } catch (error) {
            console.log("Unable to remove multi-image box items");
            console.error(error);
        }

        //Wait for the membership images to load in
        try {
            event.preventDefault();
            await new Promise(resolve => setTimeout(resolve, DELAY));
        } catch (error) {
            console.error(error)
        }

        changeImageQuality()
        // Wait for the page to load after the previous changes before capturing
        event.preventDefault();
        try {
            await new Promise(resolve => setTimeout(resolve, DELAY));
        } finally {
            dispatchEvent(new CustomEvent("single-file-on-before-capture-response"));
        }
        console.log("Finished script");
        return;
    });
})();

from single-file-cli.

gildas-lormeau avatar gildas-lormeau commented on May 31, 2024

Is it possible for me to reproduce the issue?

from single-file-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.