Skip to content

Instantly share code, notes, and snippets.

@nkmathew
Last active January 26, 2018 09:05
Show Gist options
  • Save nkmathew/bc36bda8c19a6bd1b20643a49580b0c1 to your computer and use it in GitHub Desktop.
Save nkmathew/bc36bda8c19a6bd1b20643a49580b0c1 to your computer and use it in GitHub Desktop.
A userscript that adds a button for easily reposting a link from the subreddit frontpage
// ==UserScript==
// @name Reddit Repost Button
// @namespace http://nkmathew.net
// @author nkmathew
// @description Adds a button for easily reposting a link from the sub frontpage
// @icon http://www.reddit.com/favicon.ico
// @icon64 http://www.reddit.com/favicon.ico
// @version 0.1.0
// @include /^https?:\/\/(.+\.)?reddit\.com\/?.*$/
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// @run-at document-end
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
(function() {
window.addEventListener('load', function() {
var href, link;
$('.entry .title a.title').each(function(_, val) {
href = val.href;
if (href.indexOf('https://www.reddit.com/r/') === 0) {
href = href.replace('https://www.reddit.com/', 'https://np.reddit.com/');
}
link = `
<li title="Repost this link">
<a href="#" class="reddit-repost" data-href="${href}">
repost
</a>
</li>
`;
$(val.parentNode.parentNode).find('.flat-list').append(link);
});
$('.reddit-repost').click(function(event) {
var href = $(this).data('href');
event.preventDefault();
href = encodeURIComponent(href);
href = 'https://www.reddit.com/submit?url=' + href;
window.open(href, '_blank');
});
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment