Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify the tumblr bookmarklet to post to a specific tumblr blog?

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)
like image 495
k107 Avatar asked Nov 04 '22 11:11

k107


2 Answers

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;
like image 165
KyleWpppd Avatar answered Nov 14 '22 03:11

KyleWpppd


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);
like image 21
Some Guy Avatar answered Nov 14 '22 02:11

Some Guy