-
Notifications
You must be signed in to change notification settings - Fork 2
/
CodeChefMonkey.user.js
27 lines (24 loc) · 991 Bytes
/
CodeChefMonkey.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// ==UserScript==
// @name CodeChefMonkey
// @version 1.0
// @description Links practice version of a competition problem on CodeChef
// @author Gil Vegliach
// @include https://www.codechef.com/*/problems/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// ==/UserScript==
waitForKeyElements(".problem-info", addLinkFunction);
function addLinkFunction(panels) {
var panel = panels[0];
if (panel) {
var url = removeFirstUrlSegment(window.location.href);
var p = document.createElement('p');
p.innerHTML='<label>Practice link:</label><span><a href="' + url +'">Solve practice problem</a></span>';
panel.appendChild(p);
}
}
function removeFirstUrlSegment(url) {
var from = url.indexOf('/', "https://".length);
var to = url.indexOf('/', from + 1);
return url.substring(0, from) + url.substring(to);
}