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

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

当前为 2017-12-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Bing Daily Picture Download button|必应每日图片下载按钮
  3. // @namespace https://gf.qytechs.cn/en/users/131965-levinit
  4. // @author levinit
  5. // @description Add a button for downloading bing-daily-pictures.添加一个必应每日图片下载按钮。
  6. // @include *://cn.bing.com/
  7. // @include *://www.bing.com/
  8. // @include *://www.bing.com/?*
  9. // @include *://cn.bing.com/?*
  10. // @run-at document-start
  11. // @version 0.1.4
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. //定时器周期行检测今日必应图片是否加载成功
  16. let timer = setInterval(function() {
  17. //获取到今日必应图片信息后添加按钮 停止周期检测
  18. if (getImg().url) {
  19. const imgInfo = getImg()
  20. addBtn(imgInfo)
  21.  
  22. const downloadBtn = document.querySelector('#download-btn') //下载按钮
  23. //用户前后切换了必应图片 图片地址和名称应该对应改变 当用户移动鼠标到图片上时进行检测
  24. downloadBtn.onmouseover = function() {
  25. const newInfo = getImg() //获取图片地址
  26. if (this.href != newInfo.picUrl) {
  27. //如果新获取的地址与下载按钮的地址不同 就更改为新地址和名字
  28. this.href = newInfo.picUrl
  29. this.download = newInfo.picName
  30. }
  31. }
  32.  
  33. clearInterval(timer)
  34. }
  35. }, 233)
  36.  
  37. //获取图片地址
  38. function getImg() {
  39. // 从行内css属性background-image中获取今日必应图片的url()
  40. let picUrl = document.querySelector('#bgDiv').style.backgroundImage
  41.  
  42. //如果css属性background-image写在外部css或者style标签中
  43. if (picUrl === '') {
  44. let style0 = document.styleSheets[0]
  45. let styles = style0.cssRules.length
  46. for (let i = 0; i < styles; i++) {
  47. if (style0.cssRules[i].selectorText === '#bgDiv') {
  48. picUrl = style0.cssRules[i].style.backgroundImage
  49. }
  50. }
  51. }
  52. //图片地址
  53. picUrl = picUrl.substring(5, picUrl.length - 2)
  54. //图片名称
  55. let picName = picUrl.substring(picUrl.lastIndexOf('/') + 1, picUrl.length)
  56. return { picUrl, picName }
  57. }
  58.  
  59. //添加下载按钮
  60. function addBtn(imgInfo) {
  61. //在必应首页添加下载按钮
  62. let btn = document.createElement('a')
  63. let text = null
  64.  
  65. if (navigator.language.indexOf('zh') >= 0) {
  66. text = document.createTextNode('下载今日必应图片')
  67. } else {
  68. text = document.createTextNode('Download Today Bing Pictures')
  69. }
  70.  
  71. btn.id = 'download-btn'
  72. btn.style.cssText =
  73. '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;'
  74. btn.download = imgInfo.picName
  75. btn.href = imgInfo.picUrl
  76. btn.appendChild(text)
  77. document.body.appendChild(btn)
  78. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址