Leetcode Timer

Start a timer whenever a user loads a problem at Leetcode.com

Tính đến 18-05-2020. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name     Leetcode Timer
// @description:en Start a timer whenever a user loads a problem at Leetcode.com
// @version  1
// @grant    none
// @include	 *://*leetcode.com/problems/*
// @author   ketankr9
// @namespace https://greasyfork.org/users/564674
// @description Start a timer whenever a user loads a problem at Leetcode.com
// ==/UserScript==


function countdownTimer() {
  var difference = +new Date() - startTime;
  var elapsed = "0";

  var parts = {
    days: Math.floor(difference / (1000 * 60 * 60 * 24)),
    hours: Math.floor((difference / (1000 * 60 * 60)) % 24),
    minutes: Math.floor((difference / 1000 / 60) % 60),
    seconds: Math.floor((difference / 1000) % 60)
  };

  elapsed = Object.keys(parts)
    .map(part => {
    if (!parts[part]) return;
    return `${parts[part]} ${part}`;
  })
    .join(" ");
	
  document.getElementById("countdown").innerHTML = elapsed;
}

var f = function(div){
  div.innerHTML = '<div id="countdown" style="font-size:20px;"></div>' + div.innerHTML;
  startTime = +new Date();
  setInterval(countdownTimer, 1000);
}

function waitForElementToDisplay(selector, time, f) {
  			var node = document.getElementsByClassName(selector);
        console.log(node);
        if(node.length > 0) {
          	console.log("Element Found");
            f(node[0])
            return;
        }
        setTimeout(function() {
            waitForElementToDisplay(selector, time, f);
        }, time);
    }

var startTime;
waitForElementToDisplay("btns__1OeZ", 1000, f);