繁体   English   中英

如何修改tumblr bookmarklet以发布到特定的tumblr博客?

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

我有几个博客链接到我的Tumblr帐户,但书签总是选择我的“主要”博客(列表中的第一个)。

如何修改书签以便自动选择特定博客? 我想有多个bookmarklet链接,例如“在blog1上分享”,“在blog2上分享”,这样我就不必手动选择要创建帖子的博客了。

默认Tumblr bookmarklet如下所示:

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)

使用用户脚本的组合,以及对书签的一点调整,这是您的解决方案:

将其安装为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));
    }
};

编辑BLOG_NAME变量后,将其另存为书签。 输入与下拉列表中的完全相同。 此外,您可能必须通过UglifyJS运行它以使其成为书签。

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);

给bookmarklet一个'channel_id'参数,在example_blog_name.tumblr.com'example_blog_name'

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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM