Skip to content
This repository
Browse code

Fixing up extenstions for Share, Save and Edit

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

0 comments on commit 412f38a

Please sign in to comment.
Something went wrong with that request. Please try again.