// ==UserScript== // @name bilibili plus bilibilijj // @namespace http://qli5.tk/ // @description 在bilibili界面上直接添加jj的三种下载链接。请登录jj以跳过广告页。播放弹幕可使用potplayer等。视频弹幕同名即可自动加载,第一行false改为true即可打开测试功能。 // @include http://www.bilibili.com/video/av* // @include http://bangumi.bilibili.com/anime/* // @version 0.1 // @grant GM_xmlhttpRequest // @author qli5 // @copyright qli5, 2014+, 田生 // @license Mozilla Public License 2.0; http://www.mozilla.org/MPL/2.0/ // @require https://greasyfork.org/scripts/2231-bilibili-ass-danmaku-downloader/code/bilibili%20ASS%20Danmaku%20Downloader.user.js // @connect-src www.bilibilijj.com // @connect-src comment.bilibili.com // @downloadURL none // ==/UserScript== // 感谢所有大佬,鄙人只做了微小的工作。 (function() { // 本测试功能适合一次会下载很多视频的场景,可以尽量方便地把mp4的文件名改成ass的。这是我能在同源限制下想出的最好办法。请诸大佬指教。 var testingMP4Rename=false; // 本测试功能适合看完就删的场景,可以将ass的文件名改成mp4的。文件名一般是数字乱码,也有可能失败,但不需要多点击。 var testingASSRename=false; window.removeEventListener('DOMContentLoaded', init); initFont(); GM_xmlhttpRequest({ method: 'GET', url: 'http://www.bilibilijj'+location.href.match(/\.com.*/)[0], onload: function(response) { var doc = new DOMParser().parseFromString(response.responseText, 'text/html'); var links = document.createElement('div'); var aa; aa=document.createElement('a'); aa.href='http://www.bilibilijj'+location.href.match(/\.com.*/)[0]; aa.textContent='bilibilijj'; links.appendChild(aa); var input,button; if (testingMP4Rename) { input=document.createElement('input'); input.type='text'; input.value='请选择ass...'; input.onclick=function() {this.select();}; links.appendChild(input); button=document.createElement('button'); button.onclick=function() { try { input.select(); document.execCommand('copy'); } catch(e) { console.warn('Oops, copy failed'+e); } }; button.textContent='copy'; links.appendChild(button); } var listCols=doc.getElementById('Right_Main'); for (var i=0;i span.Data_Flv > span.Data_Data'); mp4Div=list.children[j].querySelector('span.Data_Main > span.Data_Mp4 > span.Data_Data'); assDiv=list.children[j].querySelector('span.Data_Main > span.Data_Ass > span.Data_Data'); if (list.children[j].querySelector('span.PBoxName').textContent == '下载地址(右侧方块切换类型)') name=assDiv.children[0].title.slice(0,-7); else name=list.children[j].querySelector('span.PBoxName').textContent; cid=assDiv.children[1].getAttribute('href').match(/cid\=\d*(?=&)/)[0].slice(4); links.appendChild(document.createElement('br')); links.appendChild(document.createTextNode(name)); links.appendChild(document.createTextNode(' ')); var a; a=document.createElement('a'); a.href='http://www.bilibilijj.com'+flvDiv.querySelector('a').getAttribute('href'); a.textContent='flv'; links.appendChild(a); links.appendChild(document.createTextNode(' ')); a=document.createElement('a'); if (testingASSRename) a.onclick=function() {this.nextSibling.nextSibling.download=this.href.match(/DownLoad\/\d*/)[0].slice(9)+'-1-hd.ass';}; if (mp4Div.querySelector('a')) a.href='http://www.bilibilijj.com'+mp4Div.querySelector('a').getAttribute('href'); else a.onclick=function() {alert('no mp4 data\nplease check jj');}; a.textContent='mp4'; links.appendChild(a); links.appendChild(document.createTextNode(' ')); a=document.createElement('a'); a.onclick=(function(name, cid, self){ return function () { if (self.href.slice(0,4)!='blob') { fetchDanmaku(cid, function (danmaku) { var ass = generateASS(setPosition(danmaku), { 'title': name, 'ori': location.href, }); // I would assume most users are using Windows var blob = new Blob(['\ufeff'+ass], { type: 'application/octet-stream' }); self.setAttribute('href', window.URL.createObjectURL(blob)); self.click(); }); return false; } if (testingMP4Rename) { input.value=name+'.mp4'; input.select(); } }; })(name, cid, a); a.download=name+'.ass'; a.href='http://www.bilibilijj.com'+assDiv.querySelector('a').getAttribute('href'); a.textContent='ass'; links.appendChild(a); } } } links.style.backgroundColor='white'; links.style.padding='10px'; links.style.border='black'; links.style.borderWidth='thin'; links.style.borderStyle='dashed'; if (location.hostname == 'www.bilibili.com') { links.style.zIndex='500000'; links.style.position='absolute'; links.style.top='0px'; document.querySelector('.v_small').appendChild(links); } else if (location.hostname == 'bangumi.bilibili.com'){ document.querySelector('.v1-bangumi-list-part-wrapper').appendChild(links); } } }); })();