Skip to content

Commit

Permalink
新增随机调取bing背景图
Browse files Browse the repository at this point in the history
  • Loading branch information
5iux committed Nov 23, 2020
1 parent 6ab2c28 commit 48135a0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
24 changes: 24 additions & 0 deletions bg/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
作者:D.Young
主页:https://blog.5iux.cn/
github:https://github.com/5iux/sou
日期:2020-11-23
版权所有,请勿删除
使用前请注意务必设置好白名单
*/
header('Content-Type:application/json; charset=utf-8');
//防跨域调用
$allow_origin = array(
//域名白名单
'https://5iux.cn',
'https://www.5iux.cn'
);
header('Access-Control-Allow-Origin:'.$allow_origin);
header('Access-Control-Allow-Methods:POST');
header('Access-Control-Allow-Headers:x-requested-with,content-type');

$jsonlist = file_get_contents("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8");
echo $_GET["callback"].$jsonlist;
?>
25 changes: 17 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,25 @@
<script src="//at.alicdn.com/t/font_400990_j21lstb4wx.js"></script>
<script src="sou.js?t=<?php echo date("ymdhi"); ?>"></script>
<script src="wea.js?t=<?php echo date("ymdhi"); ?>"></script>

<style>
</style>
</head>

<body>
<script>
/*随机bing背景start,如无需求可注释掉*/
$.ajax({
url: './bg/',
dataType: 'json',
error: function() {
console.log('网络错误!');
},
success: function(res) {
//var bgimg;
var x=Math.floor(Math.random()*9);
$("body").append('<style> body{background:url("https://cn.bing.com/'+res.images[x].url+'") no-repeat center/cover;}</style>');
}
});
/*随机bing背景end*/
</script>
<div id="menu"><i></i></div>
<div class="list closed">
<ul>
Expand Down Expand Up @@ -180,10 +193,6 @@
<button><svg class="icon" style=" width: 21px; height: 21px; opacity: 0.5;" aria-hidden="true"><use xlink:href="#icon-sousuo"></use></svg></button>
</form>
<div id="word"></div>
<!--ul>
<li data-s="baidu" target="_blank"><i style="background-image: url(icon/baidu.svg);"></i>百度一下</li>
<li data-s="google" target="_blank"><i style="background-image: url(icon/g.svg);"></i>谷歌一下</li>
</ul-->
</div>
</div>
<div class="foot" style="height: 40px;">
Expand All @@ -198,7 +207,7 @@
作者:D.Young
主页:https://blog.5iux.cn/
github:https://github.com/5iux/sou
日期:2020-11-18
日期:2020-11-23
版权所有,请勿删除
-->
</body>
Expand Down

0 comments on commit 48135a0

Please sign in to comment.