Järjestelmäviesti:Common.js

KKWikistä
Versio hetkellä 16. helmikuuta 2021 kello 14.36 – tehnyt Tapsa (keskustelu | muokkaukset)

Huomautus: Selaimen välimuisti pitää tyhjentää asetusten tallentamisen jälkeen, jotta muutokset tulisivat voimaan.

  • Firefox ja Safari: Napsauta Shift-näppäin pohjassa Päivitä, tai paina Ctrl-F5 tai Ctrl-R (⌘-R Macilla)
  • Google Chrome: Paina Ctrl-Shift-R (⌘-Shift-R Macilla)
  • Internet Explorer: Napsauta Ctrl-näppäin pohjassa Päivitä tai paina Ctrl-F5
  • Opera: Valikko → Asetukset (Opera → Asetukset Macilla) ja sitten Tietosuoja ja turvallisuus → Tyhjennä selaustiedot → Välimuistissa olevat kuvat ja tiedostot.
/* Tämän sivun JavaScript-koodi liitetään jokaiseen sivulataukseen */

var _kk_seed = 1;
function kk_random() {
    var x = Math.sin(_kk_seed++) * 10000;
    return x - Math.floor(x);
}

function kk_random_word(){
	var o = '';
	var l = 2 + kk_random()*8;
	for (var i = 0; i < l; i++) {
		o += 'n';
	}
	return o;
}


$(document).ready(function(){
	
	var _u = window.location.href;
	_kk_seed = _u.length;
	for (var i = 0; i < _u.length; i++) {
		_kk_seed += _u.charCodeAt(i);
	}
	
	// replace feathericons
	feather.replace();
	
	// hide the stupid navigation options under the title
	$('#mw-page-header-links').hide();
	
	$('#p-views li').each(function(){
		if (!$(this).is('#ca-more')) {
			$('#p-cactions ul').prepend($(this));
		}
	});
	
	// if the current page asks us to hide non-top-level toc entries
	if ($('.x-toc-main-only').length > 0) {
		$('#toc li:not(.toclevel-1)').hide();
		$('.x-toc-main-only').show();
	}
	
	// item displays
	if ($('.x-item').length > 0) {
		
		$('.x-item').each(function(){
			
			var itemImage = $(this).attr('data-item');
		
			if (itemImage && itemImage != '') {
	            if (itemImage.indexOf('http') == 0) {
	                $(this).css('background-image', 'url("' + itemImage + '")');
	            } else {
	                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + itemImage + '.png")');
	            }
	        }
			
		});
		
	}
	
	// classified/redacted
	if ($('.kk-redacted').length > 0) {
		$('.kk-redacted').each(function(){
			
			var outText = '';
			var chapterCount = 1 + Math.floor(kk_random()*3);
			
			for (var c = 0; c < chapterCount; c++) {
				var wordCount = 5 + Math.floor(kk_random()*50);
				for (var w = 0; w < wordCount; w++) {
					outText += '<span style="margin: 0.1em; background-color: black; color: black; display: inline-block; transform: rotate('+(2-kk_random()*4)+'deg);">' + kk_random_word() + '</span> ';
				}
				outText += '<br><br>';
			}
			
			$(this).append(outText);
			
		});
	}
	
});


/*
 * RECIPE VIEWER
 */
$(document).ready(function(){
        
        var tooltipVisible = false;
        
        if ($('.x-crafting').length > 0) {
            
            $('body').append('<div class="x-crafting-tooltip" style="display: none;">Tooltip is not working.<br>Please contact Tapsa.</div>');
            $('.x-crafting-item').each(function(){
                
                var itemImage = $(this).attr('data-item');
                
                if (itemImage != '') {
                    if (itemImage.indexOf('item:') == 0) {
                        $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + itemImage.replace('item:', '') + '.png")');
                    } else {
                        $(this).css('background-image', 'url("' + itemImage + '")');
                    }
                } else {
                    $(this).css('cursor', 'default');
                }
                
            });
            
            $('body').on('mousemove', function(e){
                if (tooltipVisible) {
                    
                    $('.x-crafting-tooltip').css({
                        top: (e.clientY + 15)+'px',
                        left: (e.clientX + 15)+'px'
                    });
                    
                }
            });
            
            $('.x-crafting-item').on('mouseover', function(e){
                
                if ($(this).attr('data-item') != '' && $(this).attr('data-hover') != '') {
                    $('.x-crafting-tooltip').text($(this).attr('data-hover')).show();
                    tooltipVisible = true;
                }
                
            });
            
            $('.x-crafting-item').on('mouseout', function(e){
                
                $('.x-crafting-tooltip').hide();
                tooltipVisible = false;
                
            });
            
            $('.x-crafting-item').on('click', function(e){
                window.location.href = 'https://kk.xenomc.fi/wiki/index.php/' + encodeURIComponent($(this).attr('data-hover'));
            });
            
            var rs = function(){
                $('.x-crafting').each(function(){
                    if ($(this).parent().width() < 350) {
                        var sc = $(this).parent().width()/375;
                        $(this).css('transform-origin', 'top left');
                        $(this).css('transform', 'scale('+sc+')');
                    }
                });
            }
            
            rs();
            $(window).resize(rs);
            
        }
        
    });