当前位置:   article > 正文

jquery Deferred savevideo_$("#logdownload").attr('href', filepath);

$("#logdownload").attr('href', filepath);

isTrusted解决方案


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')
    }

});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/63601
推荐阅读
相关标签
  

闽ICP备14008679号