Skip to content

Instantly share code, notes, and snippets.

@cllu
Last active November 25, 2015 07:18
Show Gist options
  • Save cllu/fa7073c4b69747b43282 to your computer and use it in GitHub Desktop.
Save cllu/fa7073c4b69747b43282 to your computer and use it in GitHub Desktop.
LeetCode OJ Tampermonkey script

LeetCode OJ modifier

  • hide the LeetCode Premium Subscription and Books links on the top navigation bar, since I have already subscribed.
  • hide the chat link, hide the footer
  • hide the FAQ block on the right column for the discussion page
  • display the question id on the problem page
  • display number of solved/total problems on the /company/ page
// ==UserScript==
// @name LeetCode
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Make LeetCode a bit better
// @author Chunliang Lyu
// @match https://leetcode.com/company/*/
// @match https://leetcode.com/problemset/algorithms/
// @match https://leetcode.com/problems/*/
// @match https://leetcode.com/discuss/*
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
console.log("hello from tampermonkey");
// add question id to the question detail page
var questionIdNode = document.querySelector('input[name="question_id"]');
if (questionIdNode) {
var questionId = questionIdNode.value;
var node = document.createElement('span');
node.appendChild(document.createTextNode('#' + questionId));
var titleNode = document.querySelector('.question-title');
titleNode.appendChild(node);
// styling
node.style.color = "#BBB";
node.className = 'question-id';
node.style.marginLeft = '5px';
}
function hideElement(query) {
var node = document.querySelector(query);
if (node) {
node.style.display = 'none'
}
}
// hide the ugly subscribtion and book links
hideElement('#subscribe'); // on the problem page
hideElement('a[href="/subscribe"]'); // on the discuss page
hideElement('.qa-sidebar'); // discussion sidebar
hideElement('#bookNav');
hideElement('#chat-link'); // Send Feedback
hideElement('footer');
hideElement('#survey'); // Have you met this question in a real interview? No
// add statictics in the /company/*/ page
if (document.location.pathname.startsWith('/company/')) {
var stat = document.querySelectorAll('.ac').length + '/' + document.querySelectorAll('tr').length;
var node = document.createElement('span');
node.textContent = stat;
var header = document.querySelector('h3');
header.appendChild(node);
node.style.fontSize = '14px';
node.style.color = '#BBB';
}
// hide non-free questions on the problem set page
//Array.prototype.forEach.call(document.querySelectorAll('.fa-lock'), function (n) {
// n.parentElement.parentElement.style.display = "none";
//});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment