Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto committed Aug 6, 2012
0 parents commit a0f1b38
Show file tree
Hide file tree
Showing 19 changed files with 3,574 additions and 0 deletions.
7 changes: 7 additions & 0 deletions MIT.LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2012 Roberto Soares Oliveira Filho

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Gist.IO Chrome Extension

This extension adds a button **IO**, only seen in gist.io and gist.github.com pages. Click it when you’re on a gist page, and it will take you to the corresponding gist.io page and vice versa.

![Gist.IO Screenshot](http://f.cl.ly/items/2i0T0Z1b351w0D2I1H3v/gist-io-chrome.png)

## Changelog

### 0.1.0:

- main feature: to switch between pages

## Roadmap

- better icon
4 changes: 4 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
chrome.extension.onMessage.addListener(function(message, sender, sendResponse){
GistIO.setUp(message, sender.tab);
sendResponse({});
});
1 change: 1 addition & 0 deletions gist_content_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chrome.extension.sendMessage("gist", function(response) {});
25 changes: 25 additions & 0 deletions gist_io.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function GistIO(){};

GistIO.pages = {
gist: {
regex: /^http[s]?\:\/\/gist\.github\.com\/(\d+)$/,
destiny: "http://gist.io/"
},
io: {
regex: /^http\:\/\/gist\.io\/(\d+)$/,
destiny: "https://gist.github.com/"
}
};

GistIO.setUp = function(pageId, tab){
chrome.pageAction.show(tab.id);
chrome.pageAction.onClicked.addListener(function(tab){
GistIO.alternate(GistIO.pages[pageId],tab);
});
}

GistIO.alternate = function(page, tab) {
if (tab.url.match(page.regex)){
chrome.tabs.update(tab.id, {url: page.destiny + RegExp.$1});
}
};
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions io_content_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chrome.extension.sendMessage("io", function(response) {});
32 changes: 32 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "Gist.IO Link",
"version": "0.1.0",
"manifest_version": 2,
"homepage_url": "http://github.com/roberto/gist-io-chrome",
"background": {
"scripts": ["gist_io.js","background.js"]
},
"permissions": [
"tabs"
],
"content_scripts": [
{
"matches": ["https://gist.github.com/*"],
"run_at": "document_start",
"js": ["gist_content_script.js"]
},
{
"matches": ["http://gist.io/*"],
"run_at": "document_start",
"js": ["io_content_script.js"]
}
],
"icons":{
"16": "icon16.png",
"32": "icon32.png"
},
"page_action": {
"default_icon": "icon16.png",
"default_name": "Gist.IO"
}
}
59 changes: 59 additions & 0 deletions spec/SpecRunner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>

<link rel="shortcut icon" type="image/png" href="support/jasmine-1.2.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="support/jasmine-1.2.0/jasmine.css">
<script type="text/javascript" src="support/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="support/jasmine-1.2.0/jasmine-html.js"></script>
<script type="text/javascript" src="support/require.js"></script>

<!-- include source files here... -->
<script type="text/javascript" src="../gist_io.js"</script>

<!-- include spec files here... -->
<script type="text/javascript" src="bleh"></script>
<script type="text/javascript" src="background_spec.js"></script>
<script type="text/javascript" src="gist_io_spec.js"></script>
<script type="text/javascript" src="content_script_spec.js"></script>

<script type="text/javascript">
(function() {
require = require.config({
baseUrl: "../"
});

var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;

var htmlReporter = new jasmine.HtmlReporter();

jasmineEnv.addReporter(htmlReporter);

jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};

var currentWindowOnload = window.onload;

window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};

function execJasmine() {
jasmineEnv.execute();
}

})();
</script>

</head>

