Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit b0e94f9875b9d019de579693e5de6c1c5cd9eca8 1 parent f20f680
William Parry authored
10 src/background.html
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>
140 src/background.js
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);
- });*/
}
57 src/becausemac.js
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);
25 src/manifest.json
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"}
}
97 src/notification-pinned.html
View
@@ -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>
115 src/notification.js
View
@@ -0,0 +1,115 @@
+/*
+* notification.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.
+*
+*/
+
+window.onload = function () {
+
+
+ function close() {
+ parent.postMessage(data.pin_id, data.page_url); // ask parent to remove
+ }
+
+ function removeProgressBar() {
+ clearInterval(countDown);
+ countDown = null;
+
+ var EProgress = document.getElementById("progress");
+ if (EProgress) {
+ document.getElementById("main").removeChild(EProgress);
+ }
+ }
+
+ function id(e) { return document.getElementById(e); }
+
+ var countDownAmount = 5000,
+ currentCount = countDownAmount,
+ countDown = null,
+ data = JSON.parse(window.location.hash.split('#data=')[1]),
+ title = id("title"),
+ txtDescription = id("txtDescription"),
+ btnUpdate = id("btnUpdate"),
+ form = id("frmUpdate"),
+ error = id("error"),
+ img = id("imgMain");
+
+
+ title.innerHTML = 'Pinned to ' + data.board_name;
+
+ img.src = data.imgData; // from canvas
+
+ 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";
+ }
+
+ form.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";
+ }
+ });
+ }
+
+ var EProgress = document.getElementById("progress");
+ countDown = setInterval(function () {
+ currentCount -= 50;
+ if (currentCount == 0) {
+ close();
+ } else {
+ EProgress.style.width = Math.round((currentCount / countDownAmount) * 100) + "%";
+ }
+ }, 50);
+
+ txtDescription.placeholder = data.description;
+ txtDescription.onclick = removeProgressBar;
+ btnUpdate.onclick = removeProgressBar;
+}
8 src/pinterest-1.0.js
View
@@ -69,7 +69,7 @@ var Pinterest = {
fx(this.boards); // CALLBACK -->
} else {
// ****** Boards are missing, get them implicitly.
- this.initConfiguration(function __initConfigurationImplicitFromGetBoards() {
+ this.initConfiguration(function () {
if (self.boards) fx(self.boards); // CALLBACK -->
else fx(null); // CALLBACK -->
});
@@ -85,7 +85,7 @@ var Pinterest = {
if (!this.token) {
// ****** Token is missing, get it implicitly.
- this.initConfiguration(function __initConfigurationImplicitFromPin() {
+ this.initConfiguration(function () {
if (self.token) self.pin(boardId, mediaURL, description, fx); // if token was retrieved, try again pinning
else fx(401); // CALLBACK -->
});
@@ -136,7 +136,7 @@ var Pinterest = {
fx(this.token); // CALLBACK -->
} else {
// ****** Token is missing, get it implicitly.
- this.initConfiguration(function __initConfigurationImplicitFromGetToken() {
+ this.initConfiguration(function () {
fx(self.token); // CALLBACK -->
});
}
@@ -152,7 +152,7 @@ var Pinterest = {
*/
var self = this;
- this.getConfiguration(function ____getConfigurationImplicitFromInitConfiguration(token, boards) {
+ this.getConfiguration(function (token, boards) {
if (token) {
// ****** Success, set the values
self.token = token;
Please sign in to comment.
Something went wrong with that request. Please try again.