HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-seopress/assets/js/seopress-dashboard.js
jQuery(document).ready(function ($) {
    //If no notices
    if (!$.trim($("#seopress-notifications-center").html())) {
        $('#seopress-notifications-center').remove();
    }
    const notices = [
        "notice-get-started",
        "notice-usm",
        "notice-wizard",
        "notice-amp-analytics",
        "notice-litespeed-cache",
        "notice-divide-comments",
        "notice-review",
        "notice-trailingslash",
        "notice-posts-number",
        "notice-xml-sitemaps",
        "notice-rss-use-excerpt",
        "notice-ga-ids",
        "notice-search-console",
        "notice-google-business",
        "notice-ssl",
        "notice-title-tag",
        "notice-enfold",
        "notice-themes",
        "notice-ebooks",
        "notice-integrations",
        "notice-noindex",
        "notice-tasks",
        "notice-insights",
        "notice-robots-txt",
        "notice-robots-txt-valid",
        "notice-wpml-active",
        "notice-promotions",
    ]
    notices.forEach(function (item) {
        $('#' + item).on('click', function () {
            $('#' + item).attr('data-notice', $('#' + item).attr('data-notice') == '1' ? '0' : '1');

            $.ajax({
                method: 'POST',
                url: seopressAjaxHideNotices.seopress_hide_notices,
                data: {
                    action: 'seopress_hide_notices',
                    notice: item,
                    notice_value: $('#' + item).attr('data-notice'),
                    _ajax_nonce: seopressAjaxHideNotices.seopress_nonce,
                },
                success: function (data) {
                    $('#seopress-notice-save').css('display', 'block');
                    $('#seopress-notice-save .html').html('Notice successfully removed');
                    $('#' + item + '-alert').fadeOut();
                    $('#seopress-notice-save').delay(3500).fadeOut();
                },
            });
        });
    });

    const features = [
        "titles",
        "xml-sitemap",
        "social",
        "google-analytics",
        "instant-indexing",
        "advanced",
        "local-business",
        "woocommerce",
        "edd",
        "alerts",
        "dublin-core",
        "rich-snippets",
        "breadcrumbs",
        "inspect-url",
        "robots",
        "llms",
        "news",
        "404",
        "bot",
        "rewrite",
        "white-label",
        "ai",
        "agent-ready",
        "universal-metabox"
    ]
    features.forEach(function (item) {
        $('#toggle-' + item).on('click', function () {
            $('#toggle-' + item).attr('data-toggle', $('#toggle-' + item).attr('data-toggle') == '1' ? '0' : '1');

            $(this).siblings('#titles-state-default').toggleClass('feature-state-off');
            $(this).siblings('#titles-state').toggleClass('feature-state-off');

            $.ajax({
                method: 'POST',
                url: seopressAjaxToggleFeatures.seopress_toggle_features,
                data: {
                    action: 'seopress_toggle_features',
                    feature: 'toggle-' + item,
                    feature_value: $('#toggle-' + item).attr('data-toggle'),
                    _ajax_nonce: seopressAjaxToggleFeatures.seopress_nonce,
                },
                success: function () {
                    // Use WP notices store on React settings pages, fall back to legacy snackbar.
                    if (window.wp && window.wp.data && window.wp.data.dispatch('core/notices')) {
                        window.wp.data.dispatch('core/notices').createSuccessNotice(
                            seopressAjaxToggleFeatures.i18n?.saved || 'Settings saved successfully.',
                            { type: 'snackbar', isDismissible: true, id: 'seopress-toggle-success' }
                        );
                    } else {
                        $('#seopress-notice-save').show();
                        $('#seopress-notice-save').delay(3500).fadeOut();
                    }
                },
            });
        });
    });
    $('#seopress-activity-panel button, #seopress-notifications button').on('click', function () {
        $(this).toggleClass('is-active');
        $('#seopress-activity-panel-' + $(this).data('panel')).toggleClass('is-open');
    });
    $('#wpbody-content > form, #seopress-content').on('click', function (e) {
        if (e.target.id !== 'seopress-see-notifications') {
            $('#seopress-activity-panel').find('.is-open').toggleClass('is-open');
            $('#seopress-activity-panel').find('.is-active').toggleClass('is-active');
        }
    });
    $('.seopress-item-toggle-options').on('click', function () {
        $(this).next('.seopress-card-popover').toggleClass('is-open');
    });

    $('#seopress_news').on('click', function () {
        $('#seopress-news-panel').toggleClass('is-active');
        $('#seopress_news').attr('data-toggle', $('#seopress_news').attr('data-toggle') == '1' ? '0' : '1');
        $.ajax({
            method: 'POST',
            url: seopressAjaxDisplay.seopress_display,
            data: {
                action: 'seopress_display',
                news_center: $('#seopress_news').attr('data-toggle'),
                _ajax_nonce: seopressAjaxDisplay.seopress_nonce,
            },
        });
    });
    $('#seopress_tools').on('click', function () {
        $('#notice-insights-alert').toggleClass('is-active');
        $('#seopress_tools').attr('data-toggle', $('#seopress_tools').attr('data-toggle') == '1' ? '0' : '1');
        $.ajax({
            method: 'POST',
            url: seopressAjaxDisplay.seopress_display,
            data: {
                action: 'seopress_display',
                tools_center: $('#seopress_tools').attr('data-toggle'),
                _ajax_nonce: seopressAjaxDisplay.seopress_nonce,
            },
        });
    });
    $('#notifications_center').on('click', function () {
        $('#seopress-notifications').toggleClass('is-active');
        $('#notifications_center').attr('data-toggle', $('#notifications_center').attr('data-toggle') == '1' ? '0' : '1');
        $.ajax({
            method: 'POST',
            url: seopressAjaxDisplay.seopress_display,
            data: {
                action: 'seopress_display',
                notifications_center: $('#notifications_center').attr('data-toggle'),
                _ajax_nonce: seopressAjaxDisplay.seopress_nonce,
            },
        });
    });
    $('#notice-tasks').on('click', function () {
        $('#notice-tasks-alert').toggleClass('is-active');
        $('#notice-tasks').attr('data-toggle', $('#notice-tasks').attr('data-toggle') == '1' ? '0' : '1');
    });
    $('#notice-get-started').on('click', function () {
        $('#notice-get-started-alert').toggleClass('is-active');
        $('#notice-get-started').attr('data-toggle', $('#notice-get-started').attr('data-toggle') == '1' ? '0' : '1');
    });
    $('#notice-integrations').on('click', function () {
        $('#seopress-integration-panel').toggleClass('is-active');
        $('#notice-integrations').attr('data-toggle', $('#notice-integrations').attr('data-toggle') == '1' ? '0' : '1');
    });
    $('#notice-ebooks').on('click', function () {
        $('#seopress-ebook-panel').toggleClass('is-active');
        $('#notice-ebooks').attr('data-toggle', $('#notice-ebooks').attr('data-toggle') == '1' ? '0' : '1');
    });
    $('#notice-promotions').on('click', function () {
        $('#seopress-promotions-panel').toggleClass('is-active');
        $('#notice-promotions').attr('data-toggle', $('#notice-promotions').attr('data-toggle') == '1' ? '0' : '1');
    });
});

