Leetcode timer


  • 2
    S

    Tampermonkey script for chrome!!

    This adds a timer on top of each question on Leetcode OJ.
    Gives 60mins for Hard, 45 for Medium and 25 for Easy. Really helps me being concentrated.

    I thought of sharing, this could help somebody keep the momentum going.
    Installation link if you have tampermonkey on chrome installed already!
    https://openuserjs.org/scripts/codelibra/Leetcode_timer

    Happy Leetcoding.

    // ==UserScript==
    // @name         Leetcode timer
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @description  try to take over the world!
    // @author       You
    // @match        https://leetcode.com/problems/*
    // @require      https://leetcode.com/static/jquery/dist/jquery.min.js
    // @grant        none
    // ==/UserScript==
    
    $(document).ready(function() {
    var $j = jQuery.noConflict();
    $j('#tab-view-app').prepend("<button align='center' id='timer'>Start Problem</button>");
    $j( "#timer" ).click(function(){
        $('#timer').html('');
        var difficulty = $j('.question-info ul li:nth-child(5)').text();
        var diff = 25, score=0;
        if(difficulty.indexOf("Hard") !== -1) {diff = 60;score=500;}
        if(difficulty.indexOf("Medium") !== -1) {diff = 45;score=250;}
        if(difficulty.indexOf("Easy") !== -1) {diff = 25;score=100;}
        // Update the count down every 1 second
        var countDownDate = new Date(new Date().getTime() + diff*60000);
    
        $j('#tab-view-app').prepend("<h1 align='center' id='timer1'> Starting Now!</h1>");
        $j('#submission-form-app').prepend("<h1 align='center' id='timer2'> Starting Now!</h1>");
        
        var x = setInterval(function() {
    
            var now = new Date().getTime();
            var distance = countDownDate - now;
            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
            var seconds = Math.floor((distance % (1000 * 60)) / 1000);
            if(minutes%10===0) score = score - 20;
            $j('#timer1').text(minutes + "m " + seconds + "s      SCORE: " + score);
            $j('#timer2').text(minutes + "m " + seconds + "s      SCORE: " + score);
            
            // If the count down is over, write some text
            if (distance < 0) {
                document.getElementById("timer1").innerHTML = "TIME UP!!";
                document.getElementById("timer2").innerHTML = "TIME UP!!";
            }
        }, 1000);
    });
    
    });
    

  • 1
    A

    @sp4658 Awesome timesaver!!.. Very precise and tangible and no gory details..


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.