<commit_before>/*!
 * Wikichan: JavaScript
 * Used globally on http://wiki-chan.net
 * Refer to each section for license and author
 */

// On Document Ready ------------------------------

$(function() {

	// Activate main functions
	smoothScroll();
	scrollToTop();
	resizeToc();
	wikiTip();

	// Make all <pre> having "selectble" class easily selectable
	var selectable = document.getElementsByTagName("selectable");

	for ( var i = 0, j = selectable.length; i < j; i++ ) {
		var input = document.createElement("input");

		input.type = "button";
		input.value = "선택";
		input.addEventListener("click", function() {
			selectCode(input);
			return false;
		});

		selectable[i].insertBefore( input, selectable.firstChild );
	}

});

// MAIN FUNCTIONS ------------------------------

/**
 * Smooth Scroll
 * Author: 카페인러브
 * License: MIT and GPL licenses
 */
function smoothScroll() {
	// store related DOM elements into variable
	var $root = $("html, body");
	var $anchors = $("a[href^='#']");

	// add scroll event to all anchors
	$anchors.on("click", function(e) {

		e.preventDefault();

		var href = this.hash;

		// Change URL hash without page jump
		// Author: <NAME>, 2011
		// http://lea.verou.me/2011/05/change-url-hash-without-page-jump/
		if (history.pushState) {
			history.pushState(null, null, href);
		} else {
			location.hash = href;
		}
		// end

		$root.animate({
			scrollTop: $(document.getElementById( href.substr(1) )).offset().top
		}, 300);

	});
}

/**
 * Scroll To Top
 * Author: 카페인러브
 * License: MIT and GPL licenses
 */
function scrollToTop() {
	// if ( mw.config.get("wgNamespaceNumber") === 2 ) return;

	// Create ↑ button and append it to body
	var toTop = document.createElement("a");

	toTop.id = "toTop";
	toTop.appendChild( document.createTextNode("↑") );

	document.body.appendChild(toTop);

	// Toggle ↑ button on page scroll
	$(window).on("scroll", function() {
		if($(this).scrollTop() > 400) {
			$('#toTop').fadeIn();
		} else {
			$('#toTop').fadeOut();
		}
	});

	// Scroll to topmost position when user clicks on ↑ button
	var $root = $("body, html");

	$('#toTop').on("click", function() {
		$root.animate({ scrollTop: 0 }, 100);
	});
}

/**
 * Resize Table of Contents
 * Author: 카페인러브
 * License: MIT and GPL licenses
 */
function resizeToc(){
	if ( !$("#toc") ) return;

	var $toc = $("#toc");
	var windowHeight = window.innerHeight;
	
	if ( $toc.outerHeight() + 67 > windowHeight ) {
		$toc.children('ul').height( windowHeight - 105 );
	}
}

/**
 * Tooltip
 * Author: vertigo-project (vtip)
 * Arranged by: 카페인러브
 * License: MIT and GPL licenses
 */
function wikiTip() {
	var $targets = $(".tooltip");

	$targets.on("mouseenter", function() {
		$targets.find("a").removeAttr("title");

		this.t = this.title;
		this.title = "";

		var $offsets = $(this).offset();
		var $containerWidth = $(this).width();

		if ( $(this).is("[title]") ) {
 			$("body").append(
 				"<div id='tooltip'><div class='tooltip-arrow'></div><div class='tooltip-inner'>" + this.t + "</div></div>"
 			);
		}

		var $tipWidth = $("#tooltip").width();
		var $tipHeight = $("#tooltip").height();

		$("#tooltip")
			.css({
				"top": $offsets.top - ( $tipHeight + 6 ),
				"left": $offsets.left - ( $tipWidth - $containerWidth ) /2,
			})
			.fadeIn("fast");
	});

	$targets.on("mouseleave", function() {
		this.title = this.t;
		$("#tooltip").remove();
	});
}

