今年一定島 自動下載圖片

汲汲營營大報社

目前为 2022-08-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 今年一定島 自動下載圖片
  3. // @namespace https://gf.qytechs.cn/zh-TW/scripts/449572
  4. // @description 汲汲營營大報社
  5. // @author 稻米
  6. // @version 2022.08.14.0050.build16299
  7. // @grant none
  8.  
  9. // @include *://*.komica.org/00/*
  10. // @include *://*.komica.org/00/*
  11. // @exclude *://*.komica.org/00/src/*
  12. // @exclude *://*.komica.org/00/thumb/*
  13. // @exclude *.jpg
  14. // @exclude *.png
  15. // @exclude *.webm
  16. // @license WTFPL
  17.  
  18. // ==/UserScript==
  19.  
  20. $(document).ready(function() {
  21. //poi();
  22. poi();
  23. });
  24.  
  25. function poi(){ //只在回應模式套用
  26. //console.log( document.styleSheets );
  27. //console.log(window.location.href);
  28. var tmp=window.location.href;
  29. tmp=tmp.match("\\?res=");
  30. //window.location.href.match("\\?res=")
  31. //console.log(tmp);
  32. if(tmp){
  33. //沒事
  34. }else{
  35. //console.log('非回應');
  36. return 0;//不正確 中止
  37. }
  38.  
  39. if( $('div.thread').length == 1 ){
  40. //沒事
  41. }else{
  42. //回應模式只有一串討論串
  43. return 0;//不正確 中止
  44. }
  45.  
  46.  
  47. var FFF=$('body').attr('poi220815');
  48. if( FFF == 1 ){
  49. return 0;//只執行一個腳本 中止
  50. }else{
  51. $('body').attr('poi220815','1');
  52. }
  53.  
  54. poi建立啟動按鈕();//
  55.  
  56. }
  57.  
  58.  
  59. function poi建立啟動按鈕(){ //建立啟動按鈕
  60. //console.log(arguments.callee.name); //poi2
  61. //$("#threads").before('before');
  62. $(".thread").before('<poi><button type="reset">自動下載</button></poi>');
  63. $("poi >button:contains('自動下載')").click(function(){
  64. poi建立控制台();
  65. });
  66. //
  67.  
  68. }//poi2(){
  69.  
  70. function poi建立控制台(){ //建立控制台
  71. var FFF=$('#poi220814box');
  72. if( FFF.length > 0 ){
  73. return 0;//只產生一個控制台 中止
  74. }else{
  75. //沒事
  76. }
  77.  
  78.  
  79. $('.thread').prepend('<div id="poi220814box">未完成</div>');
  80. //$('#poi220814a').attr('style','');
  81. $('#poi220814box').css({
  82. 'background':'rgb(200,200,200)',
  83. 'color':'rgb(100,100,100)',
  84. 'text-align':'initial',
  85. 'width':'400px',
  86. 'height':'400px',
  87. });
  88. $('#poi220814box').text('');
  89.  
  90. $('#poi220814box').append('<button type="reset" id="poi220814f"> 標示樓層</button><br/>');
  91. $("#poi220814f").click(function(){
  92. poi標示樓層();
  93. });
  94.  
  95. $('#poi220814box').append('<input type="text" size="8" value="0,3-5,10,4-7" placeholder id="poi220814rgi"><button type="reset" id="poi220814rg">輸入範圍</button><br/>');
  96. $("#poi220814rg").click(function(){
  97. poi輸入範圍();
  98. });
  99.  
  100.  
  101. $('#poi220814box').append('<img id="poi220815img01" style="width:100px;height:100px;"><a id="poi220815aa01" href="#">†</a><br/>');
  102.  
  103. $('#poi220814box').append('<div id="poi220815m">訊息</div><br/>');
  104. $('#poi220815m').css({
  105. 'display':'block',
  106. 'font-family':'monospace',
  107. 'white-space':'pre',
  108. });
  109.  
  110.  
  111.  
  112. }//
  113.  
  114. function poi輸入範圍(){ //輸入範圍
  115. //console.log( 'poi輸入範圍' );
  116. var FFF='';
  117. FFF=$('#poi220814rgi').val();
  118. //console.log( FFF );
  119. FFF=FFF.split(',');//字串轉陣列
  120. console.log( FFF );
  121. var str_ary=FFF;
  122. str_ary.forEach(function( item,index ){//遍歷元素
  123. console.log( item,index );
  124. var aa=item.search("-");
  125. //console.log( aa );
  126. if(aa != -1){
  127. //console.log( 'yy' );
  128. var aa2=item.split('-');
  129. //console.log( aa2 );
  130. var str='';
  131. if(aa2[0]==''){str='skip';}
  132. if(aa2[1]==''){str='skip';}
  133. if(str=='skip'){
  134. $('#poi220815m').append('<br/>輸入範圍 錯誤');
  135. }else{
  136. //console.log( '???' );
  137. aa2[0]=parseInt(aa2[0]);
  138. aa2[1]=parseInt(aa2[1]);
  139. //console.log( aa2 );
  140. for(let i = aa2[0]; i <= aa2[1]; i++) {
  141. //console.log( i );
  142. str_ary.push(i);
  143. }//for
  144. //delete str_ary[index];//處理過的元素就刪除
  145. }
  146. //console.log( str_ary );
  147.  
  148. }//if
  149. });//foreach
  150. //
  151. poi輸入範圍2(str_ary);
  152.  
  153.  
  154. }//輸入範圍
  155. function poi輸入範圍2(in1){
  156. var str_ary=in1;
  157. //
  158. str_ary.forEach(function( item,index ){//遍歷元素
  159. str_ary[index]=parseInt(item);//轉換成整數
  160. });
  161. //console.log( FFF );
  162.  
  163. str_ary=str_ary.filter(function(item,index){
  164. //console.log( FFF );
  165. //var found=item.isInteger();
  166. if( parseInt(item) === item ){return true;}//留下整數
  167. });
  168.  
  169. str_ary.sort(function(a, b){return a - b});//排序 //由小到大
  170.  
  171. str_ary.forEach(function( item,index ){//遍歷元素
  172. str_ary[index]=parseInt(item);//轉換成整數
  173. });
  174.  
  175. str_ary.forEach(function( item,index ){//遍歷元素
  176. var found = str_ary.indexOf( item );
  177. if(found == index){
  178. //沒事
  179. }else{
  180. delete str_ary[index];//刪除
  181. }
  182. });
  183.  
  184. //console.log( str_ary );
  185.  
  186. str_ary=str_ary.filter(function(item,index){
  187. //console.log( FFF );
  188. //var found=item.isInteger();
  189. if( parseInt(item) === item ){return true;}//留下整數
  190. });
  191.  
  192. console.log( str_ary );
  193. poi有效的樓層(str_ary);
  194. }
  195.  
  196. function poi有效的樓層(str_ary){
  197. //console.log( 'poi有效的樓層' );
  198.  
  199. var FFF=$('.thread').find('.post');
  200. //console.log( FFF );
  201.  
  202. var aaa1=[];
  203. str_ary.forEach(function( item,index ){//遍歷元素 item=指定的樓層
  204. //console.log( item,index );
  205. //console.log( FFF[item] );
  206. aaa1.push( FFF[item] );
  207. });
  208.  
  209. //console.log( aaa1 );//指定範圍內的文章
  210.  
  211. FFF='';
  212. var aaa1b=[];
  213. aaa1.forEach(function( item,index ){//遍歷元素
  214. //console.log( item,index );
  215. FFF= $(item).find('img');
  216. if( FFF.length > 0){ //有找到圖片
  217. //console.log( FFF );
  218. //aaa1b.push( item );
  219. //aaa1b.push( $(FFF[0]).attr('src') );//縮圖
  220.  
  221. var 連結=$(FFF[0]).parent().attr('href');
  222. //console.log( 連結 );
  223. var chk=連結.match(/jpg$/);
  224. //var chk2=連結.match(/png$/);//png 會被壓成jpg??
  225. if( chk ){ //由於使用圖片CDN繞過 K島的'沒有允許跨來源資源共用'的限制 暫時只接受jpg格式
  226. aaa1b.push( 連結 );
  227. }else{
  228. //只接受jpg
  229. delete str_ary[index];
  230. }
  231.  
  232.  
  233.  
  234. }else{
  235. //沒找到圖片
  236. delete str_ary[index];
  237. }
  238. });
  239.  
  240. //console.log( str_ary );
  241. str_ary=str_ary.filter(function(item,index){
  242. //console.log( FFF );
  243. //var found=item.isInteger();
  244. if( parseInt(item) === item ){return true;}//留下整數
  245. });
  246. //
  247. if( str_ary.length > 0){ //有
  248. FFF=''+str_ary.toString();
  249. }else{
  250. FFF='無';
  251. }
  252.  
  253. console.log( FFF );//有效的樓層
  254. $('#poi220815m').append('<br/>有效的樓層:'+FFF);
  255.  
  256. //console.log( aaa1b );//要下載的圖片連結
  257. FFF=0;
  258. FFF=[FFF,aaa1b];
  259. //
  260. poi下載圖片(FFF); //啟動下載程序
  261.  
  262. }//
  263.  
  264. function poi下載圖片(traveler){
  265. var cc=traveler[0];
  266. var aaa1b=traveler[1];
  267. //
  268. console.log( cc,aaa1b.length );
  269. //
  270. if( cc < aaa1b.length){
  271. //沒事
  272. console.log( 'yy' );
  273. }else{
  274. console.log( 'nn' );
  275. $('#poi220815m').append('<br/>正常結束');
  276. return 0;//不正確 中止
  277. }
  278. $('#poi220815m').append('<br/>'+'('+cc+'/'+aaa1b.length+')');
  279.  
  280. var url=aaa1b[cc];
  281. url='https://images.weserv.nl/?url='+url+'&output=jpg&q=85&filename=1660523624393&w=2048&h=2048&fit=inside&we';
  282. //blocked by CORS policy: No 'Access-Control-Allow-Origin'
  283. //K島圖片沒有允許跨來源資源共用 用圖片CDN處理一下
  284.  
  285. console.log( url );
  286. var xhr = new XMLHttpRequest();
  287. xhr.onprogress = function(e){
  288. //console.log( 'xhr.onprogress' );
  289. var aa=0.0 + (e.loaded / e.total);
  290. aa= (aa * 100);//百分比
  291. var aa3 = aa.toFixed(2);//取小數2位
  292. var new_aa='';
  293. new_aa=''+aa3+'%';
  294. //console.log( new_aa );
  295. var ee = document.querySelector("#poi220815aa01");
  296. //var aa = document.getElementById('poi220815aa01');
  297. ee.innerHTML=new_aa;
  298.  
  299.  
  300. };
  301.  
  302. xhr.onreadystatechange = function(e){
  303. if(this.readyState == 4){
  304. if( this.status == 200 ){
  305. console.log( this.getAllResponseHeaders() );
  306. poi下載圖片2(traveler,this);//讀取圖片
  307. }
  308. }
  309. };
  310.  
  311.  
  312.  
  313. xhr.open('GET', url);
  314. xhr.responseType = 'blob';
  315. xhr.send();
  316.  
  317. }
  318.  
  319. function poi下載圖片2(traveler,this2){
  320. //console.log( traveler,this2 );
  321. var cc=traveler[0];
  322. //
  323. var img = document.getElementById('poi220815img01');
  324. img.onload = function(e){
  325. poi下載圖片3(traveler,img.src);
  326. };
  327. img.src = window.URL.createObjectURL(this2.response);
  328.  
  329. }//
  330.  
  331. function poi下載圖片3(traveler,in1){
  332. //console.log( traveler,in1 );
  333. var cc=traveler[0];
  334. //
  335. var aa = document.getElementById('poi220815aa01');
  336. aa.href = in1;
  337. aa.download='';//自動下載blob
  338. aa.click();
  339. //aa.href = '#';
  340. //
  341. $("#poi220815img01").slideUp( 1000 ).slideDown( 1000 ,function(){
  342. traveler[0]=cc+1;
  343. //console.log( traveler );
  344. poi下載圖片(traveler);
  345. });
  346. }
  347.  
  348.  
  349. function poi標示樓層(){ //標示樓層
  350. var FFF='';
  351. FFF=$('.thread').find('.post-head');
  352. //console.log( FFF );
  353. var cc=0;
  354. FFF.each(function( index,item ){//遍歷元素
  355. //console.log( index,item );
  356. $(item).prepend('<h1 style="text-align:left;">'+cc+'</h1>');//append
  357. cc++;
  358. });
  359.  
  360. }
  361.  
  362.  
  363. function poi_處理(){
  364. var aa = $('.file-text');
  365. //console.log( aa );
  366. aa.each(function( index,item ){//個別討論串
  367. var FFF=$(item).find('a').attr('href');
  368. console.log( FFF );
  369. if( /jpg$/.test( FFF ) ){
  370. poi4(item);
  371. } //不處理
  372. });
  373.  
  374. }
  375.  
  376.  

QingJ © 2025

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