Commits

Adrian Sampson committed 99b7489

rename chrome directory; factor out common link-finding code

Note that the common.js file must reside in the Chrome directory because, while
Safari supports symlinking to external files, Chrome does not. C.f. this bug:
http://code.google.com/p/chromium/issues/detail?id=27185

Comments (0)

Files changed (12)

Shortlink.safariextension/Info.plist

 		<dict>
 			<key>Start</key>
 			<array>
+				<string>common.js</string>
 				<string>content_script.js</string>
 			</array>
 		</dict>

Shortlink.safariextension/common.js

+../shortlink-chrome/common.js

Shortlink.safariextension/content_script.js

 safari.self.addEventListener("message", function(e) {
     if (e.name == 'shortlink') {
-        alert(getShortLink());
+        alert(__getShortLink());
     }
 }, false);
-
-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/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

Removed
Old 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>
-