MediaWiki:Common.js:修订间差异

Ztm0929留言 | 贡献
增加 Powered by SMW 图标切换的逻辑
Ztm0929留言 | 贡献
在正文底部增加额外搜索链接
标签已被回退
第151行: 第151行:
     // 再加一个延时
     // 再加一个延时
     setTimeout(removeBetaNotice, 2000);
     setTimeout(removeBetaNotice, 2000);
});
// 正文底部额外搜索链接
mw.hook('wikipage.content').add(function ($content) {
    // 获取当前条目的名称
    var pageName = mw.config.get('wgPageName');
    // wgPageName 会用下划线代替空格,我们换回空格
    var title = pageName.replace(/_/g, ' ');
    // 构造搜索链接
    var googleLink = $('<a>')
        .attr('href', 'https://www.google.com/search?q=' + encodeURIComponent(title))
        .attr('target', '_blank')
        .text('在谷歌中搜索 ' + title);
    var baiduLink = $('<a>')
        .attr('href', 'https://www.baidu.com/s?wd=' + encodeURIComponent(title))
        .attr('target', '_blank')
        .css('margin-left', '15px') // 给两个链接之间加点空隙
        .text('在百度中搜索 ' + title);
    // 包一层 div,放到底部
    var container = $('<div>')
        .addClass('search-links')
        .css({ marginTop: '20px', textAlign: 'center' })
        .append(googleLink)
        .append(baiduLink);
    // 插入到页面内容的底部
    $content.append(container);
});
});