Export Weibo Album to List or Image

批量导出新浪微博相册图片,用于保存、下载

  1. // ==UserScript==
  2. // @name Export Weibo Album to List or Image
  3. // @namespace https://greasyfork.org/zh-CN/users/10666-sbdx
  4. // @version 0.9.20231214
  5. // @description 批量导出新浪微博相册图片,用于保存、下载
  6. // @author sbdx
  7. // @include http*://t.sina.com.cn/*
  8. // @include http*://weibo.com/*
  9. // @include http*://www.weibo.com/*
  10. // @include http*://s.weibo.com/*
  11. // @include http*://photo.weibo.com/*
  12. // @include http*://d.weibo.com/*
  13. // @exclude http://weibo.com/app/*
  14. // @exclude http://weibo.com/app
  15. // @require https://cdn.bootcss.com/jquery/1.8.3/jquery.min.js
  16. // ==/UserScript==
  17. /*
  18. WGET最新版下载地址:https://eternallybored.org/misc/wget/
  19.  
  20. @echo off
  21. REM wget批量下载并且重命名 批处理文件
  22. REM 将URL保存到url.txt文件里,然后执行本批处理
  23. setlocal enabledelayedexpansion
  24. set /a num=0
  25. set zero=00000
  26. FOR /F %%i in (url.txt) do (
  27. set /a num+=1
  28. title !num!
  29. set "name=!zero!!num!"
  30. wget -c -nv %%i -O !name:~-4!.jpg
  31. )
  32. */
  33. jQuery(function(){
  34. var nw,UID,AlbumID,Type,total_pic,imgCountInPage,boolShowPicOrLink;
  35. //$.ajaxSetup({async:false,cache:false});
  36. function ProcessAlbum()
  37. {
  38. for (var p=1,lens=Math.ceil(total_pic/imgCountInPage); p<=lens; p++)
  39. {
  40. //console.log('正在获取第'+p+'页');
  41. let url=document.location.origin+'/photos/get_all?uid=' + UID + '&album_id=' + AlbumID + '&count=' + imgCountInPage + '&page=' + p + '&type=' + Type + '&__rnd='+(new Date().getTime());
  42. console.log('Get '+url);
  43. $.getJSON(url,function(rtn){
  44. //异步调用,返回顺序不一致
  45. plist=rtn.data.photo_list;
  46. for(i=0,plist_len=plist.length;i<plist_len;i++)
  47. {
  48. obj=plist[i];
  49. //only for me
  50. obj.pic_hos='https://ww3.sinaimg.cn';
  51. picurl=obj.pic_host + '/large/' + obj.pic_name;
  52. if(boolShowPicOrLink)
  53. {
  54. nw.document.writeln('<img src="'+picurl+'" border="0" /><br>');
  55. }
  56. else
  57. {
  58. nw.document.writeln('<a href="'+picurl+'" target="_blank">'+picurl+'</a><br>');
  59. }
  60. }
  61. });
  62. }
  63. nw.document.title='加载完成';
  64. }
  65. function GetAlbumPic()
  66. {
  67. UID=$GLOBAL_DETAIL.album_info.uid; //博主ID
  68. AlbumID=$GLOBAL_DETAIL.album_info.album_id; //相册ID
  69. Type=$GLOBAL_DETAIL.type;
  70. total_pic=$GLOBAL_DETAIL.album_info.count.photos; //相片总数
  71. imgCountInPage=30; //每页显示数量
  72. boolShowPicOrLink=true; //显示图片或地址
  73. if(total_pic>10)
  74. {
  75. boolShowPicOrLink=confirm("图片数量过多,请选择显示 图片 或 连接!\n是 - 显示图片 否 - 显示连接");
  76. }
  77. nw=window.open('','output');
  78. nw.document.title='正在载入......';
  79. ProcessAlbum();
  80. }
  81. //单条微博页九宫格大图
  82. function ShowLargeImageInSinglePage()
  83. {
  84. $('.WB_media_wrap .media_box img').each(function(i){this.src=this.src.replace(/(http[s]*:\/\/.+?\/)(.+?)(\/.*)/i,'$1large$3');});
  85. $('.wbpro-feed-content .picture .woo-picture-slot img').each(function(i){this.src=this.src.replace(/(http[s]*:\/\/.+?\/)(.+?)(\/.*)/i,'$1large$3');});
  86. }
  87. //显示相册列表页单页大图
  88. function ShowLargeImageInAlbumPage()
  89. {
  90. console.log('显示相册列表页单页大图');
  91. $('.photoList dt.photo img').each(function(i){
  92. console.log(this.src);
  93. this.src=this.src.replace(/(http[s]*:\/\/.+?\/)(.+?)(\/.*)/i,'$1large$3');
  94. });
  95. }
  96. if (document.location.host == "photo.weibo.com")
  97. {
  98. $("body").append("<div id='sbdx_tools_getAllImage' style='position:absolute;right:10px;top:100px;'><button>显示相册全部图片</button></div>");$("#sbdx_tools_getAllImage").on("click",GetAlbumPic);
  99. $("body").append("<div id='sbdx_tools_AlbumList' style='position:absolute;right:10px;top:130px;'><button>显示单页相册大图</button></div>");$("#sbdx_tools_AlbumList").on("click",ShowLargeImageInAlbumPage);
  100. }
  101. else
  102. {
  103. $("body").append("<div id='sbdx_tools_for9' style='position:absolute;right:10px;top:130px;'><button>单页显示九宫格大图</button></div>");$("#sbdx_tools_for9").on("click",ShowLargeImageInSinglePage);
  104. }
  105.  
  106. $(window).scroll(function(){$("div[id^=sbdx]").each(function(i){$(this).offset({top:$(document).scrollTop()+100+i*30});});});
  107. });