Skip to content

Instantly share code, notes, and snippets.

@gabrielqmatos88
Last active May 29, 2022 12:46
Show Gist options
  • Select an option

  • Save gabrielqmatos88/3f7e6b9718f75a27dc515f45c292801c to your computer and use it in GitHub Desktop.

Select an option

Save gabrielqmatos88/3f7e6b9718f75a27dc515f45c292801c to your computer and use it in GitHub Desktop.
Calculate a better avg for udemy courses considering the difference between the total enrolls and total of votes in the course rating, the most part of the courses rating is based in avg 20%0-30% of enrolls
// ==UserScript==
// @name Udemy Calc
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.udemy.com/course/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=udemy.com
// @grant none
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
let ratingEl = $('[data-purpose="rating-number"]');
if (!ratingEl[0]){
$('[data-purpose="rating"]');
}
const rating = +ratingEl.text().replace(',', '.');
const votes = +/\((\d+(\.\d+)?)\s*cl/.exec($('.clp-lead__badge-ratings-enrollment span').text())[1].replace(/\./g, '');
const enrolls = +$('[data-purpose="enrollment"]').text().replace(/\./g, '').split(' ')[0];
const votesPerc = (votes / enrolls * 100).toFixed(1);
const realRating = +((rating * votes) / (5 * enrolls) * 5).toFixed(1);
const allInfo = { rating, votes, enrolls, realRating, votesPerc };
const color = ratingEl.css('color');
const fontWeight = ratingEl.css('font-weight');
const avg = ((+realRating + rating) / 2).toFixed(1);
console.log('allInfo', allInfo);
const render = () => {
console.log(`rendering`);
$('.clp-lead__badge-ratings-enrollment').css({'flex-wrap': 'wrap'})
$('.clp-lead__badge-ratings-enrollment').append(`<div id="new-rating" style="width: 100%"></div>`);
$('#new-rating').html(`
<div class="g-rating">
<div>Inscritos: ${enrolls.toLocaleString()}</div>
<div>Rating(100%): ${realRating.toLocaleString()}</div>
<div class="avg">${avg}</div>
<div>Votes (${votesPerc}%): ${votes.toLocaleString()}</div><div>Rating(${votesPerc}%): ${rating.toLocaleString()}</div>
</div>
`);
$('#new-rating').css({ width: '60%', color, 'font-weight': fontWeight, 'font-size': '12px' });
$('#new-rating .g-rating').css({
display: 'grid',
'row-gap': '5px',
'grid-template-columns': '1fr 1fr 60px'
})
$('#new-rating .g-rating .avg').css({
'grid-row': '1/3',
'grid-column': '3/4',
'display': 'flex',
'justify-content': 'center',
'align-items': 'center',
'background': '#f3ca8c',
'color': '#4d3105',
'font-size': '20px'
});
};
let count = 0;
let intervalId = setInterval(() => {
console.count(`checking...`);
if (count > 12) {
console.log(`checking stop`);
return clearInterval(intervalId);
}
count++;
if (!document.getElementById('new-rating')) {
render();
} else {
console.log(`exists`);
}
}, 100)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment