Browse files

Updates the method for creating the popup window (now uses chrome.win…

…dows.create) Using new method to close the popup window since the delicious.com redesign.

We now send the ID of the popup window the extension created, to the
onUpdated listener. We then check for that ID via the onUpdated
listener, and if it's URL does not 'start with' delcious.com/save then
it's safe to close our window. A bit janky, I assume, but it's doing
the trick. Also, commented out the options that were previously
available when you clicked the extensions icon. Instead, it just
initiates the 'save' popup.
  • Loading branch information...
1 parent e1e8b23 commit 05846efe59c48025f97c8bb77042e8cea51cdd64 @billkeller committed Sep 28, 2011
Showing with 53 additions and 21 deletions.
  1. +50 −18 background.html
  2. +3 −3 popup.html
View
68 background.html
@@ -1,16 +1,46 @@
<html>
<script>
+
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
- // alert('tab has been updated');
- if(changeInfo.status == "loading") {
- if(tab.url == "http://www.delicious.com/save") {
- chrome.tabs.remove(tabId);
- }
- }
+
+ if(changeInfo.status == "loading") {
+
+ chrome.windows.getCurrent(function(w) {
+ chrome.tabs.getSelected(w.id,
+ function (response){
+ // alert(ourWindow);
+ // alert(response.id);
+ if(response.id == ourWindow) {
+ // You're here because this is the ID of the popup window our extension created
+ // alert('Found this puppy');
+
+ if (typeof String.prototype.startsWith != 'function') {
+ String.prototype.startsWith = function (str){
+ return this.slice(0, str.length) == str;
+ };
+ }
+
+ var data = tab.url
+ var input = 'http://delicious.com/save?'
+
+ if(data.startsWith(input)) {
+ // alert('This URL contains SAVE in it');
+ } else {
+ chrome.tabs.remove(tabId);
+ }
+ }
+
+
+ });
+ });
+
+ }
+
});
+
chrome.extension.onRequest.addListener(
function(message, sender, sendResponse) {
- console.log("background loaded");
+ // console.log("background loaded");
if (message.action && sender.tab) {
switch (message.action) {
case 'getFromLocalStorage':
@@ -36,7 +66,7 @@
});
(function() {
- // Respond to messages passed from content script
+ // Respond to messages passed from addDelicous.js content script
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.type === 'addDelicious') {
@@ -59,20 +89,22 @@
fullUrl = deliciousUrl + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&notes=' + encodeURIComponent(notes);
- window.open(
- fullUrl,
- 'deliciousuiv5',
- 'location=yes,links=no,scrollbars=no,toolbar=no,width=' + w.toString() + ',height=' + h.toString()
- );
-
- /*
// Chrome's API for creating windows (rather than simple window.open)
chrome.windows.create({
- url: deliciousUrl + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&notes=' + encodeURIComponent(notes),
+ url: fullUrl,
width: w,
- height: h
+ height: h,
+ type: 'popup'
+ }, function() {
+ chrome.windows.getCurrent(function(window) {
+ chrome.tabs.getSelected(window.id,
+ function (response){
+ ourWindow = response.id
+ // alert('Our window has a tab id of: ' + ourWindow);
+ });
+ });
});
- */
+
};
})();
View
6 popup.html
@@ -18,9 +18,9 @@
</script>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
- <body class="delicious">
- <div class="toolstrip-button" onclick="startPopup()">Save a new Bookmark</div>
+ <body class="delicious" onload="startPopup()">
+ <!-- div class="toolstrip-button" onclick="startPopup()">Save a new Bookmark</div>
<div class="toolstrip-button" onclick="window.open('http://del.icio.us/home/')">Bookmarks on Delicious</div>
- <div class="toolstrip-button" onclick="window.open('http://del.icio.us/inbox/')">Delicious Inbox</div>
+ <div class="toolstrip-button" onclick="window.open('http://del.icio.us/inbox/')">Delicious Inbox</div -->
</body>
</html>

0 comments on commit 05846ef

Please sign in to comment.