Youtube Sub Count Checker
`
// return `
//
//
//
`;
}
function createSecondsLabel(time, data) {
let hours = time.getHours(), minutes = time.getMinutes(), seconds = time.getSeconds();
// let item = jQuery(``)[0]
let item = jQuery(``)[0]
tippy(item, {
content : `Subscribers
${ data }
${ hours < 10 ? '0' + hours : hours }:${ minutes < 10 ? '0' + minutes : minutes }:${ seconds < 10 ? '0' + seconds : seconds }
`,
allowHTML: true,
});
return item
}
function recalculateTimeLine(forTime) {
let time = new Date(forTime);
let hours = time.getHours(), minutes = time.getMinutes();
let item = jQuery(timeRoadmap).find(`.timeline_item[data-rtime="${hours < 10 ? '0' + hours : hours }:${ minutes < 10 ? '0' + minutes : minutes }"]`)
// console.log(item, `${hours < 10 ? '0' + hours : hours }:${ minutes < 10 ? '0' + minutes : minutes }`)
item[0].classList.remove('show_time');
setTimeout(() => {
item.animate({
width: 0,
opacity: 0,
flex: '0 0 0'
}, 450, () => {
item.remove();
})
}, 450)
}
function removeEL(item){
item[0].classList.remove('show_time');
setTimeout(() => {
item.animate({
width: 0,
opacity: 0,
flex: '0 0 0'
}, 450, () => {
item.remove();
})
}, 450)
}
function restartTimeLine(){
clearInterval(interval);
timeline = {};
window.api_url_loaded = null;
jQuery(timeRoadmap).html('');
}
function initTimeLIne() {
let minutLabel = jQuery(createMinuteLabel(currTime));
jQuery(timeRoadmap).append(minutLabel);
setTimeout(() => {
minutLabel[0].style.left = '0';
}, 100)
setTimeout(() => {
minutLabel[0].classList.add('show_time');
}, 1000)
let sec = createSecondsLabel(currTime, initialData.toLocaleString('en-US'))
jQuery(minutLabel).append(sec)
setTimeout(() => {
sec.style.left = '0';
}, 100)
timeline[currTime.getTime()] = initialData;
lastTime = currTime.getTime();
initialTime = currTime.getTime();
interval = setInterval(createData, 1000);
}
function showForm(e) {
e.preventDefault();
window.ysl_form = jQuery(e.target).parents('form');
if (ysl_form.hasClass('add_new')) {
let field = jQuery(ysl_form).parents('.ysl_content').find('[data-initial-count]');
if (typeof gtag === 'function') {
gtag('event', '[TOOL] Interaction', {'tool_name': '**Youtube sub counter**'});
}
// ga('send', 'event', 'Tool Interaction', '**Youtube sub counter**')
restartTimeLine();
getYoutubeData(field, setYoutubeData);
return;
}
ysl_form.addClass('add_new');
}
function getYoutubeData(field, callback = () => {}) {
var e = jQuery('#y_url').val();
if (!e) return;
var expression = "(?:https|http)\:\/\/(?:[\w]+\.)?youtube\.com\/channel\/?([a-zA-Z0-9\-]{1,})";
var expressionC = "(?:https|http)\:\/\/(?:[\w]+\.)?youtube\.com\/c\/?([a-zA-Z0-9\-]{1,})";
var exUser = "(?:https|http)\:\/\/(?:[\w]+\.)?youtube\.com\/user\/?([a-zA-Z0-9\-]{1,})"
const channel = new RegExp(expression);
const channelC = new RegExp(expressionC);
const forUser = new RegExp(exUser);
var api_url = '';
if (e.match(channel)) {
var chanel_id = e.substring(e.lastIndexOf('/') + 1);
api_url = "https://www.googleapis.com/youtube/v3/channels?part=statistics,snippet&id=" + chanel_id + "&key=" + youtube_keys[Math.floor(Math.random() * youtube_keys.length)];
} else if (e.match(forUser)) {
var user = e.substring(e.lastIndexOf('/') + 1);
api_url = "https://www.googleapis.com/youtube/v3/channels?part=statistics,snippet&forUsername=" + user + "&key=" + youtube_keys[Math.floor(Math.random() * youtube_keys.length)];
} else if(e.match(channelC)) {
var chanel_custom_name = e.substring(e.lastIndexOf('/') + 1);
let nAp = `https://www.googleapis.com/youtube/v3/search?part=id&q=${chanel_custom_name}&type=channel&key=${youtube_keys[Math.floor(Math.random() * youtube_keys.length)]}`
jQuery.getJSON(nAp, function (data) {
if (null != data.items[0]) {
let {id: {channelId}} = data.items[0];
api_url = "https://www.googleapis.com/youtube/v3/channels?part=statistics,snippet&id=" + channelId + "&key=" + youtube_keys[Math.floor(Math.random() * youtube_keys.length)];
window.user_url = e;
window.api_url_loaded = api_url;
jQuery.getJSON(api_url, callback)
}else{
alert("User (channel) does not found or you inserted wrong value!")
}
})
return;
}
else{
api_url = "https://www.googleapis.com/youtube/v3/channels?part=statistics,snippet&forUsername=" + e + "&key=" + youtube_keys[Math.floor(Math.random() * youtube_keys.length)];
}
window.user_url = e;
window.api_url_loaded = api_url;
jQuery.getJSON(api_url, callback)
}
function setYoutubeData(data) {
if (null != data.items[0]) {
let {snippet: {title, description, thumbnails}, statistics: {subscriberCount = 0}} = data.items[0];
initialData = parseInt(subscriberCount);
let parent = jQuery(window.ysl_form).parents('.ysl_content'),
field = parent.find('[data-initial-count]'),
image = parent.find('.di_image img'),
name = parent.find('.di_name'),
link = parent.find('.di_subscribe_link')
;
field.attr('data-initial-count', initialData);
name.html(title);
image[0].src = thumbnails.default.url;
link[0].href = window.user_url;
field[0].innerText = new Intl.NumberFormat('en-GB', {
notation: "compact",
compactDisplay: "short"
}).format(initialData)
window.ysl_form[0].reset();
setTimeout(initTimeLIne, 100);
jQuery('.ysl_data').slideDown();
jQuery(window.ysl_form).removeClass('add_new');
} else {
if (!window.second) {
window.second = true;
getYoutubeData(field, setYoutubeData);
} else {
window.second = false;
alert("User (channel) does not found or you inserted wrong value!")
}
}
}