<body>
</body>
</html>
27 changes: 27 additions & 0 deletions spec/background_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe("background", function(){
beforeEach(function(){
chrome = {
extension: {
onMessage: {
addListener: function(){}
}
}
}
spyOn(chrome.extension.onMessage, 'addListener');
spyOn(GistIO, 'setUp').andCallFake(function(){});
});

it("should add a listener to setup GistIO when got a message from content scripts", function(){
runs(function(){
require(['background']);
});
waits(100);

runs(function(){
listener = chrome.extension.onMessage.addListener.mostRecentCall.args[0]
listener("message", {tab: "tab"}, function(){});
expect(GistIO.setUp).toHaveBeenCalledWith("message", "tab");
});
});

})
39 changes: 39 additions & 0 deletions spec/content_script_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
describe("content_scripts", function(){
beforeEach(function(){
chrome = {
extension: {
sendMessage: function(){}
}
}
spyOn(chrome.extension, 'sendMessage');
});

describe("gist_content_script", function(){
it("should send 'gist' as message when has been loaded", function(){
runs(function(){
require(['gist_content_script']);
});

waits(100);

runs(function(){
expect(chrome.extension.sendMessage).toHaveBeenCalledWith('gist', jasmine.any(Function));
});
})
})

describe("io_content_script", function(){
it("should send 'io' as message when has been loaded", function(){
runs(function(){
require(['io_content_script']);
});

waits(100);

runs(function(){
expect(chrome.extension.sendMessage).toHaveBeenCalledWith('io', jasmine.any(Function));
});
})
})

});
83 changes: 83 additions & 0 deletions spec/gist_io_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
describe("GistIO", function(){

describe("setUp", function(){
beforeEach(function(){
tab = {id: 12345};
page = GistIO.pages["gist"];
chrome = {
pageAction: {
show: function(){},
onClicked: {
addListener: function(){}
}
}
}

spyOn(chrome.pageAction, 'show');
spyOn(chrome.pageAction.onClicked, 'addListener');
spyOn(GistIO, 'alternate');

GistIO.setUp("gist", tab);
});

it("should show button", function(){
expect(chrome.pageAction.show).toHaveBeenCalledWith(tab.id);
});

it("should add a listener for clicked event", function(){
expect(chrome.pageAction.onClicked.addListener).toHaveBeenCalled();
});

it("should setup a listener to call alternate method", function(){
listener = chrome.pageAction.onClicked.addListener.mostRecentCall.args[0]
listener({id: 12345});
expect(GistIO.alternate).toHaveBeenCalledWith(page, tab);
});

});

describe("alternate", function(){
beforeEach(function(){
chrome = {
tabs: {
update: function(){}
}
}
spyOn(chrome.tabs, 'update');
});

it("should redirect to gist when current page is a valid gistIO page", function(){
tab = {id: 12345, url: "http://gist.io/54321"};
page = GistIO.pages["io"];

GistIO.alternate(page, tab);
expect(chrome.tabs.update).toHaveBeenCalledWith(tab.id, {url: "https://gist.github.com/54321"});
});

it("should redirect to gistIO when current page is a valid gist page", function(){
tab = {id: 12345, url: "http://gist.github.com/101010"};
page = GistIO.pages["gist"];

GistIO.alternate(page, tab);
expect(chrome.tabs.update).toHaveBeenCalledWith(tab.id, {url: "http://gist.io/101010"});
});

it("should not redirect to gist when current page is a invalid gistIO page", function(){
tab = {id: 12345, url: "http://gist.io/"};
page = GistIO.pages["io"];

GistIO.alternate(page, tab);
expect(chrome.tabs.update).wasNotCalled();
});

it("should not redirect to gistIO when current page is a invalid gist page", function(){
tab = {id: 12345, url: "https://gist.github.com/gists/101010/edit"};
page = GistIO.pages["gist"];

GistIO.alternate(page, tab);
expect(chrome.tabs.update).wasNotCalled();
});
});

});

20 changes: 20 additions & 0 deletions spec/support/jasmine-1.2.0/MIT.LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2008-2011 Pivotal Labs

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit a0f1b38

Please sign in to comment.