Last active
November 15, 2019 12:31
-
-
Save julienreszka/f0c4ebe29937e40b985c14dd0c9b975e to your computer and use it in GitHub Desktop.
Youtube cumulated attention on a video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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