Quora Enhancement

Make specific elements less wide on a page, remove Advertisement

当前为 2025-01-04 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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 ------------


})();