/******************************
*	Select text in pre
*	Author: unknown
******************************/
function selectCode(trigger) {
	var e = trigger.parentNode.getElementsByTagName("pre")[0];

	if (window.getSelection) {
		var s = window.getSelection();
		if (s.setBaseAndExtent) {
			s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);<commit_msg>Fix unlikely but possible XSS in modern-skylight.js<commit_after>/*!
 * Wikichan: JavaScript
 * Used globally on http://wiki-chan.net
 * Refer to each section for license and author
 */

// On Document Ready ------------------------------

$(function() {

	// Activate main functions
	smoothScroll();
	scrollToTop();
	resizeToc();
	wikiTip();

	// Make all <pre> having "selectble" class easily selectable
	var selectable = document.getElementsByTagName("selectable");

	for ( var i = 0, j = selectable.length; i < j; i++ ) {
		var input = document.createElement("input");

		input.type = "button";
		input.value = "선택";
		input.addEventListener("click", function() {
			selectCode(input);
			return false;
		});

		selectable[i].insertBefore( input, selectable.firstChild );
	}

});

// MAIN FUNCTIONS ------------------------------

/**
 * Smooth Scroll
 * Author: 카페인러브
 * License: MIT and GPL licenses
 */
function smoothScroll() {
	// store related DOM elements into variable
	var $root = $("html, body");
	var $anchors = $("a[href^='#']");

	// add scroll event to all anchors
	$anchors.on("click", function(e) {

		e.preventDefault();

		var href = this.hash;

		// Change URL hash without page jump
		// Author: <NAME>, 2011
		// http://lea.verou.me/2011/05/change-url-hash-without-page-jump/
		if (history.pushState) {
			history.pushState(null, null, href);
		} else {
			location.hash = href;
		}
		// end

		$root.animate({
			scrollTop: $(document.getElementById( href.substr(1) )).offset().top
		}, 300);

	});
}

/**
 * Scroll To Top
 * Author: 카페인러브
 * License: MIT and GPL licenses
 */
function scrollToTop() {
	// if ( mw.config.get("wgNamespaceNumber") === 2 ) return;

	// Create ↑ button and append it to body
	var toTop = document.createElement("a");

	toTop.id = "toTop";
	toTop.appendChild( document.createTextNode("↑") );

	document.body.appendChild(toTop);

	// Toggle ↑ button on page scroll
	$(window).on("scroll", function() {
		if($(this).scrollTop() > 400) {
			$('#toTop').fadeIn();
		} else {
			$('#toTop').fadeOut();
		}
	});

	// Scroll to topmost position when user clicks on ↑ button
	var $root = $("body, html");

	$('#toTop').on("click", function() {
		$root.animate({ scrollTop: 0 }, 100);
	});
}

/**
 * Resize Table of Contents
 * Author: 카페인러브
 * License: MIT and GPL licenses
 */
function resizeToc(){
	if ( !$("#toc") ) return;

	var $toc = $("#toc");
	var windowHeight = window.innerHeight;
	
	if ( $toc.outerHeight() + 67 > windowHeight ) {
		$toc.children('ul').height( windowHeight - 105 );
	}
}

/**
 * Tooltip
 * Author: vertigo-project (vtip)
 * Arranged by: 카페인러브
 * License: MIT and GPL licenses
 */
function wikiTip() {
	var $targets = $(".tooltip");

	$targets.on("mouseenter", function() {
		$targets.find("a").removeAttr("title");

		this.t = this.title;
		this.title = "";

		var $offsets = $(this).offset();
		var $containerWidth = $(this).width();

		if ( $(this).is("[title]") ) {
			$("body").append(
				$("<div id='tooltip'><div class='tooltip-arrow'></div></div>").append(
					$("<div class='tooltip-inner'></div>").text( this.t )
				)
			);
		}

		var $tipWidth = $("#tooltip").width();
		var $tipHeight = $("#tooltip").height();

		$("#tooltip")
			.css({
				"top": $offsets.top - ( $tipHeight + 6 ),
				"left": $offsets.left - ( $tipWidth - $containerWidth ) /2,
			})
			.fadeIn("fast");
	});

	$targets.on("mouseleave", function() {
		this.title = this.t;
		$("#tooltip").remove();
	});
}

/******************************
*	Select text in pre
*	Author: unknown
******************************/
function selectCode(trigger) {
	var e = trigger.parentNode.getElementsByTagName("pre")[0];

	if (window.getSelection) {
		var s = window.getSelection();
		if (s.setBaseAndExtent) {
			s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
{'fraction_non_alphanumeric': 0.21998409753511794, 'fraction_numerical': 0.008746355685131196, 'mean_word_length': 3.324928366762178, 'pattern_counts': {'":': 4, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2857974', 'n_tokens_mistral': 2829, 'n_tokens_neox': 2591, 'n_words': 609}