Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit 68b0cc8ec58c37be4d24e4bf94f84e3af086b4ab @fracek committed Mar 24, 2012
Showing with 287 additions and 0 deletions.
  1. +26 −0 LICENSE.txt
  2. +20 −0 README.md
  3. +47 −0 bg.html
  4. +11 −0 cs.js
  5. BIN images/icon_128.png
  6. BIN images/icon_16.png
  7. BIN images/icon_19.png
  8. BIN images/icon_48.png
  9. +4 −0 jq.min.js
  10. +26 −0 manifest.json
  11. +130 −0 options.html
  12. +23 −0 popup.html
@@ -0,0 +1,26 @@
+Copyright (c) 2012, Francesco Ceccon
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. 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.
+
+
+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.
@@ -0,0 +1,20 @@
+Amazon Affiliate Link Generator for Chrome
+==========================================
+
+Generate your Amazon affiliate links with one click!
+Click on the icon to see and copy your link.
+
+Usage
+-----
+
+1. Go to the extension's options page
+ Window > Extensions > Amazon Affiliate Link Generator > Options
+2. Put you tracking ID in the input field
+3. Click Save
+4. Visit a product page on Amazon.com
+5. Click on the icon to see and copy your link
+
+License
+-------
+
+See License.txt
47 bg.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script src='jq.min.js'></script>
+ <script>
+ // Global accessor that the popup uses.
+ var items = {};
+ var selectedItem = null;
+ var selectedId = null;
+
+ function updateItem(tabId) {
+ chrome.tabs.sendRequest(tabId, {}, function(item) {
+ items[tabId] = item;
+ if (!item) {
+ chrome.pageAction.hide(tabId);
+ } else {
+ chrome.pageAction.show(tabId);
+ if (selectedId == tabId) {
+ updateSelected(tabId);
+ }
+ }
+ });
+ }
+
+ function updateSelected(tabId) {
+ selectedItem = items[tabId];
+ if (selectedItem)
+ chrome.pageAction.setTitle({tabId:tabId, title:selectedItem});
+ }
+ chrome.tabs.onUpdated.addListener(function(tabId, change, tab) {
+ if (change.status == "complete") {
+ updateItem(tabId);
+ }
+ });
+
+ chrome.tabs.onSelectionChanged.addListener(function(tabId, info) {
+ selectedId = tabId;
+ updateItem(tabId);
+ });
+
+ // Ensure the current selected tab is set up.
+ chrome.tabs.getSelected(null, function(tab) {
+ updateItem(tab.id);
+ });
+ </script>
+ </head>
+</html>
11 cs.js
@@ -0,0 +1,11 @@
+if (window == top) {
+ chrome.extension.onRequest.addListener(function(req, sender, senderResponse) {
+ senderResponse(findItemID());
+ });
+}
+
+function findItemID() {
+ var itemId = document.getElementById('ASIN').value;
+ console.log(itemId);
+ return itemId;
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
@@ -0,0 +1,26 @@
+{
+ "name": "Amazon Affiliate Link Generator",
+ "version": "0.1",
+ "description": "Generate an Amazon affiliate link with one click",
+ "background_page": "bg.html",
+ "icons": {
+ "16": "images/icon_16.png",
+ "48": "images/icon_48.png",
+ "128": "images/icon_128.png"
+ },
+ "permissions": [
+ "tabs"
+ ],
+ "page_action": {
+ "default_icon": "images/icon_19.png",
+ "default_popup": "popup.html"
+ },
+ "content_scripts": [
+ {
+ "matches": ["http://*.amazon.com/*"],
+ "css": [],
+ "js": ["cs.js"]
+ }
+ ],
+ "options_page": "options.html"
+}
@@ -0,0 +1,130 @@
+<html>
+ <head>
+ <title>Options for Amazon Affiliate Link Generator</title>
+ <script src="jq.min.js"></script>
+ <script type="text/javascript">
+ function restoreOptions() {
+ var trackId = localStorage['trackId'];
+ if (!trackId)
+ return;
+ $('#tracking-id-text').val(trackId);
+ }
+
+ function hideStatus() {
+ setTimeout(function() {
+ $('#status').slideUp('slow');
+ }, 2000);
+ }
+
+ function saveOptions() {
+ var trackId = $('#tracking-id-text').val();
+ console.log(trackId);
+ if (trackId && trackId.length > 0) {
+ localStorage['trackId'] = trackId;
+ var successBlock = "<span class='success'>Options Saved</span>";
+ $('#status').html(successBlock);
+ $('#status').slideDown('slow', hideStatus());
+ } else {
+ var errorBlock = "<span class='error'>UHO, something went wrong</span>";
+ $('#status').html(errorBlock);
+ $('#status').slideDown('slow', hideStatus());
+ }
+ }
+ </script>
+ <style>
+ body {
+ font-family: 'Lucida Grande', sans-serif;
+ color: hsl(210, 16%, 22%);
+ }
+
+ #content {
+ width: 600px;
+ margin: 0px auto;
+ }
+
+ #status {
+ display: hidden;
+ margin: 20px 0px;
+ }
+
+ #status span {
+ display: block;
+ width: 590px;
+ border-radius: 5px;
+ padding: 8px 5px;
+ }
+
+ .success {
+ border: 1px solid hsl(81,91%,31%);
+ background-color: hsl(81,91%,91%);
+ }
+
+ .error {
+ border: 1px solid hsl(0,64%,50%);
+ background-color: hsl(0,64%,90%);
+ }
+
+ header {
+ font-size: 75%;
+ border-bottom: 1px solid #EEEEEE;
+ margin-bottom: 20px;
+ }
+
+ #options {
+ font-size: 75%;
+ }
+
+ input[type="text"] {
+ border: 1px solid hsl(0, 0%, 75%);
+ border-radius: 2px;
+ box-sizing: border-box;
+ font: inherit;
+ height: 2em;
+ margin: 0;
+ padding: 3px;
+ }
+
+ button {
+ margin-top: 14px;
+ background-color: silver;
+ height: 2em;
+ min-width: 8em;
+ -webkit-appearance: none;
+ -webkit-user-select: none;
+ background-image: -webkit-linear-gradient(
+ hsl(0, 0%, 93%),
+ hsl(0, 0%, 93%) 38%,
+ hsl(0, 0%, 87%));
+ border-radius: 2px;
+ border: 1px solid hsla(0, 0%, 0%, 0.25);
+ box-shadow: 0 1px 0 hsla(0, 0%, 0%, 0.08), inset 0 1px 2px hsla(0, 100%, 100%, 0.75);
+ color: hsl(0, 0%, 27%);
+ font: inherit;
+ text-shadow: 0 1px 0 hsl(0, 0%, 94%);
+
+ }
+
+ button:active {
+ background-image: -webkit-linear-gradient(#e7e7e7, #e7e7e7 38%, #d7d7d7);
+ box-shadow: none;
+ text-shadow: none;
+ }
+ </style>
+ </head>
+ <body onload="restoreOptions()">
+ <div id="content">
+ <header>
+ <h1>Options for Amazon Affiliate Link Generator</h1>
+ </header>
+ <div id="status">
+ </div>
+ <div id="options">
+ <label for="tracking-id-text">Your tracking id:</label>
+ <input id="tracking-id-text" type="text" placeholder="homer-12" />
+ <br/>
+ <button onClick="saveOptions()">Save</button>
+ </div>
+ </div>
+
+ </body>
+</html>
@@ -0,0 +1,23 @@
+<html>
+ <head>
+ <title>Popup</title>
+ </head>
+ <body>
+ <input type="text" id="txt" />
+ </body>
+ <script src="jq.min.js"></script>
+ <script>
+ function buildLink(item) {
+ return 'http://www.amazon.com/dp/' + item + '/?tag='
+ + localStorage['trackId'];
+ }
+
+ window.onload = function() {
+ var item = chrome.extension.getBackgroundPage().selectedItem;
+ if (item) {
+ var link = buildLink(item);
+ $('#txt').val(link);
+ }
+ }
+ </script>
+</html>

0 comments on commit 68b0cc8

Please sign in to comment.