Permalink
Browse files

Fixing up extenstions for Share, Save and Edit

  • Loading branch information...
1 parent b5a1e1a commit 412f38a5277d2e90da752a74707b78d1758c2ecd @PaulKinlan committed Aug 10, 2012
@@ -1,15 +1,15 @@
-<!doctype html>
-<script src="webintents.js"></script>
<script>
-
function clickHandler(info, tab) {
- console.log(info);
if(info.mediaType == "image" ||
info.mediaType == "video" ||
info.mediaType == "audio") {
- var intent = new Intent( "http://webintents.org/edit", info.mediaType + "/*", info.srcUrl);
+ var i = new WebKitIntent({"action": "http://webintents.org/edit", "type": info.mediaType + "/*", "data": info.linkUrl });
- chrome.tabs.sendRequest(tab.id, intent);
+ chrome.tabs.sendRequest(tab.id, i);
+ }
+ else if(!!info.linkUrl) {
+ var i = new WebKitIntent({"action": "http://webintents.org/edit", "type": "text/uri-list", "data": info.linkUrl });
+ window.navigator.webkitStartActivity(i, function() {}, function() {});
}
};
@@ -1,10 +0,0 @@
-chrome.extension.onRequest.addListener(function(intent) {
- var script = "";
- script += "var i = new Intent('" + intent.action + "'";
- script += ",'" + intent.type + "'";
- script += ", JSON.parse('" + JSON.stringify(intent.data) + "'));";
- script += "window.navigator.startActivity(i);";
- var scriptElement = document.createElement("script");
- scriptElement.innerText = script;
- document.head.appendChild(scriptElement);
-});
@@ -1,11 +0,0 @@
-(function() {
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if(xhr.readyState != 4 || xhr.status != 200) return;
- var script = document.createElement("script");
- script.textContent = xhr.responseText;
- document.head.appendChild(script);
- };
- xhr.open("GET", chrome.extension.getURL('/webintents.js'), true);
- xhr.send();
-})();
@@ -1,28 +1,14 @@
-<!doctype html>
-<script src="webintents.js"></script>
<script>
function clickHandler(info, tab) {
- console.log(info);
if(info.mediaType == "image" ||
info.mediaType == "video" ||
info.mediaType == "audio") {
- var intent = new Intent("http://webintents.org/save", info.mediaType + "/*", info.srcUrl);
- try {
- var intent = new Intent("http://webintents.org/save", "text/uri-list", info.linkUrl);
- window.navigator.startActivity(intent);
- }
- catch(e) {
- console.log(e);
- }
+ var i = new WebKitIntent({"action": "http://webintents.org/save", "type": info.mediaType + "/*", "data": info.srcUrl});
+ window.navigator.startActivty(i);
}
else if(!!info.linkUrl) {
- try {
- var intent = new Intent("http://webintents.org/save", "text/uri-list", info.linkUrl);
- window.navigator.startActivity(intent);
- }
- catch(e) {
- console.log(e);
- }
+ var i = new WebKitIntent({"action": "http://webintents.org/save", "type": "text/uri-list", "data": info.linkUrl });
+ window.navigator.webkitStartActivity(i, function() {}, function() {});
}
};
@@ -1,10 +0,0 @@
-chrome.extension.onRequest.addListener(function(intent) {
- var script = "";
- script += "var i = new Intent('" + intent.action + "'";
- script += ",'" + intent.type + "'";
- script += ", JSON.parse('" + JSON.stringify(intent.data) + "'));";
- script += "window.navigator.startActivity(i);";
- var scriptElement = document.createElement("script");
- scriptElement.innerText = script;
- document.head.appendChild(scriptElement);
-});
@@ -1,11 +0,0 @@
-(function() {
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if(xhr.readyState != 4 || xhr.status != 200) return;
- var script = document.createElement("script");
- script.textContent = xhr.responseText;
- document.head.appendChild(script);
- };
- xhr.open("GET", chrome.extension.getURL('/webintents.js'), true);
- xhr.send();
-})();
@@ -1,28 +1,15 @@
-<!doctype html>
-<script src="webintents.js"></script>
-<intent
- action="http://webintents.org/share"
- type="text/uri-list"
- href="handlers/twitter.html"
- title="Twitter"
- />
<script>
-
function clickHandler(info, tab) {
- console.log(info);
if(info.mediaType == "image" ||
info.mediaType == "video" ||
info.mediaType == "audio") {
- var i = new Intent("http://webintents.org/share", info.mediaType + "/*", info.srcUrl);
-
+
+ var i = new WebKitIntent({"action": "http://webintents.org/share", "type": info.mediaType + "/*", "data": info.srcUrl});
window.navigator.startActivty(i);
- //chrome.tabs.sendRequest(tab.id, intent);
}
else if(!!info.linkUrl) {
- var i = new WebKitIntent("http://webintents.org/share", "text/uri-list", info.linkUrl);
-
+ var i = new WebKitIntent({"action": "http://webintents.org/share", "type": "text/uri-list", "data": info.linkUrl });
window.navigator.webkitStartActivity(i, function() {}, function() {});
- //chrome.tabs.sendRequest(tab.id, intent);
}
};
@@ -1,17 +0,0 @@
-<!doctype html>
-<html>
- <head>
- <script>
- document.addEventListener("load", function() {
- if(window.intent) {
- if(window.intent.type.indexOf("text/")) {
- var href = "https://twitter.com/intent/tweet?" +
- encodeURI(window.intent.data);
- console.log(href);
- window.location = href;
- }
- }
- });
- </script>
- </head>
-</html>
@@ -1,34 +0,0 @@
-var addIntent = function() {
- // Always add the intent in.
- var intentEl = document.createElement("intent");
- intentEl.setAttribute("action", "http://webintents.org/share");
- intentEl.setAttribute("type", "text/uri-list");
- intentEl.setAttribute("href", document.location.href);
- document.head.appendChild(intentEl);
-};
-
-var checkIntent = function() {
- var interval = setInterval(function() {
- debugger;
- if (!!window.intent == false) return;
- clearInterval(interval);
- var share = document.querySelector(".c-i-f-C");
- var ev = document.createEvent("MouseEvent");
- ev.initMouseEvent("click");
- share.dispatchEvent(ev);
- setTimeout(function() {
- var se = document.querySelector(".m-n-f-ba-rd");
- se.textContent = window.intent.data;
- }, 1000);
-
- }, 1000);
-}
-
-if(document.readyState == "complete") {
- addIntent();
- checkIntent();
-}
-else {
- window.addEventListener("load", addIntent, false);
- window.addEventListener("load", checkIntent, false);
-}
@@ -1,10 +0,0 @@
-chrome.extension.onRequest.addListener(function(intent) {
- var script = "";
- script += "var i = new Intent('" + intent.action + "'";
- script += ",'" + intent.type + "'";
- script += ", JSON.parse('" + JSON.stringify(intent.data) + "'));";
- script += "window.navigator.startActivity(i);";
- var scriptElement = document.createElement("script");
- scriptElement.innerText = script;
- document.head.appendChild(scriptElement);
-});
@@ -1,11 +0,0 @@
-(function() {
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if(xhr.readyState != 4 || xhr.status != 200) return;
- var script = document.createElement("script");
- script.textContent = xhr.responseText;
- document.head.appendChild(script);
- };
- xhr.open("GET", chrome.extension.getURL('/webintents.js'), true);
- xhr.send();
-})();

0 comments on commit 412f38a

Please sign in to comment.