Skip to content

Instantly share code, notes, and snippets.

@julienreszka
Last active November 15, 2019 12:31
Show Gist options
  • Save julienreszka/f0c4ebe29937e40b985c14dd0c9b975e to your computer and use it in GitHub Desktop.
Save julienreszka/f0c4ebe29937e40b985c14dd0c9b975e to your computer and use it in GitHub Desktop.
Youtube cumulated attention on a video
var viewsNb = Number(document.querySelector('.view-count').textContent.split(' ')[0].split(',').join(''));
var videoDuration = document.querySelector('video').getDuration();
var cumulatedAttentionInSeconds = viewsNb * videoDuration;
var cumulatedAttentionInMinutes = cumulatedAttentionInSeconds / 60;
var cumulatedAttentionInHours = cumulatedAttentionInMinutes / 60;
var cumulatedAttentionInDays = cumulatedAttentionInHours / 24;
var cumulatedAttentionInWeeks = cumulatedAttentionInDays / 7;
var cumulatedAttentionInMonths = cumulatedAttentionInWeeks / 4;
var cumulatedAttentionInYears = cumulatedAttentionInMonths / 12;
var cumulatedAttentionInDecades = cumulatedAttentionInYears / 12;
var cumulatedAttentionInCenturies = cumulatedAttentionInDecades / 12; // Lean on, Gangnam Style etc ...
var cumulatedAttention = document.createElement('span');
cumulatedAttention.setAttribute('class','cumulatedAttention');
cumulatedAttention.style.fontSize = 'large'
document.querySelector('.ytd-video-primary-info-renderer').appendChild(cumulatedAttention);
if (
Math.round(cumulatedAttentionInCenturies) > 0
) {
cumulatedAttention.textContent = `${Math.round(cumulatedAttentionInCenturies)} centuries πŸ‘`;
}
else if (
Math.round(cumulatedAttentionInDecades) > 0
) {
cumulatedAttention.textContent = `${Math.round(cumulatedAttentionInDecades)} decades πŸ‘`;
}
else if (
Math.round(cumulatedAttentionInYears) > 0
) {
cumulatedAttention.textContent = `${Math.round(cumulatedAttentionInYears)} years πŸ‘`;
}
else if (
Math.round(cumulatedAttentionInMonths) > 0
) {
cumulatedAttention.textContent = `${Math.round(cumulatedAttentionInMonths)} Months πŸ‘`;
}
else if (
Math.round(cumulatedAttentionInMonths) > 0
) {
cumulatedAttention.textContent = `${Math.round(cumulatedAttentionInMonths)} Months πŸ‘`;
}
else if (
Math.round(cumulatedAttentionInWeeks) > 0
) {
cumulatedAttention.textContent = `${Math.round(cumulatedAttentionInWeeks)} Weeks πŸ‘`;
}
else if (
Math.round(cumulatedAttentionInDays) > 0
) {
cumulatedAttention.textContent = `${Math.round(cumulatedAttentionInDays)} Days πŸ‘`;
}
else if (
Math.round(cumulatedAttentionInHours) > 0
) {
cumulatedAttention.textContent = `${Math.round(cumulatedAttentionInHours)} Hours πŸ‘`;
}
else if (
Math.round(cumulatedAttentionInMinutes) > 0
) {
cumulatedAttention.textContent = `${Math.round(cumulatedAttentionInMinutes)} Minutes πŸ‘`;
}
else {
cumulatedAttention.textContent = `Nobody cares about this video πŸ‘`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment