Skip to content

Commit 23aac87

Browse files
committed
Initial commit
0 parents  commit 23aac87

8 files changed

+153
-0
lines changed

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2013 MediaCrush
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# MediaCrush for Chrome
2+
3+
This is the official MediaCrush extension for Chrome.
4+
5+
With this extension, you can upload any image to MediaCrush from any website, simply by right-clicking it.
6+
7+
Setting up a dev version is simple:
8+
9+
1. Enable developer mode in the extensions page
10+
2. Install it as an unpacked extension

extension.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function rehostImage(info, tab) {
2+
var xhr = new XMLHttpRequest();
3+
xhr.open('POST', 'https://mediacru.sh/api/upload/url');
4+
xhr.onload = function() {
5+
var result = JSON.parse(this.responseText);
6+
if (this.status == 409) {
7+
window.open('https://mediacru.sh/' + result.hash, '_blank');
8+
} else if (this.status == 200) {
9+
var notification = webkitNotifications.createNotification('icon48.png', 'MediaCrush', 'Processing, please wait...');
10+
notification.show();
11+
setTimeout(function() {
12+
checkStatus(result.hash, notification);
13+
}, 1000);
14+
} else {
15+
alert('An error occured re-hosting this image.');
16+
}
17+
};
18+
var formData = new FormData();
19+
formData.append('url', info.srcUrl);
20+
xhr.send(formData);
21+
}
22+
23+
function checkStatus(hash, notification) {
24+
var xhr = new XMLHttpRequest();
25+
xhr.open('GET', 'https://mediacru.sh/api/' + hash + '/status');
26+
xhr.onload = function() {
27+
var result = JSON.parse(this.responseText);
28+
if (result.status == "error") {
29+
notification.cancel();
30+
notification = webkitNotifications.createNotification('icon48.png', 'MediaCrush', 'There was an error while processing this file.');
31+
} else if (result.status == "timeout") {
32+
notification.cancel();
33+
notification = webkitNotifications.createNotification('icon48.png', 'MediaCrush', 'This file took too long to process.');
34+
} else if (result.status == "done") {
35+
notification.cancel();
36+
window.open('https://mediacru.sh/' + result.hash + '#fromExtension', '_blank');
37+
} else {
38+
setTimeout(function() { checkStatus(hash, notification); }, 1000);
39+
}
40+
};
41+
xhr.send();
42+
}
43+
44+
chrome.contextMenus.create({ title: 'Rehost on MediaCrush', contexts: [ 'image' ], onclick: rehostImage });

icon128.png

5.06 KB
Loading

icon16.png

848 Bytes
Loading

icon48.png

1.86 KB
Loading

manifest.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"manifest_version": 2,
3+
4+
"name": "MediaCrush",
5+
"description": "Instantly upload any image on the web to MediaCrush for reliable, fast hosting.",
6+
"version": "1.0",
7+
8+
"permissions": [
9+
"contextMenus",
10+
"https://mediacru.sh/*",
11+
"notifications"
12+
],
13+
14+
"icons": {
15+
"16": "icon16.png",
16+
"48": "icon48.png",
17+
"128": "icon128.png"
18+
},
19+
20+
"web_accessible_resources": [
21+
"icon48.png"
22+
],
23+
24+
"background": {
25+
"scripts": [
26+
"extension.js"
27+
]
28+
}
29+
}

mediacrush_logo.svg

+63
Loading

0 commit comments

Comments
 (0)