View file modules/pwa/assets/js/app.js

File size: 38.73Kb
if ('serviceWorker' in navigator) {
	window.addEventListener('load', () => {
		navigator.serviceWorker.register('sw.js')
		.then(() => console.log('ServiceWorker registration successful'))
		.catch(error => console.log(error))
	})
} else {
	console.log('ServiceWorker is not supported')
}

$(document).ready(() => {
	const route = new URLSearchParams(window.location.search);
	const $root = $('#root');
	const $upload = $('#fileInput');
	const $search = $('#searchInput');
	const $searchBtn = $('.search-btn');
	const limit = 10;
	let offsetFiles = 0;
	let offsetSearch = 0;
	let offsetComms = 0;

	const warning = (message, type = 'info') => {
		$('body').append(`<div class="alert ${type}">${message}</div>`),
		$('.alert').fadeIn(800).fadeOut(3000),
		setTimeout(() => {
			$('.alert').remove()
		}, 3500)
	};

	const validate = (extension) => {
		const extensions = ['jpg', 'gif', 'png', 'jpeg', 'bmp', 'ico', 'svg', 'psd', 'eps', 'ai', 'xd', 'sketch', 'zip', 'rar', 'mp3', 'ogg', 'wav', 'avi', 'mp4', 'webm', '3gp', 'jar', 'apk', 'doc', 'docx', 'txt', 'ttf', 'pptx', 'torrent'];
		return extensions.indexOf(extension) > -1
	};

	const timeFormat = (timestamp) => {
		const d = new Date();
		const t = new Date(timestamp * 1000);

		const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

		const curYear = d.getFullYear();
		const curMonth = months[d.getMonth()];
		const curDate = d.getDate();

		const year = t.getFullYear();
		const month = months[t.getMonth()];
		const date = t.getDate();
		const hour = t.getHours();
		const min = t.getMinutes() < 10 ? `0${t.getMinutes()}` : t.getMinutes();

		let thisYear;
		year !== curYear ? thisYear = ` ${year}` : thisYear = '';

		if (`${date}.${month}.${year}` === `${curDate}.${curMonth}.${curYear}`) {
			return `today at ${hour}:${min}`
		} else if (`${date}.${month}.${year}` === `${curDate - 1}.${curMonth}.${curYear}`) {
			return `yesterday at ${hour}:${min}`
		} else {
			return `${date} ${month}${thisYear} at ${hour}:${min}`
		}
	};

	const counter = (count) => {
		if (count === 0) return '';
		if (count < 1e3) return count;
		if (count >= 1e3 && count < 1e6) return `${+(count / 1e3).toFixed(1)}K`;
		if (count >= 1e6 && count < 1e9) return `${+(count / 1e6).toFixed(1)}M`;
		if (count >= 1e9 && count < 1e12) return `${+(count / 1e9).toFixed(1)}B`;
	};

	const copy = (text) => {
		navigator.clipboard.writeText(text)
		.then(() => warning('File link copied to the clipboard.'))
		.catch(error => warning('Could not copy text.', 'error'))
	};

	const template = {
		ic_logo: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 400 400"><path d="M163.8332634935379,3.9212235822677615 C141.8792634935379,8.412223582267762 126.2062634935379,21.126223582267762 116.82326349353791,42.055223582267764 C112.5072634935379,51.683223582267765 110.7742634935379,68.51822358226777 113.07626349353791,78.45822358226776 C113.4852634935379,80.22422358226775 113.9762634935379,82.34422358226776 114.1682634935379,83.16922358226776 C115.5592634935379,89.16222358226776 120.67926349353792,99.33122358226777 125.42226349353791,105.51922358226776 C129.6962634935379,111.09522358226776 140.8132634935379,120.85622358226776 142.8912634935379,120.85622358226776 C146.2572634935379,122.99722358226776 147.6542634935379,123.55322358226776 149.0642634935379,124.23222358226776 C153.01226349353792,126.13322358226776 157.5502634935379,127.58522358226776 163.28026349353792,128.78222358226776 C171.0252634935379,131.09622358226775 172.5262634935379,131.69322358226776 173.4692634935379,131.98822358226775 C194.4612634935379,138.57422358226776 215.1242634935379,163.04022358226777 218.8662634935379,185.73822358226775 C219.2962634935379,188.34822358226776 219.4592634935379,189.36922358226775 219.8912634935379,192.16222358226776 C220.1102634935379,193.57622358226777 220.2192634935379,198.10522358226777 220.1332634935379,202.22722358226775 C219.9482634935379,211.14122358226777 218.7042634935379,218.15222358226777 216.2942634935379,223.85422358226776 C215.9962634935379,224.56122358226776 215.4902634935379,225.91022358226775 215.1712634935379,226.85222358226775 C214.3852634935379,229.17122358226777 209.9602634935379,237.78222358226776 208.4902634935379,239.85322358226776 C207.8362634935379,240.77322358226778 207.0132634935379,241.95222358226775 206.6592634935379,242.47322358226776 C206.3062634935379,242.99422358226775 205.7162634935379,243.77522358226776 205.3482634935379,244.20922358226775 C204.9802634935379,244.64422358226776 204.3052634935379,245.52722358226777 203.8492634935379,246.17222358226775 C202.4522634935379,248.14622358226777 194.7792634935379,255.65022358226776 192.1882634935379,257.57522358226777 C185.2662634935379,262.46222358226777 183.4792634935379,263.4712235822678 178.3942634935379,266.06822358226776 C170.4792634935379,269.29022358226774 168.9832634935379,269.7072235822678 167.6872634935379,270.0892235822678 C165.1772634935379,270.83022358226776 164.2522634935379,271.0652235822678 162.54826349353792,271.39122358226774 C160.1502634935379,271.8582235822678 158.7042634935379,272.08122358226774 157.4092634935379,272.26122358226775 C156.11326349353791,272.44122358226775 154.5712634935379,272.65522358226775 153.9832634935379,272.73722358226775 C152.5852634935379,272.93222358226774 142.92926349353792,272.91722358226775 139.6362634935379,272.71522358226775 C138.2222634935379,272.62822358226776 134.6572634935379,272.0262235822678 131.7132634935379,271.37822358226776 C102.0692634935379,264.85022358226774 69.49926349353791,282.64522358226776 59.5722634935379,310.79222358226775 C56.3012634935379,318.5292235822678 54.7922634935379,333.25422358226774 55.68926349353791,340.55622358226776 C55.877263493537896,342.08722358226777 56.087263493537904,343.8222235822678 56.1552634935379,344.4112235822678 C56.337263493537904,345.9882235822678 57.6162634935379,351.34322358226774 58.04726349353791,352.3342235822678 C58.252263493537896,352.8052235822678 58.650263493537906,353.96122358226773 58.9322634935379,354.90322358226774 C61.9262634935379,364.90222358226777 71.3742634935379,377.64322358226775 81.2202634935379,384.95822358226775 C85.05239691887186,387.8055629429907 91.6066244281834,391.53068964706534 94.38025903293986,392.54221143110016 C95.70441329706534,393.02143593883875 96.09956404148267,393.24170050747193 96.59295228710144,393.4627625411463 C100.87114526815637,395.37960196576034 112.53552784521916,397.35640044794246 119.3532634935379,397.27122358226774 C125.8852634935379,397.1902235822678 126.8672634935379,397.1012235822678 131.1662634935379,396.21022358226776 C149.2732634935379,391.04522358226774 161.7762634935379,382.30822358226783 168.1882634935379,374.07622358226774 C171.5412634935379,369.8222235822678 172.2852634935379,368.61722358226774 173.1942634935379,367.24622358226776 C176.8392634935379,360.3772235822678 177.2052634935379,359.56122358226776 177.4442634935379,358.97222358226776 C177.6832634935379,358.38322358226776 178.1872634935379,357.1972235822678 178.5642634935379,356.33722358226777 C179.7652634935379,353.25422358226774 180.4502634935379,350.55622358226776 181.1042634935379,347.33622358226773 C181.7582634935379,344.11622358226776 182.6682634935379,340.7042235822678 183.1272634935379,339.7552235822678 C183.9612634935379,336.55722358226774 189.0232634935379,326.00322358226776 190.62526349353791,323.6422235822678 C192.6292634935379,320.5532235822678 193.6412634935379,319.22722358226775 194.5372634935379,318.02022358226776 C205.2812634935379,303.5582235822678 223.5252634935379,292.49222358226774 240.4922634935379,290.14622358226774 C248.30126349353793,288.78822358226773 262.6742634935379,289.39322358226775 268.1152634935379,290.6202235822678 C275.2962634935379,292.2402235822678 285.7382634935379,292.4542235822678 292.4982634935379,291.11922358226775 C298.3042634935379,289.97422358226777 304.6502634935379,287.79922358226776 309.5502634935379,285.27522358226776 C315.7952634935379,282.31222358226773 322.7752634935379,276.71222358226777 326.6992634935379,272.67622358226777 C332.5722634935379,266.6372235822678 336.7622634935379,260.1422235822678 340.51526349353793,251.26322358226776 C341.7332634935379,248.38022358226777 344.4252634935379,236.99122358226776 344.4882634935379,234.45422358226776 C344.7852634935379,222.41422358226777 344.2922634935379,217.65922358226777 341.9212634935379,209.72122358226775 C340.7112634935379,205.66722358226775 337.9942634935379,199.66722358226775 335.6202634935379,195.80322358226775 C333.7392634935379,192.80522358226776 333.24126349353793,192.17822358226775 332.78926349353793,191.41322358226776 C329.0052634935379,185.00622358226775 317.4222634935379,175.25722358226776 308.7242634935379,171.15822358226777 C302.1932634935379,168.08022358226776 301.30126349353793,167.78122358226776 293.8112634935379,166.15622358226776 C290.5142634935379,165.44122358226775 287.7192634935379,164.73522358226776 287.6012634935379,164.58822358226777 C283.7812634935379,163.13922358226776 283.6252634935379,163.07522358226777 279.0362634935379,161.05422358226775 C277.2702634935379,160.27622358226776 275.7282634935379,159.53722358226776 275.6102634935379,159.41222358226776 C271.4642634935379,157.19422358226777 270.1152634935379,156.42322358226775 269.8612634935379,156.18622358226776 C265.7492634935379,153.27122358226777 263.9802634935379,151.92322358226775 263.1142634935379,151.15722358226776 C262.2482634935379,150.39122358226777 260.7232634935379,149.09422358226777 259.7262634935379,148.27522358226776 C252.53626349353794,142.37022358226776 242.0892634935379,126.17822358226776 240.2392634935379,118.07222358226777 C239.2432634935379,115.84722358226776 238.6402634935379,113.30822358226776 237.48826349353791,107.36622358226776 C235.9852634935379,99.61822358226776 236.1352634935379,87.67022358226777 237.8362634935379,79.52922358226776 C238.5252634935379,76.23122358226776 239.1032634935379,73.05122358226777 239.1222634935379,72.46222358226777 C238.9672634935379,59.357223582267764 238.75626349353792,58.00822358226776 238.5922634935379,56.83022358226776 C238.0662634935379,53.03222358226776 236.5512634935379,47.04122358226776 235.53026349353792,44.723223582267764 C233.1932634935379,37.17522358226776 225.5892634935379,25.88922358226776 219.9632634935379,20.64222358226776 C213.9322634935379,15.01722358226776 204.8282634935379,9.138223582267761 198.7362634935379,6.936223582267761 C186.86326349353791,2.643223582267761 175.0592634935379,1.6242235822677618 163.8332634935379,3.9212235822677615 M292.0592634935379,180.87022358226776 C302.3812634935379,183.00722358226776 310.6272634935379,187.52422358226775 317.8962634935379,195.02322358226778 L319.7112634935379,196.89522358226776 L307.7912634935379,208.79322358226776 L304.7732634935379,206.11722358226777 C288.2692634935379,191.48522358226776 264.6382634935379,193.79722358226775 253.5602634935379,211.12922358226777 C241.7692634935379,229.57522358226777 252.7082634935379,255.00622358226775 274.3252634935379,259.40322358226774 C284.7222634935379,261.51822358226775 296.6022634935379,258.62322358226777 301.9882634935379,252.66222358226776 L303.4472634935379,251.04622358226777 L303.4472634935379,245.90822358226777 L303.4472634935379,240.77022358226776 L300.66426349353793,240.77022358226776 C297.40226349353793,240.77022358226776 297.3602634935379,240.67222358226775 299.5442634935379,238.17622358226777 C308.9682634935379,227.31222358226776 311.3812634935379,224.71122358226776 311.5782634935379,224.71122358226776 C312.1302634935379,224.71122358226776 325.25326349353793,239.62422358226777 325.2722634935379,240.27322358226778 C325.27605606387914,240.39954534825011 325.2253782350025,240.49795103463325 325.1035196417359,240.57124639366745 L320.1482634935379,240.55622358226776 L320.1492634935379,249.27122358226777 L320.1502634935379,257.98522358226774 L315.9742634935379,262.13822358226776 C287.0982634935379,290.8582235822678 238.6572634935379,275.87322358226777 232.3252634935379,236.26222358226775 C226.7142634935379,201.15522358226775 256.5252634935379,173.51122358226777 292.0592634935379,180.87022358226776" fill="${color}"/></svg>`;
		},
		ic_back: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z" fill="${color}"/></svg>`;
		},
		ic_user: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zM7.07 18.28c.43-.9 3.05-1.78 4.93-1.78s4.51.88 4.93 1.78C15.57 19.36 13.86 20 12 20s-3.57-.64-4.93-1.72zm11.29-1.45c-1.43-1.74-4.9-2.33-6.36-2.33s-4.93.59-6.36 2.33C4.62 15.49 4 13.82 4 12c0-4.41 3.59-8 8-8s8 3.59 8 8c0 1.82-.62 3.49-1.64 4.83zM12 6c-1.94 0-3.5 1.56-3.5 3.5S10.06 13 12 13s3.5-1.56 3.5-3.5S13.94 6 12 6zm0 5c-.83 0-1.5-.67-1.5-1.5S11.17 8 12 8s1.5.67 1.5 1.5S12.83 11 12 11z" fill="${color}"/></svg>`;
		},
		ic_load: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" fill="${color}"/><path d="M0 0h24v24H0z" fill="none"/></svg>`;
		},
		ic_like: (size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0zm0 0h24v24H0V0z"/><path d="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.58 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h4v12H1z"/></svg>`;
		},
		ic_comments: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path d="M21.99 4c0-1.1-.89-2-1.99-2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14l4 4-.01-18zM18 14H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z" fill="${color}"/></svg>`
		},
		ic_views: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="${color}"/></svg>`;
		},
		ic_search: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="${color}"/><path d="M0 0h24v24H0z" fill="none"/></svg>`;
		},
		ic_info: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"/><path d="M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" fill="${color}"/></svg>`;
		},
		ic_send: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" fill="${color}"/></svg>`;
		},
		ic_play: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24"><path d="M8 5v14l11-7z" fill="${color}"/></svg>`;
		},
		loader: (color = '#fff', size = 24) => {
			return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="lds-rolling" style="background: none;"><circle cx="50" cy="50" fill="none" stroke="${color}" stroke-width="10" r="35" stroke-dasharray="164.93361431346415 56.97787143782138" transform="rotate(84.8958 50 50)"><animateTransform attributeName="transform" type="rotate" calcMode="linear" values="0 50 50;360 50 50" keyTimes="0;1" dur="1.2s" begin="0s" repeatCount="indefinite"></animateTransform></circle></svg>`;
		},
		progress: () => {
			return `<div id="loader" class="progress"></div>`;
		},
		loadBtn: (id, type, content = template.loader()) => {
			return `
				<div class="x-center ${type}">
					<div id="${id}" class="actions primary-btn">${content}</div>
				</div>
			`;
		},
		error: (message, icon = template.ic_info('#546e7a', 112)) => {
			return `
				<div class="empty-results">
					${icon}
					<div class="empty_words">
						<div class="empty_top">${message}</div>
					</div>
				</div>
			`;
		},
		preview: (author, time, name, file, format) => {
			return `
				<div class="file_top">
					<span class="file_author">${template.ic_user('#8E9399', 20)}${author}</span>
					<span class="file_date">${timeFormat(time)}</span>
				</div>
				<span class="file_name">${name}</span>
				${format === 'jpeg' || format === 'jpg' || format === 'png' || format === 'ico' || format === 'bmp' || format === 'svg' ? `
				<div class="file_image">
					<img src="${file}" alt="">
				</div>` : ''}
				${format === 'gif' ? `
				<div class="file_image gif">
					<div class="gif_play">
						<span class="gif_btn">${template.ic_play()}</span>
					</div>
					<img class="gifview" src="https://goload.tk/modules/viewer/gif.php?image=${file.split("/").pop()}" data-src="${file}" data-file="https://goload.tk/modules/viewer/gif.php?image=${file.split("/").pop()}" alt="">
				</div>` : ''}
				${format === 'mp4' || format === 'webm' || format === '3gp' ? `
				<div class="file_video">
					<video src="${file}" poster="https://goload.tk/modules/viewer/video.php?file=${file.split("/").pop()}" controls></video>
				</div>` : ''}
				${format === 'mp3' || format === 'ogg' ? `
				<div class="file_video">
					<audio src="${file}" controls></audio>
				</div>` : ''}
			`;
		},
		view: (id, url, author, time, name, file, load, like, views, comments, format) => {
			return `
				<div class="file" data-id="${id}">
					<a href="?file=${id}" class="file_block">
						${template.preview(author, time, name, file, format)}
					</a>
					<div class="file_info">
						<span class="like ${localStorage.getItem(`like${id}`) === 'true' ? `clicked` : ''}">${template.ic_like(18)}<u class="like_count">${counter(like)}</u></span>
						<span>${template.ic_comments('#8E9399', 18)}${counter(comments)}</span>
						<span>${template.ic_load('#8E9399', 18)}${counter(load)}</span>
						<span>${template.ic_views('#8E9399', 18)}${counter(views)}</span>
					</div>
				</div>
			`;
		},
		file: (id, url, author, time, name, file, text, load, like, views, comments, format) => {
			return `
				<div class="file info" data-id="${id}">
					<a class="file_block here">
						${template.preview(author, time, name, file, format)}
					</a>

					${text ? `<div class="block">${text}</div>` : ''}

					<div class="file_info">
						<span class="like ${localStorage.getItem(`like${id}`) === 'true' ? `clicked` : ''}">${template.ic_like(18)}<u class="like_count">${counter(like)}</u></span>
						<span>${template.ic_comments('#8E9399', 18)}${counter(comments)}</span>
						<span>${template.ic_load('#8E9399', 18)}${counter(load)}</span>
						<span>${template.ic_views('#8E9399', 18)}${counter(views)}</span>
					</div>
				</div>

				${template.share(id, name)}

				<div class="x-center loadFile">
					<a href="https://goload.tk/up${id}" id="download" class="actions primary-btn clickable" download>Download file</a>
				</div>

				<div class="comm_inner">
					<div class="comm_title">Comments</div>
					<div class="comments"></div>
					${template.loadBtn('moreComms', 'loadComms')}
				</div>

				<div class="commentForm">
					${!localStorage.getItem('username') ? `
					<input type="text" id="nameInput" placeholder="Name">` : `
					<div class="user">${localStorage.getItem('username').slice(0, 1)}</div>
					`}
					<input type="text" id="textInput" placeholder="Add a comment...">
					<span id="write" class="write">${template.ic_send('#8E9399', 20)}</span>
				</div>
			`;
		},
		comment: (id, file, author, userPhoto, text, like, time) => {
			return `
				<div class="comment" data-id="${id}">
					<div class="comm_left">

						${userPhoto ? `<div class="letter" style="background-image: url('${userPhoto}');"></div>` : `<div class="letter">${author.slice(0, 1)}</div>`}

					</div>
					<div class="comm_right">
						<span class="comm_author">${author}</span>
						<span class="comm_text">${text}</span>
						<span class="comm_time">${timeFormat(time)}</span>
					</div>
					<div class="comm_like ${localStorage.getItem(`likeComm${id}`) === 'true' ? `clicked` : ''}">${template.ic_like(16)}<u class="comm_like_count">${counter(like)}</u></div>
				</div>
			`;
		},
		share: (id, name) => {
			return `
				<div class="share file${id}">
					<span>Share file:</span>
					<ul>
					${'clipboard' in navigator && `
						<li>
							<a class="copylink clickable">
								<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>
							</a>
						</li>`}
						<li>
							<a class="twitter clickable" target="_blank" href="https://twitter.com/intent/tweet?text=Download file - ${name}&amp;url=https://goload.tk/file${id}%3Futm_source=twitter%26utm_medium=social&amp;hashtags=goload">
								<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M23.954 4.569c-.885.389-1.83.654-2.825.775 1.014-.611 1.794-1.574 2.163-2.723-.951.555-2.005.959-3.127 1.184-.896-.959-2.173-1.559-3.591-1.559-2.717 0-4.92 2.203-4.92 4.917 0 .39.045.765.127 1.124C7.691 8.094 4.066 6.13 1.64 3.161c-.427.722-.666 1.561-.666 2.475 0 1.71.87 3.213 2.188 4.096-.807-.026-1.566-.248-2.228-.616v.061c0 2.385 1.693 4.374 3.946 4.827-.413.111-.849.171-1.296.171-.314 0-.615-.03-.916-.086.631 1.953 2.445 3.377 4.604 3.417-1.68 1.319-3.809 2.105-6.102 2.105-.39 0-.779-.023-1.17-.067 2.189 1.394 4.768 2.209 7.557 2.209 9.054 0 13.999-7.496 13.999-13.986 0-.209 0-.42-.015-.63.961-.689 1.8-1.56 2.46-2.548l-.047-.02z"/></svg>
							</a>
						</li>
						<li>
							<a class="telegram clickable" target="_blank" href="https://t.me/share/url?url=https://goload.tk/file${id}%3Futm_source=telegram%26utm_medium=messenger&amp;text=Download file - ${name}">
								<svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.028 20.837c-.714 0-.593-.271-.839-.949l-2.103-6.92L22.263 3.37"></path><path d="M9.028 20.837c.552 0 .795-.252 1.105-.553l2.941-2.857-3.671-2.214"></path><path d="M9.403 15.213l8.89 6.568c1.015.56 1.748.271 2-.942l3.62-17.053c.372-1.487-.564-2.159-1.534-1.72L1.125 10.263c-1.45.582-1.443 1.392-.264 1.753l5.455 1.7L18.94 5.753c.595-.36 1.143-.167.694.232"/></svg>
							</a>
						</li>
						<li>
							<a class="vk clickable" target="_blank" href="https://vk.com/share.php?url=https://goload.tk/file${id}%3Futm_source=vkontakte%26utm_medium=social&amp;title=Download file - ${name}">
								<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M11.701 18.771h1.437s.433-.047.654-.284c.21-.221.21-.63.21-.63s-.031-1.927.869-2.21c.887-.281 2.012 1.86 3.211 2.683.916.629 1.605.494 1.605.494l3.211-.044s1.682-.105.887-1.426c-.061-.105-.451-.975-2.371-2.76-2.012-1.861-1.742-1.561.676-4.787 1.469-1.965 2.07-3.166 1.875-3.676-.166-.48-1.26-.361-1.26-.361l-3.602.031s-.27-.031-.465.09c-.195.119-.314.391-.314.391s-.572 1.529-1.336 2.82c-1.623 2.729-2.268 2.879-2.523 2.699-.604-.391-.449-1.58-.449-2.432 0-2.641.404-3.75-.781-4.035-.39-.091-.681-.15-1.685-.166-1.29-.014-2.378.01-2.995.311-.405.203-.72.652-.539.675.24.03.779.146 1.064.537.375.506.359 1.636.359 1.636s.211 3.116-.494 3.503c-.495.262-1.155-.28-2.595-2.756-.735-1.26-1.291-2.67-1.291-2.67s-.105-.256-.299-.406c-.227-.165-.557-.225-.557-.225l-3.435.03s-.51.016-.689.24c-.166.195-.016.615-.016.615s2.686 6.287 5.732 9.453c2.79 2.902 5.956 2.715 5.956 2.715l-.05-.055z"/></svg>
							</a>
						</li>
						<li>
							<a class="facebook clickable" target="_blank" href="https://facebook.com/sharer/sharer.php?u=https://goload.tk/file${id}%3Futm_source=facebook%26utm_medium=social&amp;title=Download file - ${name}">
								<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.21 9.25L8.21 12.06L9.93 12.06L9.93 20.3L13.24 20.3L13.24 12.02L15.54 12.02L15.79 9.25C14.26 9.25 13.41 9.25 13.24 9.25C13.24 9.25 13.24 8.22 13.24 7.67C13.24 7.02 13.37 6.76 14 6.76C14.51 6.76 15.79 6.76 15.79 6.76C15.79 6.47 15.79 4.17 15.79 3.89C15.79 3.89 13.91 3.89 13.5 3.89C11.04 3.89 9.94 4.97 9.94 7.04C9.93 8.85 9.93 9.25 9.93 9.25C9.7 9.25 9.13 9.25 8.21 9.25Z"/></svg>
							</a>
						</li>
						<li>
							<a class="reddit clickable" target="_blank" href="https://www.reddit.com/submit?url=https://goload.tk/file${id}%3Futm_source=reddit%26utm_medium=social&amp;title=Download file - ${name}">
								<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M24 11.779c0-1.459-1.192-2.645-2.657-2.645-.715 0-1.363.286-1.84.746-1.81-1.191-4.259-1.949-6.971-2.046l1.483-4.669 4.016.941-.006.058c0 1.193.975 2.163 2.174 2.163 1.198 0 2.172-.97 2.172-2.163s-.975-2.164-2.172-2.164c-.92 0-1.704.574-2.021 1.379l-4.329-1.015c-.189-.046-.381.063-.44.249l-1.654 5.207c-2.838.034-5.409.798-7.3 2.025-.474-.438-1.103-.712-1.799-.712-1.465 0-2.656 1.187-2.656 2.646 0 .97.533 1.811 1.317 2.271-.052.282-.086.567-.086.857 0 3.911 4.808 7.093 10.719 7.093s10.72-3.182 10.72-7.093c0-.274-.029-.544-.075-.81.832-.447 1.405-1.312 1.405-2.318zm-17.224 1.816c0-.868.71-1.575 1.582-1.575.872 0 1.581.707 1.581 1.575s-.709 1.574-1.581 1.574-1.582-.706-1.582-1.574zm9.061 4.669c-.797.793-2.048 1.179-3.824 1.179l-.013-.003-.013.003c-1.777 0-3.028-.386-3.824-1.179-.145-.144-.145-.379 0-.523.145-.145.381-.145.526 0 .65.647 1.729.961 3.298.961l.013.003.013-.003c1.569 0 2.648-.315 3.298-.962.145-.145.381-.144.526 0 .145.145.145.379 0 .524zm-.189-3.095c-.872 0-1.581-.706-1.581-1.574 0-.868.709-1.575 1.581-1.575s1.581.707 1.581 1.575-.709 1.574-1.581 1.574z"/></svg>
							</a>
						</li>
					</ul>
				</div>
			`;
		}
	};

	const goload = {
		files: (url, callback) => {
			$.ajax({
				type: 'GET',
				url,
				beforeSend: () => {
					$('#moreFiles').html(template.loader())
				},
				success: (data) => {
					$('#moreFiles').text('Load more'),
					callback.call(data)
				},
				error: (error) => {
					warning(error.statusText, 'error')
				}
			})
		},
		file: (url, callback) => {
			$.ajax({
				type: 'GET',
				url,
				success: (data) => {
					callback.call(data)
				},
				error: (error) => {
					warning(error.statusText, 'error')
				}
			})
		},
		like: (url, id, selector = 'like_count', target = 'like') => {
			$.get(url, (data) => {
				$(`[data-id="${id}"]`).find(`.${selector}`).text(counter(data['count'])),
				$(`[data-id="${id}"]`).find(`.${target}`).toggleClass('clicked')
			}).fail((error) => {
				warning(error.statusText, 'error')
			})
		},
		upload: (url, formData, callback) => {
			$.ajax({
				type: 'POST',
				url,
				data: formData,
				processData: false,
				contentType: false,
				beforeSend: () => {
					$upload.after(template.progress())
				},
				xhr: () => {
					const xhr = $.ajaxSettings.xhr();
					xhr.upload.onprogress = (e) => {
						e.lengthComputable && (
							$('#loader').stop(true, true).animate({
								'width': `${e.loaded / e.total * 100}%`
							}, 200, 'linear')
						)
					};
					return xhr
				},
				success: (data) => {
					$('#loader').remove(),
					callback.call(data)
				},
				error: (error) => {
					warning(error.statusText, 'error')
				}
			})
		},
		search: (url, callback) => {
			$.ajax({
				type: 'GET',
				url,
				beforeSend: () => {
					$('#moreSearch').html(template.loader())
				},
				success: (data) => {
					$('#moreSearch').text('Load more'),
					callback.call(data)
				},
				error: (error) => {
					warning(error.statusText, 'error')
				}
			})
		},
		comments: (url, callback) => {
			$.ajax({
				type: 'GET',
				url,
				beforeSend: () => {
					$('#moreComms').html(template.loader())
				},
				success: (data) => {
					$('#moreComms').text('More comments'),
					callback.call(data)
				},
				error: (error) => {
					warning(error.statusText, 'error')
				}
			})
		},
		writecomment: (url, formData, callback) => {
			$.ajax({
				type: 'POST',
				url,
				data: formData,
				processData: false,
				contentType: false,
				success: (data) => {
					callback.call(data)
				},
				error: (error) => {
					warning(error.statusText, 'error')
				}
			})
		}
	};

	// get files
	const files = () => {
		const url = `https://goload.tk/api/all.php?limit=${limit}&offset=${offsetFiles}`;

		goload.files(url, function() {
			const res = this;
			const data = res.data;
			res.success !== false ? (
				offsetFiles += limit,
				$.each(data, (i, v) => {
					$root.append(
						template.view(
							data[i].id,
							data[i].url,
							data[i].author,
							data[i].time,
							data[i].name,
							data[i].file,
							data[i].load,
							data[i].like,
							data[i].views,
							data[i].comments,
							data[i].format
						)
					),
					Object.keys(data).length < limit && $('.loadFiles').remove()
				})
			) : (
				$('.x-center').remove(),
				$root.children('div').length == 0 && (
					$root.html(
						template.error(res.data.message)
					)
				),
				warning(res.data.message, 'error')
			)
		})
	};

	// get one file
	const file = (id = route.get('file')) => {
		const url = `https://goload.tk/api/file.php?id=${id}`;

		goload.file(url, function() {
			const res = this;
			res.success !== false ? (
				$root.html(
					template.file(
						res.data.id,
						res.data.url,
						res.data.author,
						res.data.time,
						res.data.name,
						res.data.file,
						res.data.opis,
						res.data.load,
						res.data.like,
						res.data.views,
						res.data.comments,
						res.data.format
					)
				),
				$('title').text(`${res.data.name} - GOload File Sharing`),
				$('.logo').addClass('back').html(template.ic_back()),
				$('.loadFiles, .loadSearch').remove()
			) : (
				warning(res.data.message, 'error'),
				res.data.message = "File Not Found" && (
					$('.logo').addClass('back').html(template.ic_back()),
					$('.x-center').remove(),
					$root.children('div').length == 0 && (
						$root.html(
							template.error(res.data.message)
						)
					)
				)
			)
		}),
		setTimeout(() => {
			comments(id)
		}, 700)
	};

	// get comments
	const comments = (id = route.get('file')) => {
		const url = `https://goload.tk/api/comments.php?id=${id}&limit=${limit}&offset=${offsetComms}`;

		goload.comments(url, function() {
			const res = this;
			const data = res.comments;
			res.success !== false ? (
				offsetComms += limit,
				$.each(data, (i, v) => {
					$('.comments').append(
						template.comment(
							data[i].id,
							data[i].file,
							data[i].author,
							data[i].userPhoto,
							data[i].text,
							data[i].like,
							data[i].time
						)
					),
					res.count < limit && $('.loadComms').remove()
				})
			) : (
				$('.loadComms, .comm_title').remove(),
				$('.comments').children('div').length == 0 && (
					$('.comments').html(
						template.error(res.data.message)
					)
				)
			)
		})
	};

	// write comment
	const writecomment = (id = route.get('file'), author, text) => {
		const url = `https://goload.tk/api/writecomment.php`;
		const formData = new FormData;
		formData.append('id', id);
		formData.append('author', author);
		formData.append('text', text);

		goload.writecomment(url, formData, function() {
			const res = this;
			res.success ? (
				$('.comments').prepend(
					template.comment(
						res.data.id,
						res.data.file,
						res.data.author,
						res.data.userPhoto,
						res.data.text,
						res.data.like,
						res.data.time
					)
				),
				$('.comm_title').length == 0 && ($('.comments').before(`<div class="comm_title">Comments</div>`)),
				$('.empty-results').remove()
			) : (
				warning(res.data.message, 'error')
			)
		})
	};

	// search files
	const search = (keyword) => {
		const url = `https://goload.tk/api/search.php?q=${keyword}&limit=${limit}&offset=${offsetSearch}`;

		goload.search(url, function() {
			const res = this;
			const data = res.data;
			res.success !== false ? (
				offsetSearch += limit,
				$.each(data, (i, v) => {
					$root.append(
						template.view(
							data[i].id,
							data[i].url,
							data[i].author,
							data[i].time,
							data[i].name,
							data[i].file,
							data[i].load,
							data[i].like,
							data[i].views,
							data[i].comments,
							data[i].format
						)
					),
					Object.keys(data).length < limit && $('.loadSearch').remove()
				})
			) : (
				$('.x-center').remove(),
				$root.children('div').length == 0 && (
					$root.html(
						template.error(
							res.data.message,
							template.ic_search('#546e7a', 112)
						)
					)
				),
				warning(res.data.message, 'error')
			)
		})
	};

	// like file
	$(document).on('click', '.like', function() {
		const id = $(this).closest('.file').data('id');
		const action = $(this).hasClass('clicked') ? 'dislike' : 'like';
		const url = `https://goload.tk/api/like.php?id=${id}&${action}`;
		$(this).hasClass('clicked') ? (
			localStorage.setItem(`like${id}`, false)
		) : (
			localStorage.setItem(`like${id}`, true)
		);
		goload.like(url, id)
	}),

	// like comment
	$(document).on('click', '.comm_like', function() {
		const id = $(this).closest('.comment').data('id');
		const action = $(this).hasClass('clicked') ? 'dislike' : 'like';
		const url = `https://goload.tk/api/likecomment.php?id=${id}&${action}`;
		$(this).hasClass('clicked') ? (
			localStorage.setItem(`likeComm${id}`, false)
		) : (
			localStorage.setItem(`likeComm${id}`, true)
		);
		goload.like(url, id, 'comm_like_count', 'comm_like')
	}),

	// upload file
	$upload.on('change', (e) => {
		const url = `https://goload.tk/api/upload.php`;
		const formData = new FormData;
		const file = e.target.files[0];

		localStorage.getItem('username') ? (
			formData.append('username', localStorage.getItem('username'))
		) : '';
		formData.append('filename', file);

		const extension = file.name.toLowerCase().match(/\.([^.]+?$)/)[1];
		if (!validate(extension)) {
			return warning('This file format is not allowed', 'error')
		}
		if (file.size > 1048576 * 50) {
			return warning('Maximum file size 50 Mb', 'error')
		}

		goload.upload(url, formData, function() {
			const res = this;
			res.success ? (
				$root.prepend(
					template.view(
						res.data.id,
						res.data.url,
						res.data.author,
						res.data.time,
						res.data.name,
						res.data.link,
						0,
						0,
						0,
						0,
						res.data.type
					)
				)
			) : (
				warning(res.data.message, 'error')
			)
		})
	}),

	// events for write comment
	$(document).on('click', '#write', function() {
		const id = $('body').find('.file').data('id');
		const text = $('#textInput').val().replace(/(<([^>]+)>)/ig, '');
		let author;

		localStorage.getItem('username') ? (
			author = localStorage.getItem('username')
		) : (
			author = $('#nameInput').val(),
			localStorage.setItem('username', author),
			$('#nameInput').remove(),
			$('.commentForm').prepend(`<div class="user">${localStorage.getItem('username').slice(0, 1)}</div>`)
		);

		author ? text ? (
			writecomment(id, author, text),
			$('#textInput').val('')
		)
		: warning('Enter text', 'error')
		: warning('Enter name', 'error')
	}),

	$(document).on('keyup', '#textInput', () => {
		$("#textInput").val().length > 2 && $(".commentForm").addClass("typed"),
		$("#textInput").val().length < 3 && $(".commentForm").removeClass("typed")
	}),

	$(document).on('keyup', '#nameInput, #textInput', (e) => {
		if ($("#textInput").val().length > 2 && e.which === 13) {
			const id = $('body').find('.file').data('id');
			const text = $('#textInput').val();
			let author;

			localStorage.getItem('username') ? (
				author = localStorage.getItem('username')
			) : (
				author = $('#nameInput').val(),
				localStorage.setItem('username', author),
				$('#nameInput').remove(),
				$('.commentForm').prepend(`<div class="user">${localStorage.getItem('username').slice(0, 1)}</div>`)
			);

			author ? text ? (
				writecomment(id, author.replace(/(<([^>]+)>)/ig, ''), text.replace(/(<([^>]+)>)/ig, '')),
				$('#textInput').val('')
			)
			: warning('Enter text', 'error')
			: warning('Enter name', 'error')
		}
	}),

	// events for search
	$searchBtn.on('click', () => {
		$root.empty()
		$search.toggleClass('active').focus(),
		$('.logo').addClass('back outsearch').html(template.ic_back()),
		$('.loadFiles').remove()
	}),

	$(document).on('click', '.outsearch', () => {
		$search.toggleClass('active')
	}),

	$search.on('change', function() {
		const keyword = $(this).val();
		$root.empty(),
		$('.loadSearch').remove(),
		offsetSearch = 0,
		search(keyword),
		$root.after(template.loadBtn('moreSearch', 'loadSearch'))
	}),

	// load more results
	$(document).on('click', '#moreFiles', files),
	$(document).on('click', '#moreSearch', () => {
		search($search.val())
	}),
	$(document).on('click', '#moreComms', () => {
		comments($('body').find('.file').data('id'))
	}),

	route.has('file') ? (
		file()
	) : (
		files(),
		$root.after(template.loadBtn('moreFiles', 'loadFiles'))
	),

	$(document).on('click', 'a:not(.clickable)', (e) => {
		e.preventDefault(),
		$search.removeClass('active').val('')
	}),

	$(document).on('click', 'a.file_block:not(.here)', function() {
		history.pushState && (
			history.pushState(null, null, $(this).attr('href')),
			file($(this).closest('.file').data('id'))
		);
		return false;
	}),

	$(document).on('click', 'a.back', function() {
		history.pushState && (
			history.pushState(null, null, $(this).attr('href')),
			$root.empty(),
			offsetFiles = 0,
			offsetSearch = 0,
			offsetComms = 0,
			files(),
			$root.after(template.loadBtn('moreFiles', 'loadFiles')),
			$('.loadSearch').remove(),
			$('title').text(`GOload File Sharing`),
			$('.logo').removeClass('back').html(template.ic_logo())
		);
		return false;
	}),

	window.onpopstate = () => {
		if (location.pathname.substr(location.pathname.lastIndexOf("/")+1) === 'index.html') {
			$root.empty(),
			offsetFiles = 0,
			offsetSearch = 0,
			offsetComms = 0,
			$('.x-center').remove(),
			files(),
			$root.after(template.loadBtn('moreFiles', 'loadFiles')),
			$('title').text(`GOload File Sharing`),
			$('.logo').removeClass('back').html(template.ic_logo())
		}
	},

	$(document).on('click', '.copylink', () => {
		copy(`https://goload.tk/file${$('body').find('.file').data('id')}`)
	}),

	$(document).on('click', '.gif_play', function() {
		$(this).toggleClass('playing');
		$(this).parent().find('.gifview').attr('src', $(this).parent().find('.gifview').data('src'))
	}),

	$(document).on('click', '.gifview', function() {
		$(this).parent().find('.gif_play').toggleClass('playing');
		$(this).parent().find('.gifview').attr('src', $(this).parent().find('.gifview').data('file'))
	})
});