Greasy Fork is available in English.
Make life better!
// ==UserScript==
// @name 点击必应logo直接下载背景图
// @namespace http://tampermonkey.net/
// @version 0.0.1
// @description Make life better!
// @author petitepluie
// @match https://cn.bing.com/
// @grant none
// ==/UserScript==
(function downloadBingBg() {
'use strict';
var root = 'https://cn.bing.com/';
var obgDiv = document.getElementById('bgDiv');
var nowbgDivBg = obgDiv.style.backgroundImage;
/* 将必应logo作位下载按钮 */
var downloadBtn = document.getElementsByClassName('squares')[0];
downloadBtn.style.cursor = 'pointer';
downloadBtn.onclick = function () {
nowbgDivBg = obgDiv.style.backgroundImage;
var halfUrl = '';
if (nowbgDivBg) {
halfUrl = nowbgDivBg.split('("')[1].split('")')[0];
} else {
halfUrl = document.getElementById('bgLink').getAttribute('href');
}
download(root + halfUrl);
};
function download(url) {
var anchor = document.createElement('a');
anchor.href = url;
anchor.download = getFileName();
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
}
/* 图片索引 */
var count = 0;
var timestamp = new Date().getTime();
var adayms = 24 * 60 * 60 * 1000;
var pictsName = [];
for (var i = 0; i < 8; i++) {
var thisDate = new Date(timestamp - adayms * i);
pictsName.push(thisDate.getFullYear() + '_' + (thisDate.getMonth() + 1) + '_' + thisDate.getDate() + ' of bingBackground');
}
function getFileName() {
return pictsName[-count];
}
/* 记录图片索引为-7~0,随背景图切换而改变 */
var sh_igl = document.getElementById('sh_igl');
var sh_igr = document.getElementById('sh_igr');
var newbgDivBg = '';
var timer = null;
sh_igl.onclick = function () {
if (timer) {
return;
}
timer = setTimeout(function () {
newbgDivBg = obgDiv.style.backgroundImage;
if (count > -7 && newbgDivBg != nowbgDivBg) {
count--;
nowbgDivBg = obgDiv.style.backgroundImage;
}
clearTimeout(timer);
timer = null;
}, 800);
};
sh_igr.onclick = function () {
if (timer) {
return;
}
timer = setTimeout(function () {
newbgDivBg = obgDiv.style.backgroundImage;
if (count < 0 && newbgDivBg != nowbgDivBg) {
count++;
nowbgDivBg = obgDiv.style.backgroundImage;
}
clearTimeout(timer);
timer = null;
}, 800);
};
})();