Skip to content

Commit 0c1b16c

Browse files
committed
Use of chrome.notifications APIs instead of webKitNotifications that has been deprecated
1 parent 23aac87 commit 0c1b16c

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

extension.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1+
function getNotificationOptions(message) {
2+
return {
3+
type: "basic",
4+
message: message,
5+
title: "MediaCrush",
6+
iconUrl: "icon48.png"
7+
};
8+
}
9+
110
function rehostImage(info, tab) {
211
var xhr = new XMLHttpRequest();
312
xhr.open('POST', 'https://mediacru.sh/api/upload/url');
13+
var notificationId = -1;
14+
chrome.notifications.create("", getNotificationOptions("Processing, please wait..."), function(id) {
15+
notificationId = id;
16+
});
417
xhr.onload = function() {
518
var result = JSON.parse(this.responseText);
619
if (this.status == 409) {
20+
chrome.notifications.clear(notificationId, function (ok) {});
721
window.open('https://mediacru.sh/' + result.hash, '_blank');
822
} else if (this.status == 200) {
9-
var notification = webkitNotifications.createNotification('icon48.png', 'MediaCrush', 'Processing, please wait...');
10-
notification.show();
1123
setTimeout(function() {
12-
checkStatus(result.hash, notification);
24+
checkStatus(result.hash, notificationId);
1325
}, 1000);
1426
} else {
27+
chrome.notifications.clear(notificationId, function (ok) {});
1528
alert('An error occured re-hosting this image.');
1629
}
1730
};
@@ -20,19 +33,19 @@ function rehostImage(info, tab) {
2033
xhr.send(formData);
2134
}
2235

23-
function checkStatus(hash, notification) {
36+
function checkStatus(hash, notificationId) {
2437
var xhr = new XMLHttpRequest();
2538
xhr.open('GET', 'https://mediacru.sh/api/' + hash + '/status');
2639
xhr.onload = function() {
2740
var result = JSON.parse(this.responseText);
2841
if (result.status == "error") {
29-
notification.cancel();
30-
notification = webkitNotifications.createNotification('icon48.png', 'MediaCrush', 'There was an error while processing this file.');
42+
chrome.notifications.clear(notificationId, function (ok) {});
43+
chrome.notifications.create("", getNotificationOptions('There was an error while processing this file.'), function(id) {});
3144
} else if (result.status == "timeout") {
32-
notification.cancel();
33-
notification = webkitNotifications.createNotification('icon48.png', 'MediaCrush', 'This file took too long to process.');
45+
chrome.notifications.clear(notificationId, function (ok) {});
46+
chrome.notifications.create("", getNotificationOptions('This file took too long to process.'), function(id) {});
3447
} else if (result.status == "done") {
35-
notification.cancel();
48+
chrome.notifications.clear(notificationId, function (ok) {});
3649
window.open('https://mediacru.sh/' + result.hash + '#fromExtension', '_blank');
3750
} else {
3851
setTimeout(function() { checkStatus(hash, notification); }, 1000);

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"name": "MediaCrush",
55
"description": "Instantly upload any image on the web to MediaCrush for reliable, fast hosting.",
6-
"version": "1.0",
6+
"version": "1.1",
77

88
"permissions": [
99
"contextMenus",

0 commit comments

Comments
 (0)