Skip to content

Instantly share code, notes, and snippets.

@Kief5555
Last active January 15, 2024 23:20
Show Gist options
  • Save Kief5555/2a2157cb9da629e55cf99bbac81f97ef to your computer and use it in GitHub Desktop.
Save Kief5555/2a2157cb9da629e55cf99bbac81f97ef to your computer and use it in GitHub Desktop.
Microsoft Teams Grades app calculator (for new teams)

Microsoft Teams grades (app) calculator

Only works in broswer Run this in broswer console (ctrl + shift + i), make sure to go into your team -> Grades on the side bar

Paste below:

// Select all assignment rows
const assignmentRows = document.querySelectorAll('tr[data-type="assignmentRow"]');

// Initialize variables for total marks and obtained marks
let totalMarks = 0;
let obtainedMarks = 0;

// Loop through the assignment rows
assignmentRows.forEach(assignmentRow => {
    // Extract the marks from the last column (column-15__y-uzA)
    const marksElement = assignmentRow.querySelector('.column-15__y-uzA span');
    if (marksElement) {
        const [obtained, total] = marksElement.textContent.trim().split('/').map(Number);
        if (!isNaN(obtained) && !isNaN(total)) {
            totalMarks += total;
            obtainedMarks += obtained;
        }
    }
});

// Calculate the percentage if totalMarks is not zero
const percentage = totalMarks !== 0 ? (obtainedMarks / totalMarks) * 100 : 0;

// Define grade based on percentage
let grade = '';

if (percentage >= 90) {
    grade = 'A+';
} else if (percentage >= 85) {
    grade = 'A';
} else if (percentage >= 80) {
    grade = 'A-';
} else if (percentage >= 76) {
    grade = 'B+';
} else if (percentage >= 72) {
    grade = 'B';
} else if (percentage >= 68) {
    grade = 'B-';
} else if (percentage >= 64) {
    grade = 'C+';
} else if (percentage >= 60) {
    grade = 'C';
} else if (percentage >= 55) {
    grade = 'C-';
} else {
    grade = 'F'; // Below 55 is considered fail
}

// Define color based on grade
let color = '';
switch (grade) {
    case 'A+':
    case 'A':
    case 'A-':
        color = 'green';
        break;
    case 'B+':
    case 'B':
    case 'B-':
        color = 'yellow';
        break;
    case 'C+':
    case 'C':
    case 'C-':
        color = 'orange';
        break;
    default:
        color = 'red';
}

// Log the result with colored output
console.log(`Total Marks: ${totalMarks}\nObtained Marks: ${obtainedMarks}`);
console.log(`%cPercentage: %c${percentage.toFixed(2)}%`, `color: white`, `color: ${color}`);
console.log(`%cGrade: %c${grade}`, 'color: white', `color: ${color}`);

If it logs nothing (eg a 0), you need to select any of the elements (Ctrl + Shift + C) and click on a grade (eg a 20/20) Keep in mind, if you have many assignments, you may need to scroll down to load them into the DOM

@Rycoh99
Copy link

Rycoh99 commented Jan 15, 2024

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment