Järjestelmäviesti:Common.js

KKWikistä
Versio hetkellä 27. marraskuuta 2021 kello 20.39 – 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()*15;
	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();
	}
	
	if ($('[data-hide-title]').length > 0) {
		$('[data-hide-title]').hide();
		$('#firstHeading').hide();
	}
	
	if ($('[data-redirect]').length > 0) {
		console.log('Redirect to ' + $($('[data-redirect]')[0]).attr('data-redirect'));
		window.location.href = $('[data-redirect]').attr('data-redirect');
	}
	
	// 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()*4);
			
			for (var c = 0; c < chapterCount; c++) {
				var wordCount = 5 + Math.floor(kk_random()*25);
				outText += '<p>';
				for (var w = 0; w < wordCount; w++) {
					outText += '<span style="margin: 0.1em; background-color: black; color: black; display: inline-block; transform: rotate('+(1.5-kk_random()*3)+'deg);">' + kk_random_word() + '</span> ';
				}
				outText += '</p>';
			}
			
			$(this).append(outText);
			
		});
	}
	
	// drink stars
	if ($('[data-drink-stars]').length > 0) {
		$('[data-drink-stars]').each(function(){
			var starCount = parseInt($(this).attr('data-drink-stars'));
			var starsOut = [];
			for (var i = 0; i < starsCount; i++) starsOut.push('<span class="x-drink-star">★</span>');
			$(this).text(starsOut.join(''));
		});
	}
	
});


/*
 * 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');
                var itemHover = $(this).attr('data-hover');
                
                if (itemHover.split(':').length > 1) {
                	var pts = itemHover.split(':');
                	itemHover = pts[0];
                	$(this).append($('<span class="x-amount"></span>').text(pts[1]));
                	$(this).attr('data-hover', itemHover);
                }
                
                if (itemImage != '') {
                	if (itemImage.split(';').length == 0) {
                		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 {
                		
                		var itemImages = itemImage.split(';');
						$(this).attr('data-animate-images', itemImages.join(';'));
						$(this).attr('data-animate-pointer', '0');
						
						var currentImage = itemImages[0];
						
						if (currentImage.indexOf('item:') == 0) {
			                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + currentImage.substr(5) + '.png")');
			            } else {
			                $(this).css('background-image', 'url("' + currentImage + '")');
			            }
			            
                	}
                } 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.xeno.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);
            
            
            if ($('[data-animate-images]').length > 0) {
            	var __updateAnimations = function(){
            		$('[data-animate-images]').each(function(){
            			
            			var _i = parseInt($(this).attr('data-animate-pointer'));
            			var _imgs = $(this).attr('data-animate-images').split(';');
            			
            			var currentImage = _imgs[_i];
            			if (currentImage.indexOf('item:') == 0) {
			                $(this).css('background-image', 'url("https://static.lehtodigital.fi/xeno/textures/generic/' + currentImage.substr(5) + '.png")');
			            } else {
			                $(this).css('background-image', 'url("' + currentImage + '")');
			            }
            			
            			_i++;
            			if (_i >= _imgs.length) _i = 0;
            			$(this).attr('data-animate-pointer', ''+_i);
            			
            		});
            	};
            	setInterval(__updateAnimations, 2500);
            	__updateAnimations();
            }
            
        }
        
        
        
        if ($('[data-kk-audio]').length > 0) {
        	$('[data-kk-audio]').each(function(){
        		$(this).replaceWith(
        			$('<audio></audio>')
        				.attr('src', $(this).attr('data-kk-audio'))
        				.attr('controls', 'true')
    			);
        	});
        }
        
    });