Created
October 2, 2020 21:28
This file contains hidden or 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
// ==UserScript== | |
// @name Scratch Project Analytics | |
// @version 1 | |
// @description adds engagement rates for a project's likes/fav's out of total views an to MyStuff | |
// @author NickyNouse | |
// @match https://scratch.mit.edu/projects/* | |
// @match https://scratch.mit.edu/mystuf* | |
// @grant none | |
// ==/UserScript== | |
if (location.href.indexOf('projects') != -1) { | |
var views = $('#total-views .icon').text(); | |
var xtemp = parseInt($('#stats .favorite.icon').text().replace(/\W/g, '')); | |
$('#stats .favorite.icon').append(' ('+ Math.round(100*xtemp/views) + '%)'); | |
xtemp = parseInt($('#stats .love.icon').text().replace(/\W/g, '')); | |
$('#stats .love.icon').append(' ('+ Math.round(100*xtemp/views) + '%)'); | |
} else if (location.href.indexOf('stuff') != -1) { | |
var style89 = "<style>.media-stats {width: 170px !important; text-align: left !important; -webkit-column-count: 2; -moz-column-count: 2; column-count: 2;}</style>"; | |
$('head').append(style89); | |
var analyzed = false; | |
var analyticsobserver = new MutationObserver(function(mutations) { | |
if($('.media-list').length && $('.media-item-content:not(.not-shared):not(.analyzed)').length) { | |
//analyzed = true; | |
analyticsobserve(); | |
} | |
}); | |
analyticsobserver.observe($('#content')[0], {'childList': true, 'subtree': true,}); | |
var analyticsobserve = function() { | |
$('.media-item-content:not(.not-shared):not(.analyzed)').each( function(value, index) { | |
$(this).addClass('analyzed'); | |
var projvals = new Array(); | |
$(this).find('.stat').each( function(value, index) { | |
projvals.push(parseInt($(this).text().replace(/\W/g, ''))); | |
}); | |
$(this).find('.stat').eq(2).append(' ('+ Math.round(100*projvals[2]/projvals[0]) + '%)'); | |
$(this).find('.stat').eq(3).append(' ('+ Math.round(100*projvals[3]/projvals[0]) + '%)'); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment