Bing Image Download Button

Add an image download button on Bing's home page.

< Feedback on Bing Image Download Button

Question/comment

§
Posted: 2019-03-18

获取图片名称的代码需要改下

可能bing更新了前端页面,现在脚本获取到的文件名称如下

/th?id=OHR.TofinoCoast_ZH-CN0950198582_1920x1080.jpg&rf=NorthMale_1920x1080.jpg&pid=hp

可以看到存在多余的信息。我简单写了下可以获取到简短的图片名称

//获取图片地址
function getImg() {
  ...

  //从url中取出图片名称
  let picName = picUrl.substring(picUrl.lastIndexOf('/') + 1, picUrl.length)
  // 修改获取图片名称的逻辑  yankj12  2019/3/18
  var re = new RegExp(/\.jpg|\.gif|\.png|\.bmp/);
  var suffixIndex = picUrl.search(re);
  var picSuffix = picUrl.substr(suffixIndex, 4);
  var picNameTmp = picUrl.substring(0,suffixIndex);
  var index1 = picNameTmp.lastIndexOf('.');
  picName = picNameTmp.substring(index1 + '.'.length) + picSuffix;
  //console.log(picName);

  ...

}
levinitAuthor
§
Posted: 2019-03-18
Edited: 2019-03-19

Post reply

Sign in to post a reply.