Created
February 21, 2017 02:17
-
-
Save sarices/d37c514cbbd03b563b086e9bb7bfe596 to your computer and use it in GitHub Desktop.
subhd.com 生成直接下载链接
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name subhd.com 直接下载 | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description 直接下载subhd.com的字幕 | |
// @author sarices | |
// @match http://subhd.com/a/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function downloadFile(fileName, content){ | |
console.log(fileName); | |
try{ | |
var aLink = document.createElement('a'); | |
var blob = new Blob([content]); | |
var evt = document.createEvent("HTMLEvents"); | |
evt.initEvent("click"); | |
aLink.download = fileName; | |
aLink.href = URL.createObjectURL(blob); | |
aLink.dispatchEvent(evt);}catch(e){console.log(e);} | |
} | |
$.post('/ajax/down_ajax',{sub_id:$("#down").attr("sid")},function(data){; | |
var html = '<a href="'+data.url+'" style="color:red;">直接下载</a> '; | |
$('#down').before(html); | |
$('#down').remove(); | |
},'json'); | |
var previews = $('.box a'); | |
var items = []; | |
for(var i=0;i<previews.length;i++){ | |
var item = $(previews[i]).data();; | |
var html = ''; | |
html += ' <a href="javascript:void(0);" class="subhd-download-sub" data-name="'+item.nam+'" data-id="'+item.con+'">下载</a>'; | |
var first = $(previews[i]).parent().parent().find('td'); | |
$(first.find('div')[0]).append(html); | |
$('.subhd-download-sub').bind('click',function(){ | |
var dd = $(this).data(); | |
var param = {}; | |
param.ff=dd.id; | |
$.post('/ajax/file_ajax',param,function(data){ | |
//console.log(data); | |
downloadFile(dd.name,data.texx); | |
},'json'); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment