-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
713771f
commit 7eb1065
Showing
8 changed files
with
246 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ Install/* | |
*.DS_Store | ||
*.sublime-project | ||
pylintrc | ||
*.sublime-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var languages = [ | ||
{ | ||
ext : "c", | ||
name : "C" | ||
}, | ||
{ | ||
ext : "cpp", | ||
name : "C++" | ||
}, | ||
{ | ||
ext : "java", | ||
name : "Java" | ||
}, | ||
{ | ||
ext : "py", | ||
name : "Python" | ||
} | ||
]; | ||
|
||
//Getting the URL of the HTMl Page | ||
var url = document.URL; | ||
|
||
//Removing the trailing punctuation marks | ||
while(url[url.length - 1] === "/" || url[url.length - 1] === "#") | ||
{ | ||
url = url.slice(0, url.length - 1); | ||
} | ||
|
||
//Spliting the URL to get path | ||
var us = url.split("/"); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//Helper function to get click_functions | ||
function click_codechef(language) | ||
{ | ||
return function () { | ||
console.log(language + " Code Now Clicked. Opening " + language + " IDE"); | ||
var prob_name = $('title')[0].text.split('|')[0].trim(); | ||
var prob_url = url; | ||
var u_name = ""; | ||
//Checking if User is LoggedIn | ||
if($('#user-bar span.login-box').length > 0) | ||
{ | ||
//No Logged In User Detected | ||
u_name = "No User"; | ||
} | ||
else | ||
{ | ||
//A user is logged in | ||
u_name = $('#user-bar span').text().split('!')[0].replace('Hello', '').trim(); | ||
} | ||
//Sending Message to the native host with a json object of problem details | ||
chrome.runtime.sendMessage({problem_name: prob_name, problem_url: prob_url, user_name: u_name, lang : language}); | ||
}; | ||
} | ||
|
||
// Helper function to add codechef buttons | ||
var codechef_interval = null; | ||
function add_codechef_buttons() | ||
{ | ||
if ($('#problem-page-top').length === 0) | ||
{ | ||
// This means that the page hasn't loaded completely yet. So Wait | ||
return; | ||
} | ||
else | ||
{ | ||
// Dynamic DOM Created by codechef | ||
var button_list = $("#problem-page-top").find("ul"); | ||
var html = button_list.html(); | ||
// Adding Language Button | ||
for (var i = 0; i < languages.length; i++) | ||
{ | ||
html += "<li><a href='#' id='code_now_id_" + languages[i].ext + "_button'>Code in " + languages[i].name + "</a></li>"; | ||
} | ||
button_list.html(html); | ||
|
||
//Adding Listeners | ||
for(var j = 0; j < languages.length; j++) | ||
{ | ||
$("#code_now_id_" + languages[j].ext + "_button").click(click_codechef(languages[j].ext)); | ||
} | ||
console.log("Code Now Button Added !! ~ Code Now Extension"); | ||
|
||
// Clear interval, so that buttons are not added repeatedly | ||
clearInterval(codechef_interval); | ||
} | ||
} | ||
|
||
var code = us[us.length - 1]; | ||
if(us[us.length - 2] === "problems" && code !== "easy" && code !== "medium" && code !== "hard" && code !== "challenge" && code !== "extcontest" && code !== "school") | ||
{ | ||
// Adding A little sleep here because codechef mutates DOM to add all elements dynamically | ||
codechef_interval = window.setInterval(add_codechef_buttons, 5000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
function click_codeforces(language) | ||
{ | ||
return function() { | ||
console.log(language + " Code Now Clicked. Opening " + language + " IDE"); | ||
var prob_name = $('#pageContent .title').html().split('.')[1].trim(); | ||
var prob_url = url; | ||
var u_name = ""; | ||
var reg_link = $('#header .lang-chooser div')[1].children[1].text.toLowerCase(); | ||
if(reg_link == "register") | ||
{ | ||
u_name = "No User"; | ||
} | ||
else | ||
{ | ||
u_name = $('#header .lang-chooser div')[1].children[0].text.toLowerCase(); | ||
} | ||
chrome.runtime.sendMessage({problem_name: prob_name, problem_url: prob_url, user_name: u_name, lang : language}); | ||
}; | ||
} | ||
|
||
if(us.length > 4 && (us[us.length - 2] === "problem" || us[us.length - 3] === "problem")) | ||
{ | ||
//Creating and Adding A whole new Sidebox with 3 buttons | ||
$('#sidebar').html( | ||
'<div class="roundbox sidebox" style="">' + | ||
'<div class="roundbox-lt"> </div>' + | ||
'<div class="roundbox-rt"> </div>' + | ||
'<table class="rtable ">' + | ||
'<tbody>' + | ||
'<tr><th class="left" style="width:100%;"><a style="color: black" href="">Code Now</a></th></tr>' + | ||
'<tr>' + | ||
'<td class="left bottom" colspan="1">' + | ||
'<div style="text-align:center;margin:1em;" id="code_now_button_box">' + | ||
'</div>' + | ||
'</td>' + | ||
'</tr>' + | ||
'</tbody>' + | ||
'</table>' + | ||
'</div>' + | ||
$('#sidebar').html); | ||
|
||
for(var i = 0; i < languages.length; i++) | ||
{ | ||
var button = $('<button/>', { | ||
text : 'Code in ' + languages[i].name, | ||
click : click_codeforces(languages[i].ext) | ||
}); | ||
$('#code_now_button_box').append(button); | ||
$('#code_now_button_box').append($('<br/>')); | ||
$('#code_now_button_box').append($('<br/>')); | ||
} | ||
console.log("Code Now Button Added !! ~ Code Now Extension"); | ||
} |
Oops, something went wrong.