MediaWiki:Common.js: Difference between revisions

From Riverview Legal Group
Access restrictions were established for this page. If you see this message, you have no access to this page.
mNo edit summary
mNo edit summary
Line 38: Line 38:
             // Create persistent overlay message directly after the third <h2> tag
             // Create persistent overlay message directly after the third <h2> tag
             var $overlayMessage = $('<div id="patreon-overlay">' +
             var $overlayMessage = $('<div id="patreon-overlay">' +
                 '<p>Subscribe to our <a href="https://www.patreon.com/c/CaselawNinja" target="_blank">Patreon</a> for full access! <br> Only $5.50 CAD per month.</p>' +
                 '<p>Subscribe to our <a href="https://www.patreon.com/CaselawNinja" target="_blank">Patreon</a> for full access! <br> Only $5.50 CAD per month.</p>' +
                '<p class="login-text">Already a Subscriber? <a href="https://riverview.legal/encyclopedia/index.php?title=Special:UserLogin" target="_blank">Login here</a></p>' +
                 '</div>');
                 '</div>');


Line 44: Line 45:
             $thirdHeader.after($overlayMessage);
             $thirdHeader.after($overlayMessage);


             // Create the Stripe popup
             // Create the Patreon popup
             var $stripePopup = $('<div class="popup-overlay" id="stripe-popup">' +
             var $patreonPopup = $('<div class="popup-overlay" id="patreon-popup">' +
                 '<div class="popup-box" style="top: 50%; left: 50%; transform: translate(-50%, -50%);">' +
                 '<div class="popup-box" style="top: 50%; left: 50%; transform: translate(-50%, -50%);">' +
                 '<h2>Subscribe to Unlock Content</h2>' +
                 '<h2>Support Us on Patreon</h2>' +
                 '<p>Subscribe to view the full article.</p>' +
                 '<p>Unlock all content for only <strong>$5.50 CAD per month</strong>.</p>' +
                 '<button id="subscribe-button" class="popup-button">Subscribe</button>' +
                 '<a href="https://www.patreon.com/CaselawNinja" target="_blank" id="subscribe-button" class="popup-button">Subscribe</a>' +
                 '<span class="popup-close">×</span>' +
                 '<span class="popup-close">×</span>' +
                 '</div>' +
                 '</div>' +
                 '</div>');
                 '</div>');


             $("body").append($stripePopup);
             $("body").append($patreonPopup);


            // Stripe Checkout Handler
             // Close Patreon popup
            $("#subscribe-button").click(function () {
             $("#patreon-popup .popup-close").click(function () {
                var stripe = Stripe("your_stripe_publishable_key");
                 $("#patreon-popup").fadeOut(function () { $(this).remove(); });
                stripe.redirectToCheckout({
                    sessionId: "your_checkout_session_id"
                }).then(function (result) {
                    if (result.error) {
                        alert(result.error.message);
                    }
                });
            });
 
             // Close Stripe popup
             $("#stripe-popup .popup-close").click(function () {
                 $("#stripe-popup").fadeOut(function () { $(this).remove(); });
             });
             });
         } else {
         } else {
Line 84: Line 73:
     ".popup-box { background: white; padding: 20px; border-radius: 10px; text-align: center; width: 300px;" +
     ".popup-box { background: white; padding: 20px; border-radius: 10px; text-align: center; width: 300px;" +
     "box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); position: absolute; }" +
     "box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); position: absolute; }" +
     ".popup-button { display: inline-block; background: #007bff; color: white; padding: 10px;" +
     ".popup-button { display: inline-block; background: #E85D04; color: white; padding: 10px 15px;" +
     "text-decoration: none; border-radius: 5px; margin-top: 10px; }" +
     "text-decoration: none; font-size: 16px; border-radius: 5px; margin-top: 10px; font-weight: bold;" +
    "}" +
    ".popup-button:hover { background: #ff6a00; }" +
     ".popup-close { position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 20px;" +
     ".popup-close { position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 20px;" +
     "color: black; font-weight: bold; }" +
     "color: black; font-weight: bold; }" +
Line 96: Line 87:
     "}" +
     "}" +
     "#patreon-overlay a { color: #E85D04; text-decoration: none; font-weight: bold; }" +
     "#patreon-overlay a { color: #E85D04; text-decoration: none; font-weight: bold; }" +
     "#patreon-overlay a:hover { text-decoration: underline; }"
     "#patreon-overlay a:hover { text-decoration: underline; }" +
    ".login-text { font-size: 16px; margin-top: 10px; font-weight: normal; color: #555; }" +
    ".login-text a { color: #007bff; font-weight: bold; text-decoration: none; }" +
    ".login-text a:hover { text-decoration: underline; }"
);
);

