Greasy Fork

Greasy Fork is available in English.

Bing图

百度首页变成bing

当前为 2014-04-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Bing图
// @namespace   firefox
// @include http://www.baidu.com/
// @include http://www.baidu.com/home*
// @include http://www.baidu.com/?tn=*
// @include http://www.baidu.com/index.php*
// @version     1
// @description  百度首页变成bing
// @run-at document-body
// @grant GM_xmlhttpRequest
// ==/UserScript==
if(!document.documentElement.hasAttribute('xmlns'))return false;
var _bing = {
		name : '_baiduLogo',
		X : 0,
		Y : 0,
		current:{idx:0,url:'',type:'image1'},
		formerly:{idx:0,url:'',type:'image'},
		idx:0
	};
var loading = false;

function save(_bing){
	localStorage._bing = JSON.stringify(_bing);
}
function load(){
	localStorage._bing && (_bing = JSON.parse(localStorage._bing));
	return _bing;
}
function getIdx(type) {
	var idx = 0;
	"prev" == type ? idx = _bing.current.idx + 1 : "next" == type && (idx = _bing.current.idx - 1);
	return idx;
}
function loadResponse(e){
	try{
		var d = JSON.parse(e.responseText);
		var image = d.images[0];
		var imageUrl = image.url.replace(new RegExp('^(\w{3,5}:\/\/[^/]*)'), bing_uri);
		//"/" == imageUrl[0] ? imageUrl=bing_uri+imageUrl : null;
		var	video = image.vid ? image.vid : null;
		console.log(image.copyrightlink)
		$('#sh_cp').attr('href',image.copyrightlink.replace(new RegExp('.*\\?q=([^&]*).*', 'i'), 's?wd=$1')).attr('title',image.copyright);
	}catch(error){
		console.log(error);return;
	}
	if(_bing.current.url != imageUrl){
		changeBg(imageUrl,video);
	} else{
		openLoadingLock();
	}
}
function prevImg(){
	loadBgJson(getIdx('prev'),loadResponse);
}
function nextImg(){
	loadBgJson(getIdx('next'),loadResponse);
}
function openLoadingLock(){
	loading = false;
	$("#sh_igl").attr('title','上一页');
	$("#sh_igr").attr('title','下一页');
}
function changeBg(imageUrl,video){
		var bg = new Image(),
		time = 2000,
		showV,
		hideV,
		a = $("#bg1").css("background-image"),
		b = $("#bg2").css("background-image");
	"none" == a && "none" == b && (time = 500, showV = $("#bg1"), hideV = $("#bg2"), showV.css("opacity", 0));
	"none" != a && "none" == b && (console.log('jin ru 2'),showV = $("#bg2"), hideV = $("#bg1"),showV.css("opacity", 0));
	"none" != a && "none" != b && (a = $("#bg1").css("opacity"), $("#bg2").css("opacity"), showV = a < 1 ? $("#bg1") : $("#bg2"), hideV = "bg1" == showV.attr("id") ? $("#bg2") : $("#bg1"));

	bg.addEventListener("load",function(e){
		var v = $('#bg3 video');
		if(video){
			v.attr('loop',video.loop).attr('src',bing_uri + video.codecs[0][1]);
			$('#bg3,#bg3 video').fadeIn(time)
		}else{
			$('#bg3,#bg3 video').fadeOut(time,function(){v.attr('loop',"").attr('src','')});
		}
		video==null&&showV.css("background-image",'url('+imageUrl+')');
		setTimeout(openLoadingLock,time/2);
		hideV.animate({opacity: '0'},time);  
		showV.animate({opacity: '1'},time);
	})
	bg.src = imageUrl;
	_bing.formerly = _bing.current;
	_bing.current = {idx:_bing.idx,url:imageUrl,type:'image'};
	save(_bing);
}

function loadBgJson(i/*1-7 | 0为当天 -1为明天*/,callback){
	if(loading == true){console.error('is loading '+_bing.idx)};
	if(i >= -1 && i <= 7 && loading == false){
		loading = true;
		$("#sh_igl,#sh_igr").attr('title','加载中...');
		_bing.idx = i;
		var url = bing_uri + '/HPImageArchive.aspx?format=js&idx=' + i + '&n=1&nc=' + new Date().getTime() + '&pid=hp&video=1';
		var opt = {
			method:'GET',
			url:url,
			onload:callback,
			onerror:function(e){console.log(e);ajax(opt);openLoadingLock()},
			onabort:function(e){console.log(e);ajax(opt);openLoadingLock()}
		}
		switch(i){
			case 7:{$('#sh_igl').css('opacity',0.3);break;}
			case -1:{$('#sh_igr').css('opacity',0.3);break;}
			case 6:{$('#sh_igl').css('opacity',1);break;}
			case 0:{$('#sh_igr').css('opacity',1);break;}
		}
		ajax(opt);
	}
}
function changHasBgStyle(){
	if(($('#content').attr('class')).indexOf('opacity')==-1)$("#content").addClass("s-skin-user s-skin-hasbg s-skin-dark opacity-40 white-logo");
}

