Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marcia committed Sep 23, 2011
0 parents commit c93e325
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
@@ -0,0 +1,7 @@
* Tools => Extensions
* Show developer mode
* Load unpacked extension
* Point to sesame
* Visit something like https://github.com/Khan/khan-exercises/issues/3082
* Click on the page action leaf icon to open the referenced problem locally
* BONUS: Type "o" to do the same thing
22 changes: 22 additions & 0 deletions background.html
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<script>
function showPageAction( request, sender, sendResponse ) {
// Show the page action leaf icon
chrome.pageAction.show( sender.tab.id );
// Return nothing to let the connection be cleaned up
sendResponse({});
};


// Listen for the content script to send a message
chrome.extension.onRequest.addListener( showPageAction );

// Send a request to contentscript, which will open the new tab
chrome.pageAction.onClicked.addListener( function( tab ) {
chrome.tabs.sendRequest( tab.id, {} );
});
</script>
</head>
</html>
21 changes: 21 additions & 0 deletions contentscript.js
@@ -0,0 +1,21 @@
// Depending on how your environment is set up,
// you may need to change the base variable
function openProblemInNewTab( request, sender, sendResponse ) {
var exercise = jQuery( ".content-body:first" ).text().match( /.*html.*/ );
var base = "http://localhost/khan-exercises/exercises/";
window.open( base + exercise.pop(), "_blank" );
}

// Listen for the request to open the problem in a new tab,
// which comes from the background page
chrome.extension.onRequest.addListener( openProblemInNewTab );

chrome.extension.sendRequest({}, function( response ) {});

jQuery( function() {
jQuery( document ).keypress( function( event ) {
if ( event.which === 111 ) {
openProblemInNewTab();
}
});
})
Binary file added icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions jquery.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions manifest.json
@@ -0,0 +1,20 @@
{
"name": "sesame",
"version": "1.0",
"description": "Click the leaf page action open the referenced problem locally",
"background_page": "background.html",
"page_action" :
{
"default_icon" : "icon.png"
},
"permissions" : [
"tabs"
],
"content_scripts": [
{
"matches": ["https://github.com/Khan/khan-exercises/issues/*"],
"js": ["jquery.js", "contentscript.js"],
"run_at": "document_idle"
}
]
}

0 comments on commit c93e325

Please sign in to comment.