Greasy Fork is available in English.

Quora Enhancement

Make specific elements less wide on a page, remove Advertisement

// ==UserScript==
// @name         Quora Enhancement
// @namespace    http://tampermonkey.net/
// @version      0.2.1
// @description  Make specific elements less wide on a page, remove Advertisement
// @author       aspen138
// @match        *://www.quora.com/*
// @icon        https://qsf.cf2.quoracdn.net/-4-images.favicon-new.ico-26-07ecf7cd341b6919.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // Function to adjust width and position with animation
    function adjustWidthAndPosition() {
        // Find elements by the class name and specific inline style
        const elements = document.querySelectorAll('.q-box[style*="width: 356px;"]');

        // Loop through found elements and adjust width and position with animation
        elements.forEach(function (element) {
            element.style.transition = 'width 0.5s ease-in-out, right 0.5s ease-in-out'; // Animate width and right property
            element.style.width = '156px'; // Adjust width as desired
            element.style.position = 'relative'; // Set position to relative
            element.style.right = '0px'; // Move closer to the right, adjust as needed
        });

        // Find elements by the class name and specific inline style
        const elements1 = document.querySelectorAll('.q-box[id="mainContent"]');

        // Loop through found elements and adjust width and position with animation
        elements1.forEach(function (element) {
            element.style.transition = 'width 0.5s ease-in-out'; // Animate width property
            element.style.width = '956px'; // Adjust width as desired
            element.style.position = 'relative'; // Set position to relative
            // Animation for moving to the right is not necessary here as the original code was commented out
        });

    }

    // Run the adjustment function after the page loads
    window.addEventListener('load', adjustWidthAndPosition);



    // ------------ Function to Remove Ads and Sponsored Elements ------------

    // Function to remove ads and sponsored elements
    function removeAdsAndSponsored() {
        // Select ads by specific classes or IDs
        const ads = document.querySelectorAll('.q-box.spacing_log_question_page_ad, #bunwaeabjd');

        ads.forEach(ad => {
            if (ad) ad.remove();
        });

        // Select sponsored elements by their specific class
        const sponsoredElements = document.querySelectorAll('.dom_annotate_ad_image_ad');

        sponsoredElements.forEach(elem => {
            if (elem) elem.remove();
        });

        // Optionally, hide elements that indicate sponsorship without removing them
        // For example, if there's a "Sponsored" label you want to hide:
        const sponsoredLabels = document.querySelectorAll('.sponsored-label-class'); // Replace with actual class
        sponsoredLabels.forEach(label => {
            if (label) label.style.display = 'none';
        });
    }

    // Run the removeAdsAndSponsored function on page load
    window.addEventListener('load', removeAdsAndSponsored);

    // Optionally, run the removeAdsAndSponsored function periodically to catch and remove ads/sponsored content that load asynchronously
    setInterval(removeAdsAndSponsored, 3000); // Checks and removes ads/sponsored content every 3 seconds

    // ------------ Function to Remove Ads and Sponsored Elements ------------


})();