function bing(){
	var clientHeight=document.body.clientHeight,
		clientWidth=document.body.clientWidth,
		width=clientHeight*clientWidth/720,
		height=clientHeight*clientWidth/1280,
		left=0-(width-clientWidth)/2,
		top=0-(height-clientHeight)/2;
	var css = 'div.bing_bg{background-attachment: fixed;background-position: center 0;background-repeat: no-repeat;background-size: cover;height: 100%;left: 0;position: absolute;top: 0;width: 100%;}\
	.bing_video{overflow:hidden;position:fixed;width:'+width+'px;height:'+height+'px;left:'+left+'px;top:'+top+'px;}\
	div#sh_rdiv{position:fixed;right:15px;bottom:46px;}div#sh_rdiv A{position:relative;width:29px;height:29px;margin:0 5px;float:left}\
	a[id^="sh_"]{background:url(http://imgsrc.baidu.com/forum/pic/item/7da86b899e510fb3f9270773d833c895d0430cf9.jpg) no-repeat;}\
	p#lg{position:absolute;top:10%;left:8%;width:175px;height: 45px !important;margin-top: -5px !important;background-position: 0 0px;}\
	#lg img{display: none !important;}\
	#lg{-moz-transition:all 1s ease;-webkit-transition:all 1s ease;background:url("http://imgsrc.baidu.com/forum/w%3D580/sign=108ffbc58644ebf86d716437e9fbd736/9fc170d12f2eb938e0bfb834d4628535e7dd6fc9.jpg") no-repeat;}\
    .s-skin-hasbg #kw1{background:none !important;width:423px !important;box-shadow: none !important;height: 26px!important;line-height: 26px!important;padding: auto;}\
    #form1 .bdsug{width:421px!important;}#form1 .bdsug li{width:404px!important;}\
	#form1 .bdsug{border-left:0px!important;border-right:0px!important;top:32px!important;}\
	div#s_fm {background-color: #FFFFFF;left: 8%;margin: 0 0 0 155px;padding: 0;position: absolute;top: 10%;width: 421px;}\
    .btn_wr {background: url("http://imgsrc.baidu.com/forum/pic/item/7da86b899e510fb3f9270773d833c895d0430cf9.jpg") no-repeat scroll -149px -37px rgba(0, 0, 0, 0) !important;}\
    #su1{display: none !important;}\
    span.btn_wr {float: right;left: -1px;position: relative;top: -30px;width: 28px !important;}\
    #nv a, #tb_mr b { text-decoration: none!important;font-size: 13px!important;}\
    #nv{position: absolute;left:-75px;top:6px;width: 550px !important;}\
    .s-notify-pnl .s-pk-mod,.s-new-weather-pnl{left:450px!important;}\
    #bottom_container{display: none !important;height:0px!important;}\
    #s_wrap{margin: 120px auto auto!important; padding-bottom: 0px!important;}\
	a#sh_igl{background-position:-29px -37px}\
	a#sh_igr{background-position:0px -37px}\
	a#sh_cp{background-position:-59px -37px}';
	$("body").before('<style type="text/css">'+css+'</style>');
	$("#content").append('<div id="bg1" class="bing_bg" style="z-index:-5"/><div id="bg2" class="bing_bg" style="z-index:-5"/><div id="bg3" class="bing_bg" style="z-index:-4"><video autoplay="true" class="bing_video"/></div>');
	$("#bg2,#bg1").css("background-color",'rgba(89, 83, 87, 0.3)');
	if($("#bg2").css("background-image")!='none'){
		$(".s-skin-container")&&$(".s-skin-container").remove();
	}
	$('body').append('<div id="sh_rdiv"><a id="sh_igl" href="javascript:void(0)" title="上一页"/><a id="sh_igr" href="javascript:void(0)" title="下一页"/><a id="sh_cp" href="javascript:void(0)" target="_blank"/></div>');
	$('.btn_wr').click(function(){
		$('#form1').submit();
	});
	(document.getElementById('sh_rdiv')).addEventListener('click', function(event) {
		switch (event.target.id) {
			case 'sh_igl':prevImg();break;
			case 'sh_igr':nextImg();break;
		}
	})
}
try{
	var bing_uri = 'http://cn.bing.com';
	var _window = typeof unsafeWindow != 'undefined'?unsafeWindow:window;
	var $ = _window.$;
	var ajax = GM_xmlhttpRequest;
	bing();
	changHasBgStyle();
	_bing = load();
	if(_bing.current.url){
		$("#bg1").css("background-image",'url('+_bing.current.url+')');
	}
	loadBgJson(0,loadResponse);//_bing.idx
}catch(ee){
	console.log(ee)
}