Revision as of 00:38, 2 March 2025

console.log("Common.js is loading correctly!");

// Ensure the script only loads after dependencies
mw.loader.using(['jquery', 'mediawiki.user'], function () {
    $(document).ready(function () {
        var loggedInUser = mw.config.get('wgUserName');
        var pageNamespace = mw.config.get('wgCanonicalNamespace');
        console.log("Logged-in User:", loggedInUser);
        console.log("Page Namespace:", pageNamespace);

        // Exit script if user is logged in or on a category page
        if (loggedInUser || pageNamespace === "Category") {
            console.log("User is logged in or on a category page. No blur applied.");
            return;
        }

        console.log("User is not logged in. Applying blur effect.");

        // Find the third subheader
        var $subHeaders = $("#mw-content-text h2");

        if ($subHeaders.length >= 3) {
            console.log("Applying blur after third header.");
            var $thirdHeader = $subHeaders.eq(2);

            // Select only content below the third header, excluding side menus
            var $contentToBlur = $thirdHeader.nextAll()
                .not(".sidebar, .mw-portlet, #p-tb, #p-personal, #footer, #catlinks");

            // Apply blur effect
            $contentToBlur.css({
                "filter": "blur(8px)",
                "pointer-events": "none",
                "user-select": "none",
                "position": "relative"
            });

            // Create persistent overlay message directly after the third <h2> tag
            var $overlayMessage = $('<div id="patreon-overlay">' +
                '<p>Subscribe to our <a href="https://www.patreon.com/CaselawNinja" target="_blank">Patreon</a> for full access! <br> Only $5.50 CAD per month.</p>' +
                '<p class="login-text">Already a Subscriber? <a href="https://riverview.legal/encyclopedia/index.php?title=Special:UserLogin" target="_blank">Login here</a></p>' +
                '</div>');

            // Insert the overlay **immediately after the third h2**
            $thirdHeader.after($overlayMessage);

            // Create the Patreon popup
            var $patreonPopup = $('<div class="popup-overlay" id="patreon-popup">' +
                '<div class="popup-box" style="top: 50%; left: 50%; transform: translate(-50%, -50%);">' +
                '<h2>Support Us on Patreon</h2>' +
                '<p>Unlock all content for only <strong>$5.50 CAD per month</strong>.</p>' +
                '<a href="https://www.patreon.com/CaselawNinja" target="_blank" id="subscribe-button" class="popup-button">Subscribe</a>' +
                '<span class="popup-close">×</span>' +
                '</div>' +
                '</div>');

            $("body").append($patreonPopup);

            // Close Patreon popup
            $("#patreon-popup .popup-close").click(function () {
                $("#patreon-popup").fadeOut(function () { $(this).remove(); });
            });
        } else {
            console.warn("Not enough headers found for blur effect.");
        }
    });
});

// Unified CSS for popups & overlay text
mw.util.addCSS(
    ".popup-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%;" +
    "background: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: center; z-index: 9999; }" +
    ".popup-box { background: white; padding: 20px; border-radius: 10px; text-align: center; width: 300px;" +
    "box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); position: absolute; }" +
    ".popup-button { display: inline-block; background: #E85D04; color: white; padding: 10px 15px;" +
    "text-decoration: none; font-size: 16px; border-radius: 5px; margin-top: 10px; font-weight: bold;" +
    "}" +
    ".popup-button:hover { background: #ff6a00; }" +
    ".popup-close { position: absolute; top: 10px; right: 15px; cursor: pointer; font-size: 20px;" +
    "color: black; font-weight: bold; }" +
    ".popup-close:hover { color: red; }" +

    /* Patreon Overlay Styling */
    "#patreon-overlay { width: 100%; text-align: center; margin-top: 15px;" +
    "background: rgba(255, 255, 255, 0.9); padding: 15px; font-size: 18px;" +
    "font-weight: bold; color: #333; border-radius: 5px; z-index: 10;" +
    "}" +
    "#patreon-overlay a { color: #E85D04; text-decoration: none; font-weight: bold; }" +
    "#patreon-overlay a:hover { text-decoration: underline; }" +
    ".login-text { font-size: 16px; margin-top: 10px; font-weight: normal; color: #555; }" +
    ".login-text a { color: #007bff; font-weight: bold; text-decoration: none; }" +
    ".login-text a:hover { text-decoration: underline; }"
);