5

I have a couple blogs linked to my Tumblr account, but the bookmarklet always selects my "primary" blog (the first one in the list).

How can I modify the bookmarklet so that it will auto-select a specific blog? I would like to have multiple bookmarklet links, e.g. "Share on blog1", "Share on blog2" so that I don't have to manually select which blog to create the post in.

Default Tumblr bookmarklet looks like this:

javascript: var d = document,
    w = window,
    e = w.getSelection,
    k = d.getSelection,
    x = d.selection,
    s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
    f = 'http://www.tumblr.com/share',
    l = d.location,
    e = encodeURIComponent,
    p = '?v=3&u=' + e(l.href) + '&t=' + e(d.title) + '&s=' + e(s),
    u = f + p;
try {
    if (!/^(.*\.)?tumblr[^.]*$/.test(l.host)) throw (0);
    tstbklt();
} catch (z) {
    a = function () {
        if (!w.open(u, 't', 'toolbar=0,resizable=0,status=1,width=450,height=430')) l.href = u;
    };
    if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
    else a();
}
void(0)
k107
  • 15,882
  • 11
  • 61
  • 59

2 Answers2

1

Using a combination of a user script, and a little tweaking to the bookmarklet, here's your solution:

Install this as a UserScript:

var selectOption = function (elem, value) {
    var options = elem.options;
    for(var i = 0; i < options.length; i++){
        if(options[i].innerHTML === value){
            elem.selectedIndex = i;
        }
    }
};

window.onload = function (){
    if(location.href.indexOf('tumblr.com/share') !== -1){
        selectOption(document.getElementById('channel_id'), location.hash.slice(1));
    }
};

Save this as your bookmarklet after editing the BLOG_NAME variable. Type it exactly as it is in the dropdown. Also, you'll probably have to run it through UglifyJS to make it a bookmarklet.

javascript: var BLOG_NAME = 'Test',
    d = document,
    w = window, 
    e = w.getSelection,
    k = d.getSelection,
    x = d.selection,
    s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
    f = 'http://www.tumblr.com/share',
    l = d.location,
    e = encodeURIComponent,
    p = '?v=3&u=' + e(l.href) + '&t=' + e(d.title) + '&s=' + e(s),
    u = f + p;
try {
    if (!/^(.*\.)?tumblr[^.]*$/.test(l.host)) throw (0);
    tstbklt();
} catch (z) {
    a = function () {
        if (!w.open(u + '#' + BLOG_NAME, 't', 'toolbar=0,resizable=0,status=1,width=450,height=430')) l.href = u;
    };
    if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
    else a();
}
void(0);
Some Guy
  • 15,854
  • 10
  • 58
  • 67
1

Give the bookmarklet a 'channel_id' post parameter which is 'example_blog_name' in example_blog_name.tumblr.com

javascript: var d = document,
    w = window,
    e = w.getSelection,
    k = d.getSelection,
    x = d.selection,
    s = (e ? e() : (k) ? k() : (x ? x.createRange().text : 0)),
    f = 'http://www.tumblr.com/share',
    l = d.location,
    e = encodeURIComponent,
    c = 'example_blog_name',
    p = '?v=3&u=' + e(l.href) + '&t=' + e(d.title) + '&s=' + e(s) + '&channel_id=' + e(c),
    u = f + p;
KyleWpppd
  • 2,010
  • 2
  • 16
  • 16
  • @trnsfrmr What was the error? What was the query string you passed with your request? "I couldn't get that to work at all" is not very constructive if you are actually trying, in fact, to get it to work. – KyleWpppd Sep 01 '12 at 19:03
  • I get request denied, see pic: http://imgur.com/TgwtD . @KyleWppd, does it work for you? – jnthnclrk Sep 02 '12 at 21:45
  • @trnsfrmr Can you paste the request that you are actually sending? Als you will have to be logged in and be able to post to the `channel_id`/example_blog_name to not get the 403. – KyleWpppd Sep 02 '12 at 22:24
  • Ah, I wasn't logged in. Once logged in to a Tumblr account it will work. Hmmm, I thought the question was asking for something that could handle multiple Tumblr accounts. Having to log and login to switch makes for a very tiresome workflow. – jnthnclrk Sep 02 '12 at 22:31
  • @jnthnclrk: Not multiple accounts, but multiple blogs (all on the same account). – unor Sep 11 '13 at 07:16