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
0 parents
commit c93e325
Showing
6 changed files
with
74 additions
and
0 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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(); | |||
} | |||
}); | |||
}) |
Large diffs are not rendered by default.
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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" | |||
} | |||
] | |||
} |