Commits

Adrian Sampson committed 61a76be

move chrome plugin into its own directory

Comments (0)

Files changed (8)

chrome/content_script.js

+if (window == top) {
+    chrome.extension.onRequest.addListener(function(req, sender, sendResp) {
+        sendResp(getShortLink());
+    });
+}
+
+function getShortLink() {
+    var links = document.getElementsByTagName("link");
+    for (var i=0; i < links.length; i++) {
+        var rel = links[i].getAttribute("rel");
+        if (rel == "shorturl" || rel == "shortlink") {
+            var href = links[i].getAttribute("href");
+            return href;
+        }
+    }
+    return null;
+}
+

chrome/icon.png

Added
New image

chrome/manifest.json

+{
+    "name": "Shortlink",
+    "version": "1.0",
+    "description": "Finds canonical short URLs.",
+    "browser_action": {
+        "default_title": "Get short URL",
+        "default_icon": "icon.png",
+	"default_popup": "popup.html"
+    },
+    "permissions": [
+        "tabs"
+    ],
+    "content_scripts": [
+        {
+            "matches": ["http://*/*"],
+            "js": ["content_script.js"]
+        }
+    ]
+}
+

chrome/popup.html

+<html>
+<head>
+<style>
+#shortlink {
+	display: block;
+	white-space: nowrap;
+}
+</style>
+<script>
+function findLink(tab) {
+    chrome.tabs.sendRequest(tab.id, {}, function(url) {
+        if (url == null) {
+            // Fall back to current URL if no short one found.
+            url = tab.url;
+        }
+        console.log(url);
+
+	var linkel = document.getElementById("shortlink");
+	linkel.textContent = url;
+	a.href = url;
+    });
+}
+
+var tab = chrome.tabs.getSelected(null, function(tab) {
+    findLink(tab);
+});
+</script>
+</head>
+<body>
+Short link:
+<a href="#" id="shortlink">???</span>
+</body>
+</html>
+

content_script.js

-if (window == top) {
-    chrome.extension.onRequest.addListener(function(req, sender, sendResp) {
-        sendResp(getShortLink());
-    });
-}
-
-function getShortLink() {
-    var links = document.getElementsByTagName("link");
-    for (var i=0; i < links.length; i++) {
-        var rel = links[i].getAttribute("rel");
-        if (rel == "shorturl" || rel == "shortlink") {
-            var href = links[i].getAttribute("href");
-            return href;
-        }
-    }
-    return null;
-}
-

icon.png

Removed
Old image

manifest.json

-{
-    "name": "Shortlink",
-    "version": "1.0",
-    "description": "Finds canonical short URLs.",
-    "browser_action": {
-        "default_title": "Get short URL",
-        "default_icon": "icon.png",
-	"default_popup": "popup.html"
-    },
-    "permissions": [
-        "tabs"
-    ],
-    "content_scripts": [
-        {
-            "matches": ["http://*/*"],
-            "js": ["content_script.js"]
-        }
-    ]
-}
-

popup.html

-<html>
-<head>
-<style>
-#shortlink {
-	display: block;
-	white-space: nowrap;
-}
-</style>
-<script>
-function findLink(tab) {
-    chrome.tabs.sendRequest(tab.id, {}, function(url) {
-        if (url == null) {
-            // Fall back to current URL if no short one found.
-            url = tab.url;
-        }
-        console.log(url);
-
-	var linkel = document.getElementById("shortlink");
-	linkel.textContent = url;
-	a.href = url;
-    });
-}
-
-var tab = chrome.tabs.getSelected(null, function(tab) {
-    findLink(tab);
-});
-</script>
-</head>
-<body>
-Short link:
-<a href="#" id="shortlink">???</span>
-</body>
-</html>
-