Skip to content
Browse files

Changed notification system for mac users.

  • Loading branch information...
1 parent 47dacbb commit 01be373a81aeea272b4d24a74944ee0e500a0ec5 @williamparry committed Mar 15, 2012
Showing with 120 additions and 50 deletions.
  1. +7 −1 README
  2. +24 −14 src/background.js
  3. +32 −0 src/becausemac.js
  4. +2 −2 src/manifest.json
  5. +55 −33 src/notification-pinned.html
View
8 README
@@ -1,2 +1,8 @@
Copyright (C) 2012, William Parry
-Licensed under BSD License
+Licensed under BSD License
+
+
+=== Version 1.5 ===
+
+Rebuilt notifications to embed an iframe so mac users get a better experience.
+Fixed a potential problem with the location hash splitting in the notification script
View
38 src/background.js
@@ -9,7 +9,8 @@ var boardsSchedule,
boardsScheduleIsRunning = false,
tokenSchedule,
tokenScheduleIsRunning = false,
- token;
+ token,
+ pinterestedTabs = [];
function updateBody(str) {
var range = document.createRange();
@@ -94,9 +95,7 @@ function getBoards() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
chrome.contextMenus.removeAll();
- var contextMenuImage = chrome.contextMenus.create({ "title": "Pin image to", "contexts": ["image"] }),
- contextMenuVideo = chrome.contextMenus.create({ "title": "Pin video to", "contexts": ["video"] });
-
+ var contextMenuImage = chrome.contextMenus.create({ "title": "Pin image to", "contexts": ["image"] });
updateBody(xhr.responseText);
var boardList = document.querySelectorAll(".BoardList ul li");
for (var i = 0; i < boardList.length; i++) {
@@ -107,11 +106,6 @@ function getBoards() {
pin(board.getAttribute('data'), obj.srcUrl);
}, "parentId": contextMenuImage
});
- chrome.contextMenus.create({ "title": boardTitle, "contexts": ["video"],
- "onclick": function (obj) {
- pin(board.getAttribute('data'), obj.pageUrl);
- }, "parentId": contextMenuVideo
- });
})(boardList[i]);
}
} else {
@@ -126,6 +120,7 @@ function getBoards() {
// Edit pin
+
chrome.extension.onRequest.addListener(function (resp, sender, sendResponse) {
setActive();
var xhr = new XMLHttpRequest();
@@ -149,9 +144,9 @@ chrome.extension.onRequest.addListener(function (resp, sender, sendResponse) {
xhr.send("details=" + resp.Data.description + "&link=" + resp.Data.url + "&board=" + resp.Data.board_id + "&csrfmiddlewaretoken=" + token);
-});
+});
function pin(board, media_url, title) {
setActive();
@@ -164,7 +159,8 @@ function pin(board, media_url, title) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
updateBody(xhr.responseText);
- var params = {
+ var data = {
+ tab_id: tab.id,
url: tab.url,
media_url: media_url,
description: title,
@@ -173,11 +169,18 @@ function pin(board, media_url, title) {
board_name: document.querySelectorAll(".pinSuccess h3 a")[0].innerHTML
}
- if (navigator.appVersion.indexOf("Mac") != -1) {
- chrome.windows.create({ url: "notification-pinned.html#" + JSON.stringify(params), type: "popup", width: 350, height: 150 });
+ if (pinterestedTabs.indexOf(tab.id) !== -1) {
+ chrome.tabs.sendRequest(tab.id, data);
} else {
- var notification = webkitNotifications.createHTMLNotification("notification-pinned.html#" + JSON.stringify(params)).show();
+ pinterestedTabs.push(tab.id);
+ chrome.tabs.executeScript(tab.id, { file: "becausemac.js" }, function () {
+ chrome.tabs.sendRequest(tab.id, data);
+ });
}
+
+
+
+
} else {
var notification = webkitNotifications.createNotification("img/logo.png", "You're logged out!", "Please log into Pinterest and try again.");
notification.show();
@@ -197,4 +200,11 @@ chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({ "url": "http://pinterest.com/", "selected": true });
});
+chrome.tabs.onRemoved.addListener(function (tabid) {
+ var ind = pinterestedTabs.indexOf(tabid);
+ if (ind !== -1) {
+ pinterestedTabs.splice(ind, 1);
+ }
+});
+
startTokenSchedule();
View
32 src/becausemac.js
@@ -0,0 +1,32 @@
+var QIHEIGHT = 100;
+
+function notify(data) {
+
+
+ var existingIframes = document.querySelectorAll(".quick-pinterest-notification");
+
+ var EIFrame = document.createElement("iframe");
+
+ EIFrame.style.position = "absolute";
+ EIFrame.style.top = document.body.scrollTop + (existingIframes.length * QIHEIGHT) + 5 + "px";
+ EIFrame.style.right = "5px";
+ EIFrame.style.zIndex = "100000000";
+ EIFrame.className = "quick-pinterest-notification";
+ EIFrame.style.height = EIFrame.height = QIHEIGHT + "px";
+ EIFrame.style.width = EIFrame.width = "350px";
+ EIFrame.frameBorder = "0";
+
+ EIFrame.src = chrome.extension.getURL("notification-pinned.html?r=" + (Math.random() * 999999) + "#data=" + JSON.stringify(data));
+
+ document.body.appendChild(EIFrame);
+
+ window.addEventListener("message", function (event) {
+ if (event.data == data.pin_id) {
+ document.body.removeChild(EIFrame);
+ window.removeEventListener("message", arguments.callee);
+ }
+ }, false);
+}
+
+
+chrome.extension.onRequest.addListener(notify);
View
4 src/manifest.json
@@ -1,9 +1,9 @@
{
"name": "Quick Pinterest",
"description": "Pin your favourite images using the context menu. No popups.",
- "version": "1.4",
+ "version": "1.5",
"icons": { "16": "img/logo.png", "48": "img/logo.png", "128": "img/logo.png" },
- "permissions": ["contextMenus","http://pinterest.com/pin/create/bookmarklet/", "notifications", "tabs"],
+ "permissions": ["contextMenus","http://pinterest.com/pin/create/bookmarklet/", "notifications", "tabs", "https://*/*", "http://*/*"],
"background_page": "background.html",
"minimum_chrome_version": "7",
"browser_action": { "default_icon": "img/icon.png"}
View
88 src/notification-pinned.html
@@ -13,9 +13,22 @@
<style type="text/css">
+ html,
+ body {
+ background: transparent;
+ }
+
body {
- padding: 10px;
font-family: "helvetica neue",arial,sans-serif;
+ overflow: hidden;
+ padding: 5px;
+ }
+
+ #main {
+ padding: 10px;
+ position: relative;
+ box-shadow: inset 0 0 5px rgb(34,25,25);
+ background: #FCF9F9;
}
h1 {
@@ -94,14 +107,16 @@
clear: both;
}
- progress {
+ #progress {
position: absolute;
left: 0;
- bottom: 0;
+ bottom: 0px;
width: 100%;
height: 2px;
+ background: #8C7E7E;
}
+
#error {
color: #CB2027;
font-size: 10px;
@@ -116,44 +131,48 @@
</head>
<body>
-
- <h1 id="title"></h1>
- <div id="wrap">
- <img id="imgMain" />
-
- <form id="frmUpdate">
- <input type="text" id="txtDescription" placeholder="Add description" required />
- <input type="submit" id="btnUpdate" value="Update Pin" />
- </form>
-
-
+ <div id="main">
+
+ <h1 id="title"></h1>
+ <div id="wrap">
+ <img id="imgMain" />
+ <form id="frmUpdate">
+ <input type="text" id="txtDescription" placeholder="Add description" required />
+ <input type="submit" id="btnUpdate" value="Update Pin" />
+ </form>
+ </div>
+ <div id="error">Error :( Please try again.</div>
+ <div id="progress" />
</div>
-
- <div id="error">Error :( Please try again.</div>
-
- <progress id="progress" value="100" max="100"></progress>
-
+ </body>
<script>
-
- var countDownAmount = 5000;
- var currentCount = countDownAmount;
-
- var data = JSON.parse(window.location.hash.split('#')[1]);
+ var countDownAmount = 5000,
+ currentCount = countDownAmount,
+ data = JSON.parse(window.location.hash.split('#data=')[1]),
+ EMain;
+
- window.onload = function () {
+ function close() {
+ parent.postMessage(data.pin_id, data.url);
+ }
- document.getElementById("title").innerHTML = 'Pinned to ' + data.board_name;
+ window.onload = function () {
- var progress = document.getElementById("progress");
+ EMain = document.getElementById("main"),
+ EProgress = document.getElementById("progress");
+
var txtDescription = document.getElementById("txtDescription");
var btnUpdate = document.getElementById("btnUpdate");
var error = document.getElementById("error");
-
var img = document.getElementById("imgMain");
+ document.getElementById("title").innerHTML = 'Pinned to ' + data.board_name;
+
+
+
img.src = data.media_url;
img.onload = function () {
@@ -178,7 +197,7 @@ <h1 id="title"></h1>
if (success) {
btnUpdate.value = "Updated!";
setTimeout(function () {
- window.close();
+ close();
}, 2000);
} else {
error.style.display = "block";
@@ -193,9 +212,9 @@ <h1 id="title"></h1>
var countDown = setInterval(function () {
currentCount -= 50;
if (currentCount == 0) {
- window.close();
+ close();
} else {
- progress.value = (currentCount / countDownAmount) * 100;
+ EProgress.style.width = Math.round((currentCount / countDownAmount) * 100) + "%";
}
}, 50);
@@ -204,7 +223,10 @@ <h1 id="title"></h1>
txtDescription.onclick = btnUpdate.onclick = function () {
clearInterval(countDown);
countDown = null;
- document.body.removeChild(progress);
+ if (EProgress) {
+ EMain.removeChild(EProgress);
+ }
+
}
@@ -215,5 +237,5 @@ <h1 id="title"></h1>
</script>
- </body>
+
</html>

0 comments on commit 01be373

Please sign in to comment.
Something went wrong with that request. Please try again.