Commits

Alexey Kozlov  committed 8d0e0a8

version 1.0

  • Participants

Comments (0)

Files changed (5)

File 128.png

Added
New image

File 16.png

Added
New image

File 48.png

Added
New image

File background.html

+<html>
+ <script>
+
+  function real_url(baseUrl, relativeUrl) {
+
+    if(relativeUrl.indexOf("http") == 0 || relativeUrl.indexOf("//") == 0)
+    {
+      return relativeUrl;
+    }
+
+    if(relativeUrl.charAt(0) == "/")
+    {
+      baseUrl = baseUrl.substr(0, baseUrl.indexOf("/", baseUrl.indexOf(".")));
+      relativeUrl = relativeUrl.substr(1, relativeUrl.length-1);
+    }
+    else
+    {
+      var qm = baseUrl.indexOf("?");
+      if(qm + 1)
+      {
+        baseUrl = baseUrl.substr(0, qm);
+      }
+
+      baseUrl = baseUrl.substr(0, baseUrl.lastIndexOf("/"));
+    }
+    return baseUrl + "/" + relativeUrl;
+
+  }
+
+
+  chrome.extension.onRequest.addListener(function(request) {
+
+    if (request[1] == 0) {
+      alert("No images on this page.");
+    }
+    if (request[1] == request[0]) {
+      alert("Bigest image already shown.");
+    }
+    if (request[1] != request[0] && request[1] != 0) {
+      //alert(request[0] + ' == ' + request[1]);
+
+      chrome.tabs.create({'url': real_url(request[0], request[1])});
+
+    }
+
+  });
+
+
+  chrome.browserAction.onClicked.addListener(function(tab) {
+
+    chrome.tabs.executeScript(null, {code: "lh=location.href;s=lh;a=0;r=chrome.extension.sendRequest;n=document.getElementsByTagName('img');l=n.length;if(!l||(l==1&&n.item(0)==lh)){r([lh,0]);}else{for(i=0;i<l;i++){t=n.item(i);b=t.height*t.width;if(b>a){a=b;s=t.getAttribute('src');}}r([lh,s]);}"});
+
+  });
+
+ </script>
+</html>

File manifest.json

+{
+   "name": "Show Bigest Image",
+   "description": "Find bigest image on the page and show it in new tab",
+   "version": "1.0",
+   "background_page": "background.html",
+   "browser_action": {
+      "default_icon": "48.png",
+      "default_title": "Show a bigest image"
+   },
+   "icons": {
+      "128": "128.png",
+      "48": "48.png",
+      "16": "16.png"
+   },
+   "permissions": [ "tabs", "http://*/*", "https://*/*" ]
+}