pplx Never Suggest - Hide Perplexity Suggestions & Widgets

Hide suggestion dropdown, homepage primers, and widgets on Perplexity

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         pplx Never Suggest - Hide Perplexity Suggestions & Widgets
// @namespace    https://github.com/ckep1/pplx-never-suggest
// @version      1.1.0
// @description  Hide suggestion dropdown, homepage primers, and widgets on Perplexity
// @author       Chris Kephart
// @match        https://www.perplexity.ai/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const defaultSettings = {
        hideSuggestions: true,
        hidePrimers: true,
        hideUpsells: true
    };

    function getSetting(key) {
        return GM_getValue(key, defaultSettings[key]);
    }

    function setSetting(key, value) {
        GM_setValue(key, value);
        location.reload();
    }

    // --- localStorage overrides ---

    const LS_DEFS = {
        suggestions: [
            { key: 'pplx.local-user-settings.isSuggestionsDisabled', value: 'true' }
        ],
        primers: [
            { key: 'pplx.local-user-settings.isHomepageWidgetsDisabled', value: 'true' },
            { key: 'pplx.local-user-settings.isDiscoverInterestBoxDismissed', value: 'true' }
        ],
        upsells: [
            { key: 'pplx.local-user-settings.isEnterpriseAdDismissed', value: 'true' },
            { key: 'pplx.local-user-settings.isSidebarConnectorsAdDismissed', value: 'true' },
            { key: 'pplx.local-user-settings.isSportsIosCtaDismissed', value: 'true' },
            { key: 'pplx.local-user-settings.isStudentSpaceUpsellDismissed', value: 'true' },
            { key: 'always-on-download-comet-banner-enabled', value: 'false' },
            { key: 'pplx_show_comet_upsell_existing_comet_user', value: 'false' }
        ]
    };

    function applySettings() {
        if (getSetting('hideSuggestions')) {
            LS_DEFS.suggestions.forEach(e => localStorage.setItem(e.key, e.value));
        }
        if (getSetting('hidePrimers')) {
            LS_DEFS.primers.forEach(e => localStorage.setItem(e.key, e.value));
        }
        if (getSetting('hideUpsells')) {
            LS_DEFS.upsells.forEach(e => localStorage.setItem(e.key, e.value));
        }
    }

    // --- CSS injection (runs at document-start, before DOM renders) ---

    function injectStyles() {
        const rules = [];

        if (getSetting('hideSuggestions')) {
            rules.push(
                `[data-testid="autosuggestion-container"] { display: none !important; }`,
                `.bg-raised:has([data-testid="autosuggestion-container"]) { display: none !important; }`,
                `[data-placement]:has([data-testid="autosuggestion-container"]) { display: none !important; }`,
                `div:has(> [data-placement] [data-testid="autosuggestion-container"]) { display: none !important; }`,
                `.rounded-b-none.border-b-none {
                    border-bottom-left-radius: 16px !important;
                    border-bottom-right-radius: 16px !important;
                    border-bottom-style: solid !important;
                }`
            );
        }

        if (getSetting('hidePrimers')) {
            rules.push(
                `.group\\/primer { display: none !important; }`,
                `[aria-label="Primer query categories"] { display: none !important; }`,
                `div.mt-lg.absolute.w-full:has(.group\\/primer) { display: none !important; }`,
                `div.mt-lg.absolute.w-full:has([aria-label="Primer query categories"]) { display: none !important; }`
            );
        }

        if (rules.length === 0) return;

        const style = document.createElement('style');
        style.id = 'pplx-never-suggest';
        style.textContent = rules.join('\n');
        (document.head || document.documentElement).appendChild(style);
    }

    // --- MutationObserver fallback (catches late-rendered elements) ---

    function startObserver() {
        const hideSuggestions = getSetting('hideSuggestions');
        const hidePrimers = getSetting('hidePrimers');
        if (!hideSuggestions && !hidePrimers) return;

        const startTime = Date.now();
        const observer = new MutationObserver(() => {
            // Re-enforce localStorage for the first 5s while Perplexity's JS initializes
            if (Date.now() - startTime < 5000) applySettings();

            if (hideSuggestions) {
                document.querySelectorAll('[data-testid="autosuggestion-container"]').forEach(el => {
                    const popup = el.closest('[data-placement]')?.parentElement || el;
                    if (popup.style.display !== 'none') popup.style.display = 'none';
                });
            }
            if (hidePrimers) {
                document.querySelectorAll('.group\\/primer, [aria-label="Primer query categories"]').forEach(el => {
                    const target = el.closest('.mt-lg.absolute') || el;
                    if (target.style.display !== 'none') target.style.display = 'none';
                });
            }
        });

        const start = () => {
            observer.observe(document.body, { childList: true, subtree: true });
        };

        if (document.body) start();
        else document.addEventListener('DOMContentLoaded', start);
    }

    // --- Menu commands ---

    GM_registerMenuCommand(`${getSetting('hideSuggestions') ? '✅' : '❌'} Hide Suggestions (typing)`, () => {
        setSetting('hideSuggestions', !getSetting('hideSuggestions'));
    });

    GM_registerMenuCommand(`${getSetting('hidePrimers') ? '✅' : '❌'} Hide Homepage Primers`, () => {
        setSetting('hidePrimers', !getSetting('hidePrimers'));
    });

    GM_registerMenuCommand(`${getSetting('hideUpsells') ? '✅' : '❌'} Hide Upsells & Banners`, () => {
        setSetting('hideUpsells', !getSetting('hideUpsells'));
    });

    // --- Init ---

    applySettings();
    injectStyles();
    startObserver();

})();