Permalink
Browse files

Added remaining files for Opera support - NOTE: pretty sure that this…

… breaks the Chrome extension - stay tuned.
  • Loading branch information...
1 parent 23982ae commit 9bf8ec848734ba864cc9f12bb71bf836d3ac7023 @nathan-osman committed Jan 16, 2012
View
28 common/stackalert.js
@@ -101,9 +101,7 @@ var StackAlert = {
// Create a canvas element that will be used to overlay the icon
// and the colored text.
- var canvas = (StackAlert.Browser == 'firefox')?
- document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'):
- document.createElement('canvas');
+ var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
canvas.setAttribute('width', StackAlert.IconSize);
canvas.setAttribute('height', StackAlert.IconSize);
@@ -143,6 +141,9 @@ var StackAlert = {
},
+ // The single button instance
+ ButtonInstance: null,
+
// List of buttons that receive notifications when the icon changes
ButtonList: [],
@@ -185,6 +186,14 @@ var StackAlert = {
chrome.browserAction.setTitle({title: tooltip});
});
+ } else { // currently only Opera
+
+ StackAlert.GenerateImageData(document, text,
+ function(canvas, context) {
+
+ StackAlert.ButtonInstance.icon = canvas.toDataURL("image/png");
+
+ });
}
},
@@ -297,9 +306,9 @@ var StackAlert = {
else {
var window_url = 'https://stackexchange.com/oauth/dialog?client_id=' + StackAlert.ClientID +
- '&scope=no_expiry,read_inbox&redirect_uri=' + encodeURIComponent(chrome.extension.getURL('auth_complete.html'));
+ '&scope=no_expiry,read_inbox&redirect_uri=' + encodeURIComponent('https://stackexchange.com/oauth/login_success');
- window.open(window_url, 'auth_window', 'width=640,height=400,menubar=no,toolbar=no,location=no,status=no');
+ var new_window = window.open(window_url, 'auth_window', 'width=640,height=400,menubar=no,toolbar=no,location=no,status=no');
}
},
@@ -337,10 +346,7 @@ var StackAlert = {
},
// Completes the authorization process by storing the access token and fetching the data
- CompleteAuthorization: function(browser_location) {
-
- // Trim the '#' from the current hash and split against '&'
- var hash = browser_location.hash;
+ CompleteAuthorization: function(hash) {
if(hash.indexOf('#') === 0)
hash = hash.substr(1);
@@ -388,8 +394,10 @@ var StackAlert = {
// Select the newly opened tab
browser.selectedTab = browser.addTab(url);
- } else
+ } else if(StackAlert.Browser == 'chrome')
chrome.tabs.create({'url': url});
+ else // assume Opera
+ opera.extension.bgProcess.opera.extension.tabs.create({'url': url, 'focused': true});
},
View
1 opera/auth_complete.html
@@ -0,0 +1 @@
+Hello!
View
0 opera/button.png → opera/badge.png
File renamed without changes
View
2 opera/config.xml
@@ -4,4 +4,6 @@
<description>Displays the number of unread inbox items from your Stack Exchange accounts.</description>
<author href="http://quickmediasolutions.com" email="admin@quickmediasolutions.com">Nathan Osman</author>
<icon src="icon.png"/>
+
+ <access origin="https://api.stackexchange.com"/>
</widget>
View
15 opera/includes/auth.user.js
@@ -0,0 +1,15 @@
+// ==UserScript==
+// @include https://stackexchange.com/oauth/login_success*
+// ==/UserScript==
+
+// Close this window.
+window.addEventListener('load', function() {
+
+ // Send the access token to the background script
+ // which will store it for later usage.
+ opera.extension.postMessage(window.location.hash);
+
+ // Close the window
+ window.close();
+
+}, true);
View
54 opera/index.html
@@ -1,27 +1,41 @@
<!DOCTYPE html>
<html>
<head>
-<script>
-
-window.addEventListener("load", function(){
+ <script src='stackalert.js'></script>
+ <script src='opera.js'></script>
+ <script>
+
+ window.addEventListener("load", function(){
- var button;
- var ToolbarUIItemProperties = {
- title: "Stack Alert",
- icon: "button.png",
- popup: {
- href: "popup.html",
- width: 110,
- height: 30
- }
- };
-
- button = opera.contexts.toolbar.createItem(ToolbarUIItemProperties);
- opera.contexts.toolbar.addItem(button);
-
-}, false);
-
-</script>
+ var button;
+ var ToolbarUIItemProperties = {
+ title: "Stack Alert",
+ icon: "badge.png",
+ popup: {
+ href: "popup.html",
+ width: 320,
+ height: 300
+ }
+ };
+
+ button = opera.contexts.toolbar.createItem(ToolbarUIItemProperties);
+ opera.contexts.toolbar.addItem(button);
+
+ StackAlert.ButtonInstance = button;
+
+ // Begin the update
+ StackAlert.PerformUpdate();
+
+ }, false);
+
+ opera.extension.onmessage = function(event) {
+
+ // NOT GOOD - we are silently discarding the error message
+ StackAlert.CompleteAuthorization(event.data);
+
+ };
+
+ </script>
</head>
<body>
</body>
View
6 opera/opera.js
@@ -0,0 +1,6 @@
+// This file sets the browser and API key for Opera
+
+StackAlert.Browser = 'opera';
+StackAlert.IconSize = '18';
+StackAlert.APIKey = '0WFcdwLcxOFOTzTXArczrg((';
+StackAlert.ClientID = '56';
View
13 opera/popup.html
@@ -1,9 +1,18 @@
<!DOCTYPE html>
<html>
<head>
- <title>Hello World!</title>
+ <link href="style.css" rel="stylesheet" />
+ <script src='stackalert.js'></script>
+ <script src='opera.js'></script>
</head>
<body>
- [CONTENT GOES HERE]
+ <script>
+
+ var div = document.createElement('div');
+ StackAlert.GeneratePopupHTML(window, div);
+
+ document.getElementsByTagName('body')[0].appendChild(div);
+
+ </script>
</body>
</html>

0 comments on commit 9bf8ec8

Please sign in to comment.