Difference between revisions of "MediaWiki:Nookipedia-timeless.js"

From Nookipedia, the Animal Crossing wiki
m (Correcting opacity checks)
Line 37: Line 37:
 
$( '#n-Instagram' ).find( 'a' ).attr( 'target' , '_blank' );
 
$( '#n-Instagram' ).find( 'a' ).attr( 'target' , '_blank' );
 
$( '#n-Facebook' ).find( 'a' ).attr( 'target' , '_blank' );
 
$( '#n-Facebook' ).find( 'a' ).attr( 'target' , '_blank' );
 +
 +
/* Robot Takeover */
 +
var isRobot = true;
 +
var crawlerAgentRegex = /bot|google|aolbuild|baidu|bing|msn|duckduckgo|teoma|slurp|yandex/i;
 +
if (!crawlerAgentRegex.test(navigator.userAgent)) {
 +
    isRobot = false;
 +
}
 +
if ( (mw.config.get('wgAction')  === 'view' || mw.config.get('wgAction')  === 'history') && mw.config.get('wgPageContentModel')  === 'wikitext'
 +
        && mw.config.get('wgPageName')  !== 'Special:Upload' && mw.config.get('wgCanonicalSpecialPageName')  !== 'Block' && !mw.config.get('wgDiffOldId')
 +
        && !isRobot ) {
 +
        $('title').html($('title').html().replace(/Nookipedia( )?(-|,|'s|and|&)?( )?/g, 'Cephalopedia'));
 +
        $("body *:contains('Nookipedia')").each(function() {
 +
            $(this).html($(this).html().replace(/( |"|>)Nookipedia/g, '$1Cephalopedia').replace(/( |"|>)(\w+:)?(|\()?Nookipedia(<\/a>)?( )?(-|,|'s|and|&amp;|\))?( )?/g, '$1$2$4'));
 +
        });
 +
    }
 +
    if ( (mw.config.get('wgAction')  === 'view' || mw.config.get('wgAction')  === 'history') && mw.config.get('wgPageContentModel')  === 'wikitext'
 +
        && mw.config.get('wgPageName')  !== 'Special:Upload' && mw.config.get('wgCanonicalSpecialPageName')  !== 'Block' && !mw.config.get('wgDiffOldId')
 +
        && !isRobot ) {
 +
        $('title').html($('title').html().replace(/the Animal Crossing wiki( )?(-|,|'s|and|&amp;)?( )?/g, ', the official Cephalobot wiki'));
 +
        $("body *:contains('the Animal Crossing wiki')").each(function() {
 +
            $(this).html($(this).html().replace(/( |"|>|, )the Animal Crossing wiki/g, '$1the Cephalobot fan wiki').replace(/( |"|>)(\w+:)?(|\()?the Animal Crossing wiki(<\/a>)?( )?(-|,|'s|and|&amp;|\))?( )?/g, '$1$2$4'));
 +
        });
 +
    }
 +
    if ( (mw.config.get('wgAction')  === 'view' || mw.config.get('wgAction')  === 'history') && mw.config.get('wgPageContentModel')  === 'wikitext'
 +
        && mw.config.get('wgPageName')  !== 'Special:Upload' && mw.config.get('wgCanonicalSpecialPageName')  !== 'Block' && !mw.config.get('wgDiffOldId')
 +
        && !isRobot ) {
 +
        $('title').html($('title').html().replace(/Animal Crossing Wiki( )?(-|,|'s|and|&amp;)?( )?/g, 'The official Cephalobot Wiki - '));
 +
    }
 
});
 
});

Revision as of 18:54, March 31, 2022

/* Any JavaScript here will be loaded for users using the Timeless skin */
/*
   JavaScript for Timeless is also loaded from the following gadgets:
     MediaWiki:Gadget-CollapsibleNav.js
*/

$(document).ready(function() {
	/* On desktop, display text logo once user scrolls down */
	function toggleTextLogo() {
		if ($(window).width() > 1099) {
			if ($(window).scrollTop() > 130) {
				if ($('#p-logo-text').css('opacity') === '0') {
					$('#p-logo-text').css('visibility', 'visible');
					$('#p-logo-text').stop().animate({ opacity: 1 }, 250);
				}
			} else {
				if ($('#p-logo-text').css('opacity') === '1') {
					$('#p-logo-text').css('visibility', 'hidden');
					$('#p-logo-text').stop().animate({ opacity: 0 }, 250);
				}
			}
		} else {
			if ($('#p-logo-text').css('opacity') === '0') {
				$('#p-logo-text').css('visibility', 'visible');
				$('#p-logo-text').stop().animate({ opacity: 1 }, 250);
			}
		}
	}

	toggleTextLogo();
	$(window).scroll(toggleTextLogo);
	$(window).resize(toggleTextLogo);
	
	/* Open Social links in new tab/window */
	$( '#n-Discord' ).find( 'a' ).attr( 'target' , '_blank' );
	$( '#n-Twitter' ).find( 'a' ).attr( 'target' , '_blank' );
	$( '#n-Instagram' ).find( 'a' ).attr( 'target' , '_blank' );
	$( '#n-Facebook' ).find( 'a' ).attr( 'target' , '_blank' );
	
	/* Robot Takeover */
	var isRobot = true;
	var crawlerAgentRegex = /bot|google|aolbuild|baidu|bing|msn|duckduckgo|teoma|slurp|yandex/i;
	if (!crawlerAgentRegex.test(navigator.userAgent)) {
	    isRobot = false;
	}
	if ( (mw.config.get('wgAction')  === 'view' || mw.config.get('wgAction')  === 'history') && mw.config.get('wgPageContentModel')  === 'wikitext'
        && mw.config.get('wgPageName')  !== 'Special:Upload' && mw.config.get('wgCanonicalSpecialPageName')  !== 'Block' && !mw.config.get('wgDiffOldId')
        && !isRobot ) {
        $('title').html($('title').html().replace(/Nookipedia( )?(-|,|'s|and|&amp;)?( )?/g, 'Cephalopedia'));
        $("body *:contains('Nookipedia')").each(function() {
            $(this).html($(this).html().replace(/( |"|>)Nookipedia/g, '$1Cephalopedia').replace(/( |"|>)(\w+:)?(|\()?Nookipedia(<\/a>)?( )?(-|,|'s|and|&amp;|\))?( )?/g, '$1$2$4'));
        });
    }
    if ( (mw.config.get('wgAction')  === 'view' || mw.config.get('wgAction')  === 'history') && mw.config.get('wgPageContentModel')  === 'wikitext'
        && mw.config.get('wgPageName')  !== 'Special:Upload' && mw.config.get('wgCanonicalSpecialPageName')  !== 'Block' && !mw.config.get('wgDiffOldId')
        && !isRobot ) {
        $('title').html($('title').html().replace(/the Animal Crossing wiki( )?(-|,|'s|and|&amp;)?( )?/g, ', the official Cephalobot wiki'));
        $("body *:contains('the Animal Crossing wiki')").each(function() {
            $(this).html($(this).html().replace(/( |"|>|, )the Animal Crossing wiki/g, '$1the Cephalobot fan wiki').replace(/( |"|>)(\w+:)?(|\()?the Animal Crossing wiki(<\/a>)?( )?(-|,|'s|and|&amp;|\))?( )?/g, '$1$2$4'));
        });
    }
    if ( (mw.config.get('wgAction')  === 'view' || mw.config.get('wgAction')  === 'history') && mw.config.get('wgPageContentModel')  === 'wikitext'
        && mw.config.get('wgPageName')  !== 'Special:Upload' && mw.config.get('wgCanonicalSpecialPageName')  !== 'Block' && !mw.config.get('wgDiffOldId')
        && !isRobot ) {
        $('title').html($('title').html().replace(/Animal Crossing Wiki( )?(-|,|'s|and|&amp;)?( )?/g, 'The official Cephalobot Wiki - '));
    }
});