Permalink
Browse files

Merged foletto's fork.

Upgraded to manifest v2 which caused some minor adjustments in the notification popup.

The new pinterest-1.0.js library doesn't appear to handle the condition where the user has logged out while the context menu is still populated.
  • Loading branch information...
1 parent f20f680 commit b0e94f9875b9d019de579693e5de6c1c5cd9eca8 @williamparry committed May 26, 2012
Showing with 247 additions and 205 deletions.
  1. +0 −10 src/background.html
  2. +54 −86 src/background.js
  3. +49 −8 src/becausemac.js
  4. +21 −4 src/manifest.json
  5. +4 −93 src/notification-pinned.html
  6. +115 −0 src/notification.js
  7. +4 −4 src/pinterest-1.0.js
View
@@ -1,10 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title></title>
- <script src="pinterest-1.0.js"></script>
- <script src="background.js"></script>
- </head>
- <body>
- </body>
-</html>
View
@@ -1,13 +1,38 @@
/*
-Copyright William Parry 2012
-
-This script is intended for general use and no warranty is implied for suitability to any given task.
-I hold no responsibility for your setup or any damage done while using/installing/modifing this script.
+* background.js
+*
+* Last update: 2012-05-26
+*
+* ==========================================================================================
+*
+* Copyright (c) 2012, William Parry.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are
+* permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this list of
+* conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials
+* provided with the distribution.
+* Neither the name of the Pinterest.js library nor the names of its contributors may be used to
+* endorse or promote products derived from this software without specific prior written
+* permission.
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
*/
-// **************************************************************************************************** INTERNAL
-var pinterestedTabs = [];
-var timerSchedule = null;
+var pinterestedTabs = [],
+ timerSchedule = null;
function startSchedule() {
// Prepare
@@ -49,29 +74,27 @@ function makeLoggedOutMenu() {
// **************************************************************************************************** PINTEREST CALLS
function getBoards() {
- Pinterest.getBoards(function __getBoards(boards) {
- console.log(boards);
- if (boards.length > 0) {
- // We have boards, let's create the menu
-
- chrome.contextMenus.removeAll();
- var contextMenuImage = chrome.contextMenus.create({ "title": "Pin image to", "contexts": ["image"] });
-
- for (var i = 0; i < boards.length; i++) {
- (function (board) {
- chrome.contextMenus.create({ "title": board.title, "contexts": ["image"],
- "onclick": function (obj) {
- pin(board.id, obj.srcUrl);
- }, "parentId": contextMenuImage
- });
- })(boards[i]);
- }
-
- } else {
- // Uh oh, no boards.
- handleLoggedOut();
- }
- });
+ Pinterest.getBoards(function (boards) {
+
+ if (boards.length > 0) {
+
+ chrome.contextMenus.removeAll();
+ var contextMenuImage = chrome.contextMenus.create({ "title": "Pin image to", "contexts": ["image"] });
+
+ for (var i = 0; i < boards.length; i++) {
+ (function (board) {
+ chrome.contextMenus.create({ "title": board.title, "contexts": ["image"],
+ "onclick": function (obj) {
+ pin(board.id, obj.srcUrl);
+ }, "parentId": contextMenuImage
+ });
+ })(boards[i]);
+ }
+
+ } else {
+ handleLoggedOut();
+ }
+ });
}
@@ -151,63 +174,8 @@ function pin(board, media_url, title) {
setInactive();
});
- });
-
- /* From Pinterest.js
- var params = {
- media_url: mediaURL,
- description: description,
- pin_id: xmlDOM.querySelectorAll(".pinSuccess ul li:first-child a")[0].href.split('/')[4],
- board_id: boardId,
- board_name: xmlDOM.querySelectorAll(".pinSuccess h3 a")[0].innerHTML
- }
- */
-
- /*setActive();
- chrome.tabs.getSelected(null, function (tab) {
- title = title ? title : tab.title;
- var xhr = new XMLHttpRequest();
- xhr.open("POST", "http://pinterest.com/pin/create/bookmarklet/", true);
- xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4) {
- if (xhr.status === 200) {
- updateBody(xhr.responseText);
- var data = {
- tab_id: tab.id,
- url: tab.url,
- media_url: media_url,
- description: title,
- pin_id: document.querySelectorAll(".pinSuccess ul li:first-child a")[0].href.split('/')[4],
- board_id: board,
- board_name: document.querySelectorAll(".pinSuccess h3 a")[0].innerHTML
- }
-
- if (pinterestedTabs.indexOf(tab.id) !== -1) {
- chrome.tabs.sendRequest(tab.id, data);
- } else {
- 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();
- setTimeout(function () { notification.cancel(); }, 3000);
-
- handleLoggedOut();
- }
+});
- setInactive();
- }
- };
- xhr.send("board=" + board + "&currency_holder=buyable&peeps_holder=replies&tag_holder=tags&title=" + title + "&media_url=" + encodeURIComponent(media_url) + "&url=" + encodeURIComponent(tab.url) + "&csrfmiddlewaretoken=" + token + "&caption=" + title);
- });*/
}
View
@@ -1,16 +1,46 @@
-var QIHEIGHT = 100;
+/*
+* becausemac.js
+*
+* Last update: 2012-05-26
+*
+* ==========================================================================================
+*
+* Copyright (c) 2012, William Parry.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are
+* permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this list of
+* conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials
+* provided with the distribution.
+* Neither the name of the Pinterest.js library nor the names of its contributors may be used to
+* endorse or promote products derived from this software without specific prior written
+* permission.
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+* ----------------------------------------------------------------------------------------------
+* Why does this file exist? webkitnotifications fail on mac
+* ----------------------------------------------------------------------------------------------
+*/
+var QIHEIGHT = 100;
function notify(data) {
- /*****************************************************************************************************
- * Creates the notification panel
- * This script is going to be loaded once per tab, see the pin() function in background.js
- */
-
+
var existingIframes = document.querySelectorAll(".quick-pinterest-notification");
var EIFrame = document.createElement("iframe");
- // Define iframe
EIFrame.style.position = "absolute";
EIFrame.style.top = document.body.scrollTop + (existingIframes.length * QIHEIGHT) + 5 + "px";
EIFrame.style.right = "5px";
@@ -19,7 +49,18 @@ function notify(data) {
EIFrame.style.height = EIFrame.height = QIHEIGHT + "px";
EIFrame.style.width = EIFrame.width = "350px";
EIFrame.frameBorder = "0";
-
+
+ var canvas = document.createElement('canvas'),
+ ctx = canvas.getContext('2d');
+ img = document.querySelectorAll("img[src='" + data.media_url + "']")[0];
+
+ // Take THAT CSP
+ canvas.width = img.width;
+ canvas.height = img.height;
+ ctx.drawImage(img, 0, 0);
+
+ data.imgData = canvas.toDataURL();
+
// Load & attach the notification HTML
EIFrame.src = chrome.extension.getURL("notification-pinned.html?r=" + (Math.random() * 999999) + "#data=" + JSON.stringify(data));
document.body.appendChild(EIFrame);
View
@@ -1,10 +1,27 @@
{
+ "manifest_version" : 2,
"name": "Quick Pinterest",
"description": "Pin your favourite images using the context menu. No popups.",
- "version": "1.5",
+ "version": "1.6",
"icons": { "16": "img/logo.png", "48": "img/logo.png", "128": "img/logo.png" },
- "permissions": ["contextMenus","http://pinterest.com/pin/create/bookmarklet/", "notifications", "tabs", "https://*/*", "http://*/*"],
- "background_page": "background.html",
- "minimum_chrome_version": "7",
+ "permissions": [
+ "contextMenus",
+ "http://pinterest.com/pin/create/bookmarklet/",
+ "notifications",
+ "tabs",
+ "https://*/*",
+ "http://*/*"
+ ],
+ "web_accessible_resources": [
+ "img/icon.png",
+ "notification-pinned.html"
+ ],
+ "background": {
+ "scripts": [
+ "pinterest-1.0.js",
+ "background.js"
+ ]
+ },
+ "minimum_chrome_version": "18",
"browser_action": { "default_icon": "img/icon.png"}
}
@@ -145,101 +145,12 @@ <h1 id="title"></h1>
<div id="error">Error :( Please try again.</div>
<div id="progress" />
</div>
- </body>
- <script>
- // **************************************************************************************************** SCRIPT
- var countDownAmount = 5000;
- var currentCount = countDownAmount;
- var countDown = null;
- var data = JSON.parse(window.location.hash.split('#data=')[1]);
+ <script src="notification.js"></script>
+
+ </body>
- window.onload = function () {
- /*****************************************************************************************************
- * Update the form with the right data.
- */
- 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;
-
-
- // ****** On image load set correct image thumbnail size
- img.src = data.media_url;
-
- img.onload = function () {
- if (this.width >= this.height) {
- this.width = Math.min(45, this.width);
- } else {
- this.height = Math.min(45, this.height);
- }
- img.style.display = "block";
- }
-
- // ****** Update Pin button
- document.getElementById("frmUpdate").onsubmit = function (e) {
- e.preventDefault();
- error.style.display = "none";
- txtDescription.disabled = "disabled";
- btnUpdate.disabled = "disabled";
- btnUpdate.value = "Updating...";
-
- data.description = txtDescription.value;
-
- chrome.extension.sendRequest({ Data: data }, function (success) {
- if (success) {
- btnUpdate.value = "Updated!";
- setTimeout(function () {
- close();
- }, 2000);
- } else {
- error.style.display = "block";
- txtDescription.removeAttribute("disabled");
- btnUpdate.removeAttribute("disabled");
- btnUpdate.value = "Update";
- }
- });
- }
-
- // ****** Countdown
- var EProgress = document.getElementById("progress");
- countDown = setInterval(function () {
- currentCount -= 50;
- if (currentCount == 0) {
- close();
- } else {
- EProgress.style.width = Math.round((currentCount / countDownAmount) * 100) + "%";
- }
- }, 50);
-
- // ****** Description text field: when clicked, stop countdown
- txtDescription.placeholder = data.description;
- txtDescription.onclick = removeProgressBar;
- btnUpdate.onclick = removeProgressBar;
- }
-
- function close() {
- /*****************************************************************************************************
- * Send message back to becausemac.js to remove iframe
- */
- parent.postMessage(data.pin_id, data.page_url);
- }
-
- function removeProgressBar() {
- /*****************************************************************************************************
- * Remove the progress bar timer and indicator
- */
- clearInterval(countDown);
- countDown = null;
-
- var EProgress = document.getElementById("progress");
- if (EProgress) {
- document.getElementById("main").removeChild(EProgress);
- }
- }
- </script>
+
</html>
Oops, something went wrong.

0 comments on commit b0e94f9

Please sign in to comment.