//Dashboard - Simple view
jQuery(document).ready(function ($) {
    $('.seopress-btn-view-switch').on('click', function () {
        $('body').toggleClass('seopress-simple-view');
        $.ajax({
            method: 'POST',
            url: seopressAjaxSwitchView.seopress_switch_view,
            data: {
                action: 'seopress_switch_view',
                view: $('body').hasClass('seopress-simple-view') ? 'simple' : 'default',
                _ajax_nonce: seopressAjaxSwitchView.seopress_nonce,
            },
        });
    });
});

//SEO Tools Tabs
jQuery(document).ready(function ($) {
    var get_hash = window.location.hash;
    var clean_hash = get_hash.split('$');

    if (typeof sessionStorage != 'undefined') {
        var seopress_admin_tab_session_storage = sessionStorage.getItem("seopress_admin_tab");

        // Activate a tab only if its nav-tab is actually rendered, otherwise fall back to the first available tab.
        function seopressActivateDashboardTab(tabKey) {
            var $navTab = tabKey ? $('#' + tabKey + '-tab') : $();
            if ($navTab.length) {
                $('#seopress-admin-tabs').find('.nav-tab.nav-tab-active').removeClass("nav-tab-active");
                $('#seopress-admin-tabs').find('.seopress-tab.active').removeClass("active");
                $navTab.addClass("nav-tab-active");
                $('#' + tabKey).addClass("active");
                return true;
            }
            return false;
        }

        function seopressActivateDefaultDashboardTab() {
            var $firstNavTab = $('#seopress-admin-tabs a.nav-tab').first();
            if (!$firstNavTab.length) {
                return;
            }
            var hrefParts = ($firstNavTab.attr('href') || '').split('#tab=');
            var defaultTab = hrefParts[1] || $firstNavTab.attr('id').replace(/-tab$/, '');
            seopressActivateDashboardTab(defaultTab);
        }

        var hashTabMap = {
            '1': 'tab_seopress_analytics',
            '2': 'tab_seopress_matomo',
            '3': 'tab_seopress_ps',
            '4': 'tab_seopress_gsc'
        };

        if (hashTabMap[clean_hash[1]]) {
            if (!seopressActivateDashboardTab(hashTabMap[clean_hash[1]])) {
                seopressActivateDefaultDashboardTab();
            }
        } else if (seopress_admin_tab_session_storage) {
            var sessionTab = seopress_admin_tab_session_storage.split('#tab=')[0];
            if (!seopressActivateDashboardTab(sessionTab)) {
                seopressActivateDefaultDashboardTab();
            }
        } else {
            seopressActivateDefaultDashboardTab();
        }
    };
    $("#seopress-admin-tabs").find("a.nav-tab").click(function (e) {
        e.preventDefault();
        var hash = $(this).attr('href').split('#tab=')[1];

        $('#seopress-admin-tabs').find('.nav-tab.nav-tab-active').removeClass("nav-tab-active");
        $('#' + hash + '-tab').addClass("nav-tab-active");

        if (clean_hash[1] == 1) {
            sessionStorage.setItem("seopress_admin_tab", 'tab_seopress_analytics');
        } else if (clean_hash[1] == 2) {
            sessionStorage.setItem("seopress_admin_tab", 'tab_seopress_matomo');
        } else if (clean_hash[1] == 3) {
            sessionStorage.setItem("seopress_admin_tab", 'tab_seopress_ps_tools');
        } else {
            sessionStorage.setItem("seopress_admin_tab", hash);
        }

        $('#seopress-admin-tabs').find('.seopress-tab.active').removeClass("active");
        $('#' + hash).addClass("active");
    });

    // Copy sitemap URL to clipboard
    $('#seopress-copy-sitemap-url').on('click', function(e) {
        e.preventDefault();
        const $input = $('#seopress-sitemap-url');
        const $button = $(this);
        const $icon = $button.find('.dashicons');
        const $text = $button.find('.seopress-btn-text');
        const originalText = $text.text();

        navigator.clipboard.writeText($input.val()).then(function() {
            // Update button state
            $icon.removeClass('dashicons-clipboard').addClass('dashicons-yes');
            $text.text('Copied!');

            setTimeout(function() {
                $icon.removeClass('dashicons-yes').addClass('dashicons-clipboard');
                $text.text(originalText);
            }, 2000);
        }).catch(function(err) {
            console.error('Failed to copy:', err);
        });
    });
});