Skip to content

Commit

Permalink
add option to submit url to reddit
Browse files Browse the repository at this point in the history
  • Loading branch information
AdeelH committed May 31, 2017
1 parent a97096f commit 5c5e3ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "Find on Reddit",
"description": "Find discussions of the current URL on Reddit",
"version": "1.4.0",
"version": "1.4.1",

"browser_action": {
"default_icon": "icon-256.png",
Expand Down
13 changes: 9 additions & 4 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ function render(userClicked = false) {
let urlPromise = getUrl();
let params = getSearchParams();
let useCache = !userClicked;
let originalUrl;

urlPromise.then(url => updateUiBasedOnUrl(url, params));
urlPromise.then(url => {
originalUrl = url;
updateUiBasedOnUrl(url, params);
});
urlPromise
.then(url => {
let isYt = isYoutubeUrl(url) && params.ytHandling;
Expand All @@ -65,7 +69,7 @@ function render(userClicked = false) {

return findOnReddit(urlToSearch, useCache, exactMatch);
})
.then(displayPosts)
.then(posts=> displayPosts(posts, originalUrl))
.then(() => setUiState('SEARCH_END'))
.catch(onRequestError);
}
Expand Down Expand Up @@ -116,7 +120,7 @@ function calcAge(timestampSeconds) {
}

/* UI */
function displayPosts(posts) {
function displayPosts(posts, url = '') {
if (!posts) {
return;
}
Expand All @@ -134,7 +138,8 @@ function displayPosts(posts) {
// context for Handlebars template
context: {
numPosts: posts.length,
posts: posts
posts: posts,
url: url
}
};
document.getElementById('tFrame').contentWindow.postMessage(msg, '*');
Expand Down
6 changes: 5 additions & 1 deletion template.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script src="js/handlebars.min.js"></script>
<script id="search-results-template" type="text/x-handlebars-template">
<div class="row num-results-container">
<span id="num-results">{{numPosts}} results</span>
{{#if numPosts}}
<span id="num-results">{{numPosts}} results | <a href="https://www.reddit.com/{{url}}">repost to Reddit</a></span>
{{else}}
<span id="num-results">{{numPosts}} results | <a href="https://www.reddit.com/{{url}}">post to Reddit</a></span>
{{/if}}
</div>
<div class="row container-fluid list-container">
<table id="list" class="table">
Expand Down

3 comments on commit 5c5e3ba

@AdeelH
Copy link
Owner Author

@AdeelH AdeelH commented on 5c5e3ba May 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#12

@nkmathew
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't really repost the link, it'll return the first matching thread. Should be https://www.reddit.com/submit?url={{url}}

@AdeelH
Copy link
Owner Author

@AdeelH AdeelH commented on 5c5e3ba Jun 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fixed it a couple hours ago. Check latest release.

Please sign in to comment.