// ==UserScript== // @id heawercher@gmail.com // @name 豆瓣电影C+|MyDoubanMovieHelper|豆瓣|豆瓣电影|douban.movie.com // @namespace Chang_way_enjoying // @version 0.6.6_2016-05-20 // @description 在 movie.douban.com 网站下直接显示下载链接,可通过多个站点获取。 // @author c wt U r // @match https://movie.douban.com/subject/* // @connect pan.baidu.com // @connect mp4ba.com // @connect edmag.net // @connect tl95.com // @connect kat.cr // @require https://cdn.bootcss.com/jquery/2.2.3/jquery.min.js // @require https://cdn.bootcss.com/jBox/0.3.2/jBox.min.js // @grant GM_xmlhttpRequest // @grant GM_setClipboard // @downloadURL none // ==/UserScript== /** * Created by c wt U r on 2016/5/18. * QQ 3099891314 * * node{detailURL,downloadURL,date,type[0,1,2],title} * type[0 , // mag * 1 , // ed2k * 2 , // thunder * ] * TODO 加入book.douban.com的支持 * TODO baidu网盘的链接有效性检测函数 * TODO google 搜索 百度网盘 * TODO baidu网盘已登录用户一键保存 * */ var config = { c01: 3, //config。c01 单个类型在电影网页里面显示的最大数量 }; addCSSfile("https://cdn.bootcss.com/jBox/0.3.2/jBox.min.css"); //jQuery.getScript("https://cdn.bootcss.com/jBox/0.3.2/jBox.min.js", function(data, status, jqxhr) {}); function addCSSfile(url) { $("") .attr({ rel: "stylesheet", type: "text/css", href: url }) .appendTo("head"); } function getDoc(url, callback) { GM_xmlhttpRequest({ method: 'GET', url: url, headers: { 'User-agent': window.navigator.userAgent, 'Content-type': null }, onload: function (responseDetail) { var doc = ''; if (responseDetail.status == 200) { // For Firefox, Chrome 30+ Supported doc = new DOMParser().parseFromString(responseDetail.responseText, 'text/html'); if (doc === undefined) { doc = document.implementation.createHTMLDocument(""); doc.querySelector('html').innerHTML = responseText; } } callback(doc, responseDetail.finalUrl); } }); } function postDoc(url, callback, data) { GM_xmlhttpRequest({ anonymous:true, method: 'POST', url: url, headers: { 'User-agent': window.navigator.userAgent, 'Content-type': 'application/x-www-form-urlencoded' }, data:data, onload: function (responseDetail) { callback(responseDetail.responseText, responseDetail.finalUrl); } }); } function timeago(stime) { var publishTime = new Date(stime); var d_minutes, d_hours, d_days; var timeNow = parseInt(new Date().getTime() / 1000); var d; d = timeNow - publishTime; d_days = parseInt(d / 86400); d_hours = parseInt(d / 3600); d_minutes = parseInt(d / 60); if (d_days > 0 && d_days < 4) { return d_days + "天前"; } else if (d_days <= 0 && d_hours > 0) { return d_hours + "小时前"; } else if (d_hours <= 0 && d_minutes > 0) { return d_minutes + "分钟前"; } else { var s = new Date(publishTime * 1000); // s.getFullYear()+"年"; return (s.getMonth() + 1) + "月" + s.getDate() + "日"; } } // TODO 将绝对时间转换为相对时间; function msg_info(msg) { new jBox('Notice', { content: msg, position: { x: 15, y: 65 }, zIndex: 12000, onInit: function () { this.options.color = 'blue'; }, }); } function msg_warning(msg) { console.log(msg); var color = 'yellow'; new jBox('Notice', { attributes: { x: 'left', y: 'bottom' }, delayClose: 1000 * 30, theme: 'NoticeBorder', color: color, //audio: '/libraries/jBox-' + global.jBoxVersion + '/Source/audio/bling2', // volume: noticeN3Volume, animation: {open: 'slide:bottom', close: 'slide:left'}, onInit: function () { this.options.color = color; this.options.title = "提示"; this.options.content = msg; }, }); } function msg_error(msg) { var color = 'red'; new jBox('Notice', { attributes: { x: 'left', y: 'bottom' }, theme: 'NoticeBorder', color: color, //audio: '/libraries/jBox-' + global.jBoxVersion + '/Source/audio/bling2', // volume: noticeN3Volume, animation: {open: 'slide:bottom', close: 'slide:left'}, onInit: function () { this.options.color = color; this.options.title = "错误警告"; this.options.content = msg; }, }); console.error(msg); } imdb = $("#info").find("a[href^='http://www.imdb.com/title/tt']").text(); title_cn = $("#content").children()[0].firstElementChild.textContent.split(" ")[0]; title_en = undefined;// TODO title_en 可以实现,但更倾向于使用imdb搜索影视; if (!imdb) { msg_error('imdb is null'); } else { if (imdb.startsWith('tt')) { imdb = imdb.slice(2); } } msg = ["IMDB:\t" + imdb, "TITLE:\t" + title_cn].join("\n"); msg_info(msg); var linksTable = { table: undefined, nodes: [], init: function () { var div, h2 = undefined; div = $("
").attr({"data-column-id": "copy", style: "width:33px"}); th = th.html(" "); tr.append(th); th = $(" | ").attr({"data-column-id": "detail", style: "width:33px"}); th = th.html(" "); tr.append(th); th = $(" | ").attr({"data-column-id": "date", style: "width:80px"}); th = th.html("时间"); tr.append(th); th = $(" | ").attr({"data-column-id": "type", style: "width:55px"}); th = th.html("类型"); tr.append(th); th = $(" | ").attr({"data-column-id": "title"}); th = th.html("详细信息"); tr.append(th); //th = $(" | ").attr({"data-column-id": "link"}); //th = th.html("链接"); //tr.append(th); thead.append(tr); this.table.append(thead); this.table.appendTo($("#dtable")); }, clean: function () { $("#dtable").remove(); this.init(); }, _add: function (data) {// TODO 链接文件名太长的,隐藏 thead = $($("#dlinks")[0].firstElementChild); types = {0: "mag", 1: "ed2k", 2: 'thunder'}; var tr, th = undefined; tr = $(' | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
"); th = th.html('详情'); tr.append(th); th = $(" | "); th = th.html('复制'); th.click(function () { url = $(this.firstElementChild).attr("data-src"); GM_setClipboard(url, "{ type: 'text', mimetype: 'text/plain'}"); msg_info("链接已复制"); }); tr.append(th); th = $(" | "); th = th.html("");// TODO data.date tr.append(th); th = $(" | "); th = th.html(types[data.type]); tr.append(th); if (data.title.length > 45) { th = $(' | '); th = th.html(data.title.slice(0, 40) + "..."); th.jBox('Tooltip', { id: 'jBox_dlinks_tooltip', width: 280, closeOnMouseleave: true, animation: 'zoomIn', zIndex: 8000, content: th.attr("data") }); tr.append(th); } else { th = $(' | '); th = th.html(data.title); tr.append(th); } //th = $(" | ");
//th = th.html(data.url);
//tr.append(th);
thead.append(tr);
},
print: function () {
this.clean();
var mag = [];
var ed2k = [];
var thunder = [];
var netdisk = [];
var all = [netdisk, mag, ed2k, thunder,];
for (i = 0; i < this.nodes.length; i++) {
var node = this.nodes[i];
if (node.type === 0) {
mag.push(node);
} else if (node.type === 1) {
ed2k.push(node);
} else if (node.type === 2) {
thunder.push(node);
} else if (node.type === 3) {
netdisk.push(node);
} else {
msg_warning("code:1001 msg:不支持当前链接格式.");
}
}//分类
for (var i = 0, n; (n = all[i]) != null; i++) {
if (n.length) {
//确保唯一
function unique(arr) {
var result = [], hash = {};
for (var i = 0, elem; (elem = arr[i]) != null; i++) {
if (!hash[elem.downloadURL]) {
result.push(elem);
hash[elem.downloadURL] = true;
}
}
return result;
};
n = unique(n);//绕了一大圈,其实只需要确保下载地址的唯一性
//加入
for (var i2 = 0, node; ((node = n[i2]) != null ) && i2 < config.c01; i2++) {
if (node) {
this._add(node);
}
}
}
}
//输出
/*
if (netdisk.length) {
for (i = 0; i < 3; i++) {
var node = netdisk[i];
if (node) {
this._add(node);
}
}
}
if (ed2k.length) {
for (i = 0; i < 3; i++) {
var node = ed2k[i];
if (node) {
this._add(node);
}
}
}
if (mag.length) {
for (i = 0; i < 3; i++) {
var node = mag[i];
if (node) {
this._add(node);
}
}
}
if (thunder.length) {
for (i = 0; i < 3; i++) {
var node = thunder[i];
if (node) {
this._add(node);
}
}
}
*/
},
refresh: function () {
this.nodes = [];
for (i = 0; i < dmovie.sites.length; i++) {
this.nodes = this.nodes.concat(dmovie.sites[i].nodes);
}
this.print();
},
act: function () {
$("#dtable").bootgrid();
}
};
var baidu_netdisk = {
id: "netdisk_table",
nodes: [],
hashtable: {},
init: function () {
var div, h2 = undefined;
div = $(" ").attr({
id: this.id
});
h2 = $(" "); h2 = h2.html("网盘信息"); div.append(h2); $($("div.related-info")[0]).after(div); var tr, th = undefined; this.table = $("
|