Clean Chegg

Formats Chegg pages nicely

目前为 2023-05-09 提交的版本。查看 最新版本

// ==UserScript==
// @name         Clean Chegg
// @description  Formats Chegg pages nicely
// @version      2.5
// @author       bhackel
// @homepageURL  https://github.com/bhackel/cheggbog
// @match        https://*.chegg.com/homework-help/*
// @icon         https://www.google.com/s2/favicons?domain=chegg.com
// @namespace    https://github.com/bhackel/cheggbog
// @license      MIT
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    setTimeout(function () {
        let elem;

        // Main page formatting
        elem = document.querySelector("#__next > div > div > div");
        if (elem) elem.style.margin = 0; // Removes auto centering of content
        document.querySelector("#chegg-main-content > form")?.remove(); // Removes the search box at the top of the page
        document.querySelector("#__next > div > div > div > header")?.remove(); // Removes the title bar at the top of the page
        document.querySelector("#chegg-main-content > div > div > div:nth-child(2)")?.remove(); // Removes the right sidebar
        document.querySelector("#__next > div > footer")?.remove() // Removes the footer
        document.querySelector("#chegg-main-content > div > div > div > div > div:nth-child(3)")?.remove(); // Removes "Up next in your courses" above footer
        document.querySelector("#chegg-main-content > div > div > div > div > div:nth-child(3)")?.remove(); // Removes "Post a Question" box
        document.querySelector("#__next > div > div > nav")?.remove() // Removes side navigation bar
        document.querySelector('#chegg-main-content > div > div > div > div > div:nth-child(2)')?.remove() // Removes the lower "Post a Question"

        // Details
        elem = document.querySelector("#chegg-main-content > div > div > div > div > div:nth-child(1) > section > div > div > div:nth-child(2) > div");
        if (elem) elem.style.maxWidth = "none"; // Allows question text to be infinitely wide
        elem = document.querySelector("#chegg-main-content");
        if (elem) elem.style.padding = "5px"; // Shrinks main content padding
        elem = document.querySelector("#chegg-main-content > div > div");
        if (elem) elem.style.display = "inline" // Makes content fill entire width of the page (up to a max set below)
        elem = document.querySelector("#chegg-main-content")
        if (elem) elem.style.width = "960px"; // Sets the width of the main content, change this according to the width of the window

        // Makes thumbs up/down more visible
        let thumbsDiv = document.querySelector('#qna-answer-rating-container > div');
        if (thumbsDiv) {
            thumbsDiv.style.fontSize = "75px";
        }

        // Repeatedly search for "All Steps" and click Show all steps once it has loaded
        let stepsInterval = setInterval(function() {
            // Click "All Steps" for pages with steps
            // first, click show one step
            let button = document.querySelector('#chegg-main-content > div > div > div > div > div > div:nth-child(2) > section > div:nth-child(4) > div > div > div > div > div > div:nth-child(1)');
            if (button) {
                button.click();
                // then, click show all steps after delay
                setTimeout(function () {
                    button = document.querySelector('#chegg-main-content > div > div > div > div > div > div:nth-child(2) > section > div:nth-child(4) > div > div > div > div > div > div:nth-child(2)');
                    if (button) {
                        button.click();
                        clearInterval(stepsInterval); // stop clicking when successful
                    }
                }, 100)
            }
        }, 1000);

        // Increase size of images when they are small for some reason
        elem = document.querySelector('#chegg-main-content > div > div > div > div > div:nth-child(2) > section')
        if (elem) {
            let ansImgLst = Array.from(elem.querySelectorAll('img')).slice(1); // get all images except some chegg one
            for (let img of ansImgLst) {
                if (parseInt(img.style.width, 10) < 600) {
                    img.style.width = '600px'
                }
            }
        }

    }, 3000) // Increase this delay for slower internet connections and page loading times
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址