Bing Daily Pictures Download button|必应每日图片下载按钮

Add a button for downloading bing-daily-pictures.添加一个必应每日图片下载按钮。

Από την 12/11/2017. Δείτε την τελευταία έκδοση.

// ==UserScript==
// @name        Bing Daily Pictures Download button|必应每日图片下载按钮
// @namespace   https://greasyfork.org/en/users/131965-levinit
// @author      levinit
// @description Add a button for downloading bing-daily-pictures.添加一个必应每日图片下载按钮。
// @include     *://cn.bing.com
// @include     *://www.bing.com/
// @include     *://www.bing.com/?*
// @include     *://cn.bing.com/?*
// @run-at      document-start
// @version     0.1
// @grant       none
// ==/UserScript==
window.onload=function () {
    var picUrl = document.querySelector("#bgDiv").style.backgroundImage;
    if (picUrl === "") {
        var style0 = document.styleSheets[0];
        var styles = style0.cssRules.length;
        for (var i = 0; i < styles; i++) {
            if (style0.cssRules[i].selectorText === "#bgDiv") {
                picUrl = style0.cssRules[i].style.backgroundImage;
            }
        }
    }

    var picName = picUrl.substring(
        picUrl.lastIndexOf("/") + 1,
        picUrl.length - 2
    );

    if (picUrl.indexOf("http") === -1) {
        picUrl = "http://cn.bing.com" + picUrl.substring(5, picUrl.length - 2);
    }

    var btn = document.createElement("a");
    var text = null;
    if(navigator.language === 'zh'){
        text = document.createTextNode("下载今日必应图片");
    }else{
        text = document.createTextNode("Download Today Bing Pictures");
    }

    btn.style.cssText =
        "display:inline-block;padding:0.25em;border-radius:0.25em;position:fixed;z-index:1000;right:20%;top:12%;background-color:#c3d1cf94;font-size: 1.5em;";
    btn.download = picName;
    btn.href = picUrl;

    btn.appendChild(text);
    document.body.appendChild(btn);
};