Permalink
Browse files

initial commit

  • Loading branch information...
gingerbeardman committed Jul 27, 2012
0 parents commit d463bcb3005b436f6a4f050398f174edc7f60e38
Showing with 222 additions and 0 deletions.
  1. +20 −0 Global.html
  2. BIN Icon.png
  3. +59 −0 Info.plist
  4. +7 −0 README.md
  5. +134 −0 iStockLargeComp.js
  6. +2 −0 zepto.js
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<script>
+safari.application.addEventListener("command", performCommand, false);
+safari.application.addEventListener("validate", validateCommand, false);
+
+function performCommand(event)
+{
+ if (event.command !== "viewFS") return;
+
+ event.currentTarget.activeBrowserWindow.openTab().url = event.userInfo.url;
+}
+
+function validateCommand(event)
+{
+ if (event.command !== "viewFS") return;
+
+ var state = (event.userInfo.classname != 'jewelcase') || (!event.userInfo.url);
+ event.target.disabled = state;
+}
+</script>
BIN Icon.png
Binary file not shown.
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Author</key>
+ <string>Matt Sephton</string>
+ <key>Builder Version</key>
+ <string>8536.25</string>
+ <key>CFBundleDisplayName</key>
+ <string>iStockLargeComp</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.gingerbeardman.istocklargecomp</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>Chrome</key>
+ <dict>
+ <key>Global Page</key>
+ <string>global.html</string>
+ </dict>
+ <key>Content</key>
+ <dict>
+ <key>Scripts</key>
+ <dict>
+ <key>Start</key>
+ <array>
+ <string>zepto.js</string>
+ <string>iStockLargeComp.js</string>
+ </array>
+ </dict>
+ </dict>
+ <key>Description</key>
+ <string>Generates a downloadable large comp from the individual zoom tiles on iStockphoto.com</string>
+ <key>ExtensionInfoDictionaryVersion</key>
+ <string>1.0</string>
+ <key>Permissions</key>
+ <dict>
+ <key>Website Access</key>
+ <dict>
+ <key>Allowed Domains</key>
+ <array>
+ <string>*.istockphoto.com</string>
+ <string>istockphoto.com</string>
+ </array>
+ <key>Include Secure Pages</key>
+ <true/>
+ <key>Level</key>
+ <string>Some</string>
+ </dict>
+ </dict>
+ <key>Update Manifest URL</key>
+ <string>http://www.gingerbeardman.com/safari/update.xml</string>
+ <key>Website</key>
+ <string>http://www.gingerbeardman.com/safari/</string>
+</dict>
+</plist>
@@ -0,0 +1,7 @@
+iStockLargeComp.safariextension
+==============================
+
+Generates a downloadable large comp from the individual zoom tiles on iStockphoto.com
+
+## License
+This is made available under a [Creative Commons Attribution-Share Alike 3.0 Unported License](http://creativecommons.org/licenses/by-sa/3.0).
@@ -0,0 +1,134 @@
+Zepto(function($){
+ var artworkID = $('#ZoomFileID').attr('value');
+ var imgType = $('#imgExt').attr('value');
+ var zoomSizes = eval($('#ZoomAvilSizes').attr('value'));
+ var maxZoom = zoomSizes[1]; //default zoom
+ // var maxZoom = zoomSizes[zoomSizes.length - 1]; //full zoom
+
+ var totalTiles = totalWidth = totalHeight = counter = 0;
+
+ if ($('#ZoomFileID').attr('value')) {
+ $('#downloadAComp').html($('#downloadAComp').html() +'<img src="http://i.istockimg.com/static/images/blank.gif" class="sptGreySeparator">'+'<a href="#downloadLargeComp" id="downloadLargeComp">Download a large comp</a>');
+
+ $('#downloadLargeComp').click(function() {
+ $("#ZoomImage").trigger('click');
+ $("#zoomInImg").trigger('click');
+ // $("#wrapper").hide();
+
+ $.ajaxJSONP({
+ url: 'http://www.istockphoto.com/ajax_class_creator.php',
+ success: function(data){
+ // data is a js object, such as Object or Array
+ console.log(data);
+ }
+ })
+ // console.log(zoomFile.myRequest.transport.responseText);
+
+ setTimeout(function() {
+ tileHeight = Math.ceil(Math.abs(parseInt($("#h0Img").css('height')))/380);
+ tileWidth = Math.ceil(Math.abs(parseInt($("#h0Img").css('width')))/380);
+ // console.log(tileHeight +","+ tileWidth);
+ totalTiles = tileWidth * tileHeight;
+
+ // $("#wrapper").show();
+ // glue();
+ }, 1000);
+
+ return false;
+ });
+ } else {
+ $('#downloadAComp').html('Sign in to download large comp');
+ }
+
+ function glue() {
+ $('#wrapper').text('');
+ $('footer').text('').css('marginTop', '50px');
+
+ var status = document.createElement("DIV");
+ status.setAttribute('style', 'clear: both;');
+ status.innerHTML = "<p id=\"status\"></p>";
+ document.getElementById('wrapper').appendChild(status);
+
+ var cont = document.createElement("DIV");
+ cont.setAttribute('id', 'cont');
+ cont.setAttribute('style', 'clear: both;');
+ document.getElementById('wrapper').appendChild(cont);
+
+ var i = 0;
+ for (y=0; y<tileHeight; y++) {
+ for (x=0; x<tileWidth; x++) {
+ offsetX = 190 + (x * 380);
+ offsetY = 190 + (y * 380);
+
+ addImage("http://www.istockphoto.com/file_inspector_view/"+ artworkID +"/"+ maxZoom +"/"+ offsetX +"/"+ offsetY +"/zoom_"+ artworkID +"."+imgType, i);
+
+ i++;
+ }
+ var br = document.createElement("BR");
+ br.setAttribute('clear', 'all');
+ document.getElementById('cont').appendChild(br);
+ }
+ }
+
+ function addImage(url, c) {
+ var img = document.createElement("img");
+ img.id = "zoompiece"+ c;
+ img.src = url;
+ img.setAttribute('style','display: block; margin: 0; float: left;');
+ img.onload = function() {
+ if (c < tileWidth) totalWidth += img.width;
+ if (c % tileWidth == 0) totalHeight += img.height;
+
+ img.height = img.height / 10;
+
+ counter++;
+
+ setStatus("Downloading zoom tiles, please wait... "+ counter +"/"+ totalTiles);
+
+ if (counter == totalTiles) {
+ setStatus("Generating download link...");
+
+ setTimeout(function() {
+ concatenateImages(totalWidth, totalHeight)
+ }, 600);
+ }
+ };
+
+ document.getElementById('cont').appendChild(img);
+
+ img.onerror = function() {
+ document.getElementById('cont').removeChild(img);
+ totalTiles--;
+ };
+ }
+
+ function setStatus(s) {
+ $('#status').html(s + "<br><br><a href=\""+ document.location.href +"\" style=\"text-decoration: underline;\">Cancel</a>");
+ }
+
+ function concatenateImages(w, h) {
+ var canvas = document.createElement("canvas");
+ canvas.id = 'canvas';
+ canvas.width = w;
+ canvas.height = h;
+ document.getElementById('cont').appendChild(canvas);
+
+ var ctx = canvas.getContext("2d");
+
+ var p = 0;
+ for (y=0; y<tileHeight; y++) {
+ for (x=0; x<tileWidth; x++) {
+ var img = document.getElementById('zoompiece'+ p++);
+ ctx.drawImage(img, x*380, y*380);
+ }
+ }
+
+ var grabcanvas = document.getElementById("canvas");
+ var imgdata = grabcanvas.toDataURL("image/jpeg");
+ imgdata = imgdata.replace("image/jpeg", "image/octet-stream");
+
+ setStatus("<a href=\""+ imgdata +"\" style=\"text-decoration: underline;\">Option-click this link to download the large comp</a><br><br><b>Important information:</b><br><em style=\"color: red;\">Whilst downloading the large image your browser will become totally unresponsive for a short while. Do not panic - it has not crashed!</em><br>A large JPEG image will be saved to your download folder with the filename \"Unknown\" which can then be renamed.");
+
+ $('#canvas').hide();
+ }
+});

Large diffs are not rendered by default.

Oops, something went wrong.

0 comments on commit d463bcb

Please sign in to comment.