Leetcode Points

see monthly progress of leetcode points

2022-05-23 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @license      MIT
// @name         Leetcode Points
// @namespace    https://github.com/pk2sd
// @version      0.1
// @description  see monthly progress of leetcode points
// @author       https://leetcode.com/pK2015/
// @match        https://leetcode.com/store/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @grant        none
// @run-at       document-end
// ==/UserScript==

$('document').ready(() => {
    $.ajax({
        url: 'https://leetcode.com/points/api/'
    }).done((response) => {
        parseDataAndAddSummary(response)
    })

    let toTable = (map) => {
        let mapToTr = (totr) => {
            return Array.from(totr).sort((a, b) => {
                return parseInt(b[1]) - parseInt(a[1])
            }).map((entry) => {
                let key = entry[0]
                let value = entry[1]
                return '<tr>'
                    + '<td>'
                    +  key
                    + '</td>'
                    + '<td>'
                    +  value
                    + '</td>'
                    + '</tr>'
            }).reduce((prev, cur) => prev + cur, '')

        }
        return '<table>'
            + '<thead>'
            + '<tr>'
            + '<th>'
            +  'Activity'
            + '</th>'
            + '<th>'
            +  'Points'
            + '</th>'
            + '</tr>'
            + '</thead>'
            + '<tbody>'
            + mapToTr(map)
            + '</tbody>'
            + '</table>'


    }

    let parseDataAndAddSummary = (points) => {
        const month = new Date().getMonth()
        const year = new Date().getFullYear()
        const npoints = points.scores.map(point => {
            return {...point, date: new Date(Date.parse(point.date))}
        }).filter(p => p.date.getMonth() == month && p.date.getFullYear() == year)

        const total = npoints.map(p => p.score).reduce((x,y) => x+y,0);
        const activityToPointsMap = npoints.reduce((map, curPoint) => {
            if(map.has(curPoint.description)){
                map.set(curPoint.description, map.get(curPoint.description) + curPoint.score)
            } else {
                map.set(curPoint.description, curPoint.score)
            }
            return map
        }, new Map())

        $('<p>', {id: 'points_p'}).prependTo('body')
        $('#points_p').html('<h4> Total points: ' + total + '</h4><br/>' + toTable(activityToPointsMap))
        $('#points_p').css('display', 'flex')
        $('#points_p').css('align-items', 'center')
        $('#points_p').css('justify-content', 'center')
    }
    })