Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from barnabywalters/master

Added ability to set the redirect URL in preferences
  • Loading branch information...
commit e2420e480408c08816f7c5520c45725d71a80112 2 parents b984569 + 7ca3482
@aaronpk authored
View
2  .gitignore
@@ -1,3 +1,5 @@
# osx noise
.DS_Store
profile
+*.crx
+*.pem
View
12 README.md
@@ -3,10 +3,18 @@ IndieWeb Reply
This browser extension rewrites Twitter.com "reply" buttons to open a browser window to your own site, allowing you to post a reply from your site.
-Click "reply" on a tweet
+## Setup
+
+Before it can be used, you need to set the URL to redirect to in the IndieWeb Reply extension preferences. This URL is a [web action URL](http://waterpigs.co.uk/articles/web-actions/) which should provide a UI for posting a new note.
+
+You can use <code>{url}</code> in your URL (perhaps in a query parameter) and it will be replaced by the URL of the tweet you’re replying to.
+
+## Usage
+
+On twitter.com, click "Reply" on a tweet:
![A Tweet](https://github.com/aaronpk/IndieWeb-Reply-Browser-Extension/raw/master/example-tweet.png)
A window opens on your own domain so you can reply from your site
-![Reply from your site](https://github.com/aaronpk/IndieWeb-Reply-Browser-Extension/raw/master/example-reply.png)
+![Reply from your site](https://github.com/aaronpk/IndieWeb-Reply-Browser-Extension/raw/master/example-reply.png)
View
16 chrome/background.js
@@ -16,6 +16,22 @@ chrome.extension.onConnect.addListener(function(port) {
});
});
+chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {
+ console.log('onMessage called with request, sender, response:');
+ console.log(request);
+ console.log(sender);
+ console.log(sendResponse);
+
+ if (request.getLocalStorage !== undefined) {
+ console.log('Getting locally stored variable ' + request.getLocalStorage);
+
+ var response = {};
+ response[request.getLocalStorage] = window.localStorage[request.getLocalStorage];
+
+ sendResponse(response);
+ }
+});
+
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
console.debug(request);
});
View
36 chrome/content_script.js
@@ -9,18 +9,30 @@ function bindTwitter() {
$(e).unbind("click").click(function(evt){
var tweet = $(evt.target).parents(".tweet");
var url = "https://twitter.com/" + $(tweet).data('screen-name') + "/status/" + $(tweet).attr('data-item-id');
-
- // TODO: THIS IS A HACK! see below.
- var postURL = "http://pk.dev/admin/?reply_to=" + encodeURI(url);
- window.open(postURL);
-
- // TODO: Need to either get the page URL from the extension preferences, or send an event to the extension
- // where the extension can open the new window
- // chrome.extension.sendMessage({url: url}, function(response) {
- // console.log(response);
- // });
-
- return false;
+
+ var replace = {
+ url: encodeURI(url)
+ };
+
+ chrome.extension.sendMessage({'getLocalStorage': 'IndieWebReplyPostURL'}, function (response) {
+ var postURL = response.IndieWebReplyPostURL;
+
+ if (postURL === undefined) {
+ alert('You must set a Reply Post URL in Chrome options in order to use IndieWeb Reply');
+ return false;
+ }
+
+ // Replace template vars
+ for (var template in replace) {
+ if (replace[template] == undefined)
+ continue;
+ postURL = postURL.split('{' + template + '}').join(replace[template]);
+ }
+
+ window.open(postURL);
+ });
+
+ return false;
});
});
}
View
47 chrome/options.html
@@ -1,4 +1,4 @@
-<!DOCTYPE>
+<!doctype>
<html>
<head>
<title>Options for the IndieWeb Reply Extension</title>
@@ -8,32 +8,33 @@
* LICENSE file.
-->
<style>
- #providerSelection {
- font-family: Helvetica, Arial, sans-serif;
- font-size: 10pt;
+ body {
+ font-family: "Georgia", serif;
+ font-size: 18px;
+ }
+
+ input[type=url] {
+ font-size: 18px;
+ width: 50em;
+ max-width: 100%;
}
</style>
<script src="options.js"></script>
</head>
<body>
- <table border="0">
- <tr>
- <td rowspan="2" valign="top" align="center" width="80">
- <img src="mail_128x128.png" width="64" height="64" />
- </td>
- <td height="22"></td>
- </tr>
- <tr>
- <td valign="center">
- <div id="providerSelection">
- <strong>Enter your posting URL:</strong>
- <br /><br />
- <label>
- <input id="postURL" name="postURL" type="text" />
- </label>
- </div>
- </td>
- </tr>
- </table>
+ <h1>Indieweb Reply Preferences</h1>
+
+ <div id="providerSelection">
+ <p>Enter the URL of your new note UI:</p>
+
+ <label>URL: <input id="postURL" name="postURL" type="url" /></label>
+
+ <p>The following expressions will be expanded:</p>
+
+ <dl>
+ <dt><code>{url}</code>
+ <dd>Expands to the (urlencoded) URL of the current page
+ </dl>
+ </div>
</body>
</html>
View
4 chrome/options.js
@@ -9,7 +9,7 @@ function saveURL(evt) {
alert('Local storage is required for changing providers');
return;
}
- window.localStorage.postURL = evt.target.value;
+ window.localStorage.IndieWebReplyPostURL = evt.target.value;
}
function main() {
@@ -18,7 +18,7 @@ function main() {
return;
}
- document.getElementById('postURL').value = window.localStorage.postURL;
+ document.getElementById('postURL').value = window.localStorage.IndieWebReplyPostURL;
}
document.addEventListener('DOMContentLoaded', function () {
Please sign in to comment.
Something went wrong with that request. Please try again.