Permalink
Browse files

Add other amazon stores

  • Loading branch information...
1 parent 66e3bb0 commit d2c917363f91c286967af98484e9266c6f4a4f57 @fracek committed Apr 9, 2012
Showing with 189 additions and 15 deletions.
  1. +9 −3 cs.js
  2. +159 −0 jquery.url.js
  3. +12 −5 manifest.json
  4. +9 −7 popup.html
View
12 cs.js
@@ -5,7 +5,13 @@ if (window == top) {
}
function findItemID() {
- var itemId = document.getElementById('ASIN').value;
- console.log(itemId);
- return itemId;
+ if (window.location.host === 'www.amazon.de') {
+ var itemId = document.getElementsByName('ASIN.0')[0].value;
+ console.log(itemId);
+ return itemId;
+ } else {
+ var itemId = document.getElementById('ASIN').value;
+ console.log(itemId);
+ return itemId;
+ }
}
View
@@ -0,0 +1,159 @@
+// JQuery URL Parser plugin - https://github.com/allmarkedup/jQuery-URL-Parser
+// Written by Mark Perkins, mark@allmarkedup.com
+// License: http://unlicense.org/ (i.e. do what you want with it!)
+
+;(function($, undefined) {
+
+ var tag2attr = {
+ a : 'href',
+ img : 'src',
+ form : 'action',
+ base : 'href',
+ script : 'src',
+ iframe : 'src',
+ link : 'href'
+ },
+
+ key = ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","fragment"], // keys available to query
+
+ aliases = { "anchor" : "fragment" }, // aliases for backwards compatability
+
+ parser = {
+ strict : /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, //less intuitive, more accurate to the specs
+ loose : /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs
+ },
+
+ querystring_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g, // supports both ampersand and semicolon-delimted query string key/value pairs
+
+ fragment_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g; // supports both ampersand and semicolon-delimted fragment key/value pairs
+
+ function parseUri( url, strictMode )
+ {
+ var str = decodeURI( url ),
+ res = parser[ strictMode || false ? "strict" : "loose" ].exec( str ),
+ uri = { attr : {}, param : {}, seg : {} },
+ i = 14;
+
+ while ( i-- )
+ {
+ uri.attr[ key[i] ] = res[i] || "";
+ }
+
+ // build query and fragment parameters
+
+ uri.param['query'] = {};
+ uri.param['fragment'] = {};
+
+ uri.attr['query'].replace( querystring_parser, function ( $0, $1, $2 ){
+ if ($1)
+ {
+ uri.param['query'][$1] = $2;
+ }
+ });
+
+ uri.attr['fragment'].replace( fragment_parser, function ( $0, $1, $2 ){
+ if ($1)
+ {
+ uri.param['fragment'][$1] = $2;
+ }
+ });
+
+ // split path and fragement into segments
+
+ uri.seg['path'] = uri.attr.path.replace(/^\/+|\/+$/g,'').split('/');
+
+ uri.seg['fragment'] = uri.attr.fragment.replace(/^\/+|\/+$/g,'').split('/');
+
+ // compile a 'base' domain attribute
+
+ uri.attr['base'] = uri.attr.host ? uri.attr.protocol+"://"+uri.attr.host + (uri.attr.port ? ":"+uri.attr.port : '') : '';
+
+ return uri;
+ };
+
+ function getAttrName( elm )
+ {
+ var tn = elm.tagName;
+ if ( tn !== undefined ) return tag2attr[tn.toLowerCase()];
+ return tn;
+ }
+
+ $.fn.url = function( strictMode )
+ {
+ var url = '';
+
+ if ( this.length )
+ {
+ url = $(this).attr( getAttrName(this[0]) ) || '';
+ }
+
+ return $.url( url, strictMode );
+ };
+
+ $.url = function( url, strictMode )
+ {
+ if ( arguments.length === 1 && url === true )
+ {
+ strictMode = true;
+ url = undefined;
+ }
+
+ strictMode = strictMode || false;
+ url = url || window.location.toString();
+
+ return {
+
+ data : parseUri(url, strictMode),
+
+ // get various attributes from the URI
+ attr : function( attr )
+ {
+ attr = aliases[attr] || attr;
+ return attr !== undefined ? this.data.attr[attr] : this.data.attr;
+ },
+
+ // return query string parameters
+ param : function( param )
+ {
+ return param !== undefined ? this.data.param.query[param] : this.data.param.query;
+ },
+
+ // return fragment parameters
+ fparam : function( param )
+ {
+ return param !== undefined ? this.data.param.fragment[param] : this.data.param.fragment;
+ },
+
+ // return path segments
+ segment : function( seg )
+ {
+ if ( seg === undefined )
+ {
+ return this.data.seg.path;
+ }
+ else
+ {
+ seg = seg < 0 ? this.data.seg.path.length + seg : seg - 1; // negative segments count from the end
+ return this.data.seg.path[seg];
+ }
+ },
+
+ // return fragment segments
+ fsegment : function( seg )
+ {
+ if ( seg === undefined )
+ {
+ return this.data.seg.fragment;
+ }
+ else
+ {
+ seg = seg < 0 ? this.data.seg.fragment.length + seg : seg - 1; // negative segments count from the end
+ return this.data.seg.fragment[seg];
+ }
+ }
+
+ };
+
+ };
+
+})(jQuery);
View
@@ -15,12 +15,19 @@
"default_icon": "images/icon_19.png",
"default_popup": "popup.html"
},
- "content_scripts": [
- {
- "matches": ["http://*.amazon.com/*"],
+ "content_scripts": [{
+ "matches": ["http://*.amazon.com/*",
+ "http://*.amazon.de/*", /* TODO */
+ "http://*.amazon.it/*",
+ "http://*.amazon.co.uk/*",
+ "http://*.amazon.fr/*",
+ "http://*.amazon.co.jp/*",
+ "http://*.amazon.ca/*",
+ "http://*.amazon.cn/*",
+ "http://*.amazon.es/*"],
+
"css": [],
"js": ["cs.js"]
- }
- ],
+ }],
"options_page": "options.html"
}
View
@@ -23,17 +23,19 @@
<input type="text" id="txt" />
</body>
<script src="jq.min.js"></script>
+ <script src="jquery.url.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);
+ chrome.tabs.getSelected(null, function(tab) {
+ var tablink = tab.url,
+ host = $.url(tablink).attr('host'),
+ link = 'http://' + host + '/dp/' + item + '/?tag='
+ + localStorage['trackId'];
+ console.log(link);
+ $('#txt').val(link);
+ });
}
}
</script>

0 comments on commit d2c9173

Please sign in to comment.