赞
踩
var evt = document.createEvent('MouseEvents'); evt.initMouseEvent("click", true, true, window,0, 634, 376, 634, 281, false, false, false, false, 0, null); //$('.course-item .course-show:first')[0].dispatchEvent(evt); console.log(evt.isTrusted,typeof(evt),"isTrusted"); evt.isTrusted=true; console.log(evt.isTrusted,"isTrusted"); //$('.course-item .course-show:first')[0].dispatchEvent(evt); //####################################################################################### //####################################################################################### //####################################################################################### var defereds = []; $imgs.each(function() { var dfd = $.Deferred(); $(this).load(dfd.resolve); defereds.push(dfd); }); $.when.apply(null, defereds).done(function() { console.log('load compeleted'); }); 如上修改为 var defereds = []; function getid(name_str) { return $.Deferred(function($dfd) { console.log($dfd,'s1'); chrome.tabs.query({status:"complete"},function (tabs){ for( var i in tabs){ find = tabs[i].title.indexOf(name_str); if(find!=-1){ sleep(3000); $dfd.resolve(tabs[i].id); //console.log($dfd,'e4'); break ; } } }); console.log('run immediately2'); }).promise(); } $.when( getid("锤子商城首页") ) .then(execscript) .then(function(result){console.log(result)}); //此处没有延迟对象 titlelist=[]; $('.course-item').each(function(index,html){ var title = $('.media-body a',this).text(); //相当于目录总目录 var filename = $('.period-list li:first a span',this).text(); var fileurl = $('.period-list li:first a',this).attr('href'); //url1 console.log(index+1,'item'); title = String(index+1)+title; //final folder name var videos = $('.period-list li[data-id] a',this).each(function(index,ele){ title2 = $(this).attr('title'); title2 = String(index+1+title2); videohref = $(this).attr('href'); //console.log(index,$(this).attr('href'),$(this).attr('title'),'href','video'); }); }); //####################################################################################### //####################################################################################### //####################################################################################### reg1 = /<div class="lesson-content" id="lesson-video-content" data-key="(\S+)"[ ]*\n\r*[ ]*data-url="(\S+)"/; $.get("http://www.ydma.com/classroom/11/task/61/course/2461/lesson/9901/learn?taskDayId=0",{}, function(data){ result = reg1.exec(data); tasks.reduce(function(prev,next){… key= result[1]; domain= result[2]; url=domain+'/'+key+ '/'; console.log("result:",url); }),'html'; function get_video_url(url){ return $.Deferred(function($dfd) { $.get(url,{},function(data){ var reg = /<div class="lesson-content" id="lesson-video-content" data-key="(\S+)"[ ]*\n\r*[ ]*data-url="(\S+)"/; var result = reg.exec(data); var key= result[1]; var domain= result[2]; var urls=domain+'/'+key+ '/'; $dfd.resolve(urls); },'html'); //console.log('run immediately2'); }).promise(); } var reg = /<div class="lesson-content" id="lesson-video-content" data-key="(\S+)"[ ]*\n\r*[ ]*data-url="(\S+)"/; $.get("https://slice.ydma.com/course/2461/lesson/9901/771/",{}, function(data){ result = reg1.exec(data); key= result[1]; domain= result[2]; url=domain+'/'+key+ '/'; console.log("result:",url,data); }),'html'; function get_video_extm3ulist(url,domain){ return $.Deferred(function($dfd) { //console.log(url,'url'); $.get(url,{},function(data){ var urls=[]; var reg = /\/[a-zA-Z0-9\/]+/g; var result = data.match(reg); for (var i in result){ urls[i]=domain+'/'+result[i]; }; $dfd.resolve(urls); },'html'); //console.log('run immediately2'); }).promise(); } //正确的参数传递关系是如下 $.when(get_video_urllist("https://slice.ydma.com/course/2461/lesson/9901/771/",'asdf')).then(function(result){console.log(result,'then')}); deferred.resolve( args )返回: Deferred 描述: 解决Deferred(延迟)对象,并根据给定的args参数调用任何完成回调函数(doneCallbacks)。 添加的版本: 1.5deferred.resolve( args ) args 类型: Object 传递给完成回调函数(doneCallbacks)的可选的参数。 当延迟对象被 resolved 时,任何通过 deferred.then或deferred.done 添加的 doneCallbacks,都会被调用。回调函数的执行顺序和它们被添加的顺序是一样的。传递给 deferred.resolve() 的 args 参数,会传给每个回调函数。当延迟对象进入 resolved 状态后,再添加的任何 doneCallbacks,当它们被添加时,就会被立刻执行,并带上传入给 .resolve()的参数。有关详细信息,请参阅文件Deferred object 。 //??????????????????????????????????????????????????????????????? function get_video_extm3ulist(para){ return $.Deferred(function($dfd) { //console.log(para,'m3u1'); $.get(para[0],{},function(data){ var urls=[]; var reg = /\/[a-zA-Z0-9\/]+/g; result = data.match(reg); for (var i in result){ urls[i]=para[1]+'/'+result[i]; }; //console.log(urls,'m3u2'); $dfd.resolve(urls); },'html'); //console.log('run immediately2'); }).promise(); } function get_video_url(url){ return $.Deferred(function($dfd) { //console.log(url,'video1'); $.get(url,{},function(data){ var reg = /<div class="lesson-content" id="lesson-video-content" data-key="(\S+)"[ ]*\n\r*[ ]*data-url="(\S+)"/; var result = reg.exec(data); var key= result[1]; var domain= result[2]; var urls=domain+'/'+key+ '/'; //console.log([urls,domain],'video2'); $dfd.resolve([urls,domain]); },'html'); }).promise(); } url = []; $('.course-item').each(function(num,html){ url[num] = []; var title = $('.media-body a',this).text(); //相当于目录总目录 var filename = $('.period-list li:first a span',this).text(); var fileurl = $('.period-list li:first a',this).attr('href'); //url1 console.log(num+1,'item'); title = String(num+1)+title; //final folder name url[num][0]=[title,filename,fileurl]; $('.period-list li[data-id] a',this).each(function(index,ele){ var title2 = $(this).attr('title'); title2 = String(index+1+title2); videohref = $(this).attr('href'); url[num][index+1]=[title,title2]; //console.log(index,$(this).attr('href'),$(this).attr('title'),'href','video'); $.when(get_video_url(videohref)) .then(function(urls2){return get_video_extm3ulist(urls2)}) .then(function(urlss){url[num][index+1][2]=[urlss];}); }); }); function get_video_extm3ulist(para){ return $.Deferred(function($dfd) { console.log(para,'m3u1'); $.get(para[0],{},function(data){ var urls=[]; var reg = /\/[a-zA-Z0-9\/]+/g; result = data.match(reg); for (var i in result){ urls[i]=para[1]+'/'+result[i]; }; console.log(urls,'m3u2'); $dfd.resolve(urls); },'html'); //console.log('run immediately2'); }).promise(); } function get_video_url(url){ return $.Deferred(function($dfd) { console.log(url,'video1'); $.get(url,{},function(data){ var reg = /<div class="lesson-content" id="lesson-video-content" data-key="(\S+)"[ ]*\n\r*[ ]*data-url="(\S+)"/; var result = reg.exec(data); var key= result[1]; var domain= result[2]; var urls=domain+'/'+key+ '/'; console.log([urls,domain],'video2'); $dfd.resolve([urls,domain]); },'html'); }).promise(); } url = []; $('.course-item').each(function(num,html){ url[num] = []; var title = $('.media-body a',this).text(); //相当于目录总目录 var filename = $('.period-list li:first a span',this).text(); var fileurl = $('.period-list li:first a',this).attr('href'); //url1 console.log(num+1,'item'); title = String(num+1)+title; //final folder name url[num][0]=[title,filename,fileurl]; $('.period-list li[data-id] a',this).each(function(index,ele){ var title2 = $(this).attr('title'); title2 = String(index+1+title2); videohref = $(this).attr('href'); url[num][index+1]=[title,title2]; //console.log(index,$(this).attr('href'),$(this).attr('title'),'href','video'); $.when(get_video_url(videohref)) .then(function(urls2){return get_video_extm3ulist(urls2)}) .then(function(urlss){url[num][index+1][2]=[urlss];}); }); }); //下载第二页视频 url = []; $('.course-item').each(function(num,html){ console.log($(this).children('ul'),num,'ul') url[num] = []; var title = $('.media-body a',this).text(); //相当于目录总目录 if ($('.period-list li:first a .period-state',this).text()=='下载课件'){ var filename = $('.period-list li:first a .title',this).text(); var fileurl = $('.period-list li:first a',this).attr('href'); //url1 console.log(num+1,'item'); title = String(num+1)+title; //final folder name url[num][0]=[title,filename,fileurl]; }else{ url[num][0]=[] } $('.period-list li[data-id] a',this).each(function(index,ele){ var title2 = $(this).attr('title'); title2 = String(index+1+title2); videohref = $(this).attr('href'); url[num][index+1]=[title,title2]; //console.log(index,$(this).attr('href'),$(this).attr('title'),'href','video'); $.when(get_video_url(videohref)) .then(function(urls2){return get_video_extm3ulist(urls2)}) .then(function(urlss){url[num][index+1][2]=urlss;}); }); }); url = url.slice(0,-1) //删除最后一个数组元素 $.when(get_video_url("http://www.ydma.com/classroom/11/task/61/course/2451/lesson/9851/learn?taskDayId=0")) .then(function(urls2){return get_video_extm3ulist(urls2)}) .then(function(urlss){console.log(urlss,'urllistreturn');}); listurl = listurl2.slice(5); for(var i in listurl){ if (i<6){ for(var j in listurl[i]){ if(j==0){ if(listurl[i][j].length != 0){ //加了不为空的判断 []==[]居然为false,想不通 url=listurl[i][j][2]; name='./课件/'+listurl[i][j][1].replace(/^\s*|\s*$/g,"")+'.zip'; console.log(i,j,url,name,'file'); chrome.downloads.download({url:url,filename:name},function(id){}); } }else{ arr = listurl[i][j][2]; for ( var k in arr){ url=arr[k]; filename = arr[k].match(/http.*\/([^\/]+)/); console.log(filename,'filename---------------------------------'); name='./'+listurl[i][j][0].replace(/^\s*|\s*$/g,"")+'/'+listurl[i][j][1].replace(/^\s*|\s*$/g,"")+'/'+filename[1]; console.log(i,j,k,url,name,'video'); chrome.downloads.download({url:url,filename:name},function(id){}); } } } } } imglist=[]; $('#content_views p img').each(function(index,ele){ var url=$(this).attr('src'); var name=$(this).attr('alt')+'.jpg'; imglist[index]=[$(this).attr('alt'),$(this).attr('src')]; //chrome.downloads.download({url:url,filename:name},function(id){}); }); JSON.stringify(imglist) arr = JSON.parse('[["1","https://img-blog.csdnimg.cn/20190823012118320.jpg"],["2","https://img-blog.csdnimg.cn/20190823012154984.jpg"],["3","https://img-blog.csdnimg.cn/20190823012241732.jpg"],["4","https://img-blog.csdnimg.cn/20190823012257571.jpg"],["5","https://img-blog.csdnimg.cn/20190823012315266.jpg"],["6","https://img-blog.csdnimg.cn/20190823012333916.jpg"],["7","https://img-blog.csdnimg.cn/20190823012351508.jpg"],["8","https://img-blog.csdnimg.cn/20190823012406900.jpg"],["9","https://img-blog.csdnimg.cn/20190823012427675.jpg"],["10","https://img-blog.csdnimg.cn/20190823012440982.jpg"],["11","https://img-blog.csdnimg.cn/2019082301251972.jpg"],["12","https://img-blog.csdnimg.cn/20190823012538583.jpg"],["13","https://img-blog.csdnimg.cn/20190823012552148.jpg"],["14","https://img-blog.csdnimg.cn/20190823012606298.jpg"],["15","https://img-blog.csdnimg.cn/20190823012620711.jpg"],["16","https://img-blog.csdnimg.cn/20190823012654105.jpg"],["17","https://img-blog.csdnimg.cn/20190823012721263.jpg"],["18","https://img-blog.csdnimg.cn/20190823012738311.jpg"],["19","https://img-blog.csdnimg.cn/20190823012752808.jpg"]]') for (var i in arr){ url=arr[i][1]; name=arr[i][0]; chrome.downloads.download({url:url,filename:name},function(id){}); } for (var i=0;i<1036;i++){ url='https://v5.weizan.cn/262845/132110276476927034/68225097201_'+String(i)+'.ts'; name='./从0到1带你读懂数据分析/'+String(i); //console.log(i,url,name); chrome.downloads.download({url:url,filename:name},function(id){ chrome.downloads.search({id:id}, function(item){ console.log(i,id,item); }) }); } chrome.downloads.erase({}, function(item){ for (var i in item){ console.log(i,item[i]); //chrome.downloads.resume //chrome.downloads.cancel(item[i].id,function(){console.log('ok');}); } console.log(item,'item'); }) chrome.downloads.onChanged.addListener(function(delta){ if(delta.state=='interrupted'){ console.log(delta.url,delta.id,delta.filename,delta,'change') } });
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。