Skip to content

Commit 4e9f2c2

Browse files
SaraVieiraCompuIves
authored andcommitted
Create simple chrome extension (codesandbox#1188)
* create simple chrome extension * add readme * only show if a package.json is presengt * bump version
1 parent 8713bb1 commit 4e9f2c2

File tree

11 files changed

+93
-0
lines changed

11 files changed

+93
-0
lines changed

packages/chrome-extension.zip

336 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
chrome-extension.pem
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Chrome Extension
2+
3+
![Image](https://user-images.githubusercontent.com/1051509/46907462-fc0ef600-cf12-11e8-8d73-05b95577364e.png)
4+
5+
[![available in the chrome store](https://developer.chrome.com/webstore/images/ChromeWebStore_Badge_v2_206x58.png)](https://chrome.google.com/webstore/detail/jkhbnhagngalpojoeijaleemepfpefmp)
6+
7+
This chrome extension adds a button to all github repos that will open that repo in CodeSandbox in a new window
8+
9+
## How to run
10+
11+
- Open the Extension Management page by navigating to chrome://extensions.
12+
- Enable Developer Mode by clicking the toggle switch next to Developer mode.
13+
- Click the LOAD UNPACKED button and select this folder.
14+
15+
![load](https://developer.chrome.com/static/images/get_started/load_extension.png)
16+
17+
## How to publish
18+
19+
Unfortunately there is a need for a key to in order to update apps so as soon as something gets merged pls ping me in the PR and I will create a new version
6.1 KB
Loading
620 Bytes
Loading
1.99 KB
Loading
35 KB
Loading
301 KB
Loading
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// CodeSandbox Logo
2+
const SVG = `
3+
<svg x="0px" y="0px" width="18px" height="18px" viewBox="0 0 1024 1024"><g id="Layer_1"><polyline fill="#FFFFFF" points="719.001,851 719.001,639.848 902,533.802 902,745.267 719.001,851"></polyline><polyline fill="#FFFFFF" points="302.082,643.438 122.167,539.135 122.167,747.741 302.082,852.573 302.082,643.438"></polyline><polyline fill="#FFFFFF" points="511.982,275.795 694.939,169.633 512.06,63 328.436,169.987 511.982,275.795"></polyline></g><g id="Layer_2"><polyline fill="none" stroke="#FFFFFF" stroke-width="80" stroke-miterlimit="10" points="899,287.833 509,513 509,963"></polyline><line fill="none" stroke="#FFFFFF" stroke-width="80" stroke-miterlimit="10" x1="122.167" y1="289" x2="511.5" y2="513"></line><polygon fill="none" stroke="#FFFFFF" stroke-width="80" stroke-miterlimit="10" points="121,739.083 510.917,963.042 901,738.333 901,288 511,62 121,289"></polygon></g></svg>
4+
`;
5+
6+
const addButton = () => {
7+
const files = Array.from(
8+
document.querySelectorAll('.files .content .js-navigation-open')
9+
).map(n => n.innerHTML);
10+
11+
// No package.json === stop
12+
if (!files.includes('package.json')) {
13+
return null;
14+
}
15+
16+
// .Get the toolbar
17+
const toolbar = document.querySelector(
18+
'.file-navigation.in-mid-page.d-flex.flex-items-start'
19+
);
20+
// Get everything after https://github.com/
21+
const URL = window.location.pathname;
22+
23+
// Create the button
24+
const button = document.createElement('a');
25+
button.setAttribute('href', `https://codesandbox.io/s/github${URL}`);
26+
button.setAttribute('target', '_blank');
27+
button.setAttribute('rel', 'noopener noreferrer');
28+
29+
button.classList.add(
30+
'btn',
31+
'btn-sm',
32+
'btn-primary',
33+
'open-codesanbox-chrome-extension'
34+
);
35+
button.innerHTML = `
36+
${SVG}
37+
Open in CodeSandbox
38+
`;
39+
40+
// Add it to the DOM
41+
return toolbar.append(button);
42+
};
43+
addButton();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Open in CodeSandbox",
4+
"short_name": "CodeSandbox",
5+
"version": "1.1.0",
6+
"description": "Adds an open in CodeSandbox button to Github Repos",
7+
"homepage_url": "https://codesandbox.io",
8+
"icons": {
9+
"16": "./assets/icon16.png",
10+
"48": "./assets/icon48.png",
11+
"128": "./assets/icon128.png"
12+
},
13+
"content_scripts": [
14+
{
15+
"css": ["styles.css"],
16+
"js": ["content.js"],
17+
"matches": ["https://github.com/*"]
18+
}
19+
]
20+
}

0 commit comments

Comments
 (0)