vanilla-lib

Vanilla JS library

12.06.2018 itibariyledir. En son verisyonu görün.

Bu script direkt olarak kurulamaz. Başka scriptler için bir kütüphanedir ve meta yönergeleri içerir // @require https://update.greasyfork.org/scripts/369430/604970/vanilla-lib.js

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

/* vanilla-lib */
var  mapFlat = ( array,func ) => array.map( x => func(x) ).reduce( (a,b) => a.concat(b) ),
     parenth = ( elem,nth ) => traverse(elem, ifndef(nth, 1), 0), //( ! elem ? null : elem.parentNode ),
     ifndef  = ( expr,value ) => ( ndef(expr) ? value : expr ),
     ifnan   = ( expr,value ) => ( isNaN(expr) ? value : expr ),
     isarr   = expr => ( 'object' === typeof expr && Array === expr.constructor ),
     isfn    = expr => ( 'function' === typeof expr ),
     ndef    = expr => ( 'undefined' === typeof expr ),
     test    = ( expr,func,other ) => ( !! expr ? func(expr) : isfn(other) ? other(expr) : other ),
     log     = console.debug,
     on      = ( elem,event,func ) => elem.addEventListener(event, func),
     $$      = ( sel,elem ) => Array.slice((elem || document).querySelectorAll(sel)),
     $       = ( sel,elem ) => (elem || document).querySelector(sel);

var  aggrate = ( amount,rate,periods ) => ( ! periods ? amount : aggrate(amount * rate, rate, periods - 1) ),
     toDec   = expr => ( Math.round(parseFloat((expr +'').replace(/\$|,/g, '')) * 100) / 100 ),
     toMny   = amount => ( (segs => isNaN(segs[ 0 ]) ? null : '$ '+ segs[ 0 ] +'.'+ ((segs[ 1 ] || 0) +'00').slice(0, 2)) ((toDec(amount) +'').split('.')) );

//Array.prototype.mapFlat = function( func ) { return  mapFlat(this, func); };

function  adopt( elem, sibling, position ) {
	let  wrap = parenth(elem);
	// Look for the reference point (for 'insertBefore' function); null = use 'append' instead
	elem = ( position < 0 ? traverse(elem, 0, position, true) : traverse(elem, 0, (position || 0) + 1, false) );
	if ( ! elem ) {
		wrap.append(sibling);
	} else {
		wrap.insertBefore(sibling, elem);
	}
	// Return the element added
	return  sibling;
}

function  attr( elem, name, value ) {
	if ( isarr(elem) ) {
		return  elem.map( el => attr(el, name, value) );
	}

	if ( null === value ) {
		elem.removeAttribute(name);
	} else {
		elem.setAttribute(name, value);
	}
	return  elem;
}

function  create( html, containerType ) {
	let  container = null,
	     result    = null;
	containerType = containerType || 'div';
	create[ containerType ] = 
	container               = create[ containerType ] || document.createElement(containerType);
	container.innerHTML = html;
	result = Array.slice(container.childNodes)
	         	.map( elem => (elem.remove(), elem) );
	if ( 1 == result.length ) {
		result = result[ 0 ];
	}
	return  result;
}

function  traverse( elem, up, sideways, elementsOnly, lastIfNull ) {
	let  last = elem;
	while ( !! elem && up -- > 0 )  elem = (last = elem, parenth(elem));

	let  prop = ( elementsOnly ? 'Element' : '' ) +'Sibling';
	if ( sideways < 0 ) {
		while ( !! elem && sideways ++ < 0 )  elem = (last = elem, elem[ 'previous'+ prop ]);
	} else if ( sideways > 0 ) {
		while ( !! elem && sideways -- > 0 )  elem = (last = elem, elem[ 'next'+ prop ]);
	}

	return  ( ! lastIfNull ? elem : elem || last );
}