Create Discourse Bookmarklet and redirect current page to another site

If you are using Discourse as a place to collect resources you find online, you might like these bookmarklets.

To use them, create a bookmark (I put them on my browser Bookmarks Bar), then right-click and edit the bookmark, copy one of the javascript blocks below, and paste it in the URL field.

Use these blocks to configure the code with your forum URL and preferred category.

These control the size of the pop-up window if you use one of those

Select your preferred action

New window, URL in title

javascript:(function(){var%20a=window,b=document,c=encodeURIComponent,d=a.open("=url=new-topic?category==category=&tags==tags=&title="+c(b.location),"bkmk_popup","left="+((a.screenX||a.screenLeft)+10)+",top="+((a.screenY||a.screenTop)+10)+",height==height=,width==width=,resizable=1,alwaysRaised=1");a.setTimeout(function(){d.focus()},300)})();

New window: title from page title, selected text and URL in the topic body

javascript:(function(){var%20a=window,b=document,c=encodeURIComponent,d=a.open("=url=new-topic?category==category=&tags==tags=&tags==tags=&title="+c(b.title)+"&body="+c(b.location)+"%250A%250A"+c(b.getSelection().toString()),"bkmk_popup","left="+((a.screenX||a.screenLeft)+10)+",top="+((a.screenY||a.screenTop)+10)+",height==height=,width==width=,resizable=1,alwaysRaised=1");a.setTimeout(function(){d.focus()},300)})();

Same Window: title from page title, selected text and URL in the topic body

javascript:(function(){var%20a=window,b=document,c=encodeURIComponent,d=a.open("=url=new-topic?category==category=&tags==tags=&title="+c(b.title)+"&body="+c(b.location)+"%250A%250A"+c(b.getSelection().toString()),"_self");a.setTimeout(function(){d.focus()},300)})();

New tab: title from page title, selected text and URL in the topic body

javascript:(function(){var%20a=window,b=document,c=encodeURIComponent,d=a.open("=url=new-topic?category==category=&tags==tags=&title="+c(b.title)+"&body="+c(b.location)+"%250A%250A"+c(b.getSelection().toString()),"_add_to_discourse");a.setTimeout(function(){d.focus()},300)})();

How to use on Android

To make this work on android, edit the url of the current page and type the name of your bookmark and select it from the list.

Visit current path on a different hostname

This is useful when checking how a production site’s URLs work on a staging server. For example, I’m working on a new web site, with this, I can go to each page on my site, click this link, and see what that page does on my test site.

Enter the domain you want to redirect to in the field below and then copy/paste the javascript into your bookmark.

Visit current path on =url=

Paste into a bookmark url

javascript:(function(){var a=window,b=document,c=encodeURIComponent,d=a.open(window.location.href.replace(/https?:\/\/.*?\//,'=url='),"_add_to_discourse");a.setTimeout(function(){d.focus()},300)})();

Following How to enter newline character in bookmarklet JavaScript - Stack Overflow

Consider re-writing something like this:

javascript:(function() {
    var today = new Date();
    var url = 'https://mail.google.com/mail/?view=cm';
    var to = 'emailfrombookmarklet@example.com';
    var subject = '【weather report】【' + today.getFullYear() + '-' + ('00' + (today.getMonth() + 1)).slice(-2) + '-' + ('00' + today.getDate()).slice(-2) + ' bar】 email from bookmarklet';
    var body1 = 'Hi,\n\nThis is Kim Kardashian.\nIt\'s sunny today.\n\ndate:';
    var targetDate = ' ' + today.getFullYear() + '-' + ('00' + (today.getMonth() + 1)).slice(-2) + '-' + ('00' + today.getDate()).slice(-2);
    var body2 = '\nName: Kim Kardashian\n';
    var body3 = '\nBest Regards,';
    url += '&to=' + encodeURIComponent(to) + '&su=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body1 + targetDate + body2 + body3);
    window.open(url);
})();