Greasy Fork 还支持 简体中文。

豆瓣电影磁力链

在 https://movie.douban.com/ 中进入电影的详细页时,在电影海报下方自动添加与当前电影匹配的磁力链。

Version vom 26.05.2018. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         豆瓣电影磁力链
// @namespace    http://tampermonkey.net/
// @version      0.18.0526.12
// @description  在 https://movie.douban.com/ 中进入电影的详细页时,在电影海报下方自动添加与当前电影匹配的磁力链。
// @author       anntiza
// @match        https://movie.douban.com/subject/*
// @connect      www.wcs123.com
// @run-at       document-idle
// @grant        GM.xmlHttpRequest

// ==/UserScript==

(function() {
    'use strict';

    // 获取电影的标题
    let title = document.querySelector("#content h1 span");
    // 取中文名
    let key = title.innerText.split(" ")[0];

    // 在此点前插入显示磁力结果的表格
    let info = document.querySelector("#interest_sect_level");
    let data=[];

    // 转换搜索结果
    function parsetext(text) {
        let doc = null;
        try {
            doc = document.implementation.createHTMLDocument("");
            doc.documentElement.innerHTML = text;
            return doc;
        }
        catch (e) {
            //  alert("parse error");
        }
    }

    // 将搜索结果保存到数组中
    function make_data(mags){
        let d=[];
        mags.forEach(function(item,index){
            d.push({
                "title":item.querySelector("h3").innerText,
                "url": "http://www.wcs123.com"+item.querySelector("h3>a").href,
                "magnet":   item.querySelector("span>a").href,
                "hot":   item.querySelector("span:nth-child(5)>b").innerText,
                "description":   item.querySelector("span:nth-child(6)").innerText.split(":")[1]
            });
        });
        return d;
    }

    // 创建显示结果的表格
    function create_table(data){
        let table = document.createElement("table");
        let thead = table.createTHead();
        let tbody = table.createTBody();

        // 使用 douban 原有的表格样式
        table.setAttribute("class","olt");

        let tr = document.createElement("tr");
        let th1 = document.createElement("th");
        let magnetTitle = document.createElement("strong");
        magnetTitle.innerText="磁力链";

        th1.appendChild(magnetTitle);
        th1.setAttribute("style","border:1px dashed #dddddd;text-align:center;width:50px;padding:5px;color:#007722;font-size:16px;padding:8px;");
        tr.appendChild(th1);
        var th2 = document.createElement("th");
        th2.innerHTML = "热度";
        th2.setAttribute("style","border:1px dashed #dddddd;text-align:center;width:40px;padding:5px;color:#007722;font-size:16px;padding:8px;");
        tr.appendChild(th2);
        var th3 = document.createElement("th");
        th3.innerHTML = "文件大小";
        th3.setAttribute("style","border:1px dashed #dddddd;text-align:center;width:70px;padding:5px;color:#007722;font-size:16px;padding:8px;");
        tr.appendChild(th3);
        var th4 = document.createElement("th");
        th4.innerHTML = "文  件  标  题";
        //th4.setAttribute("style","text-align: center;");
        th4.setAttribute("style","border:1px dashed #dddddd;text-align:center;padding:5px;color:#007722;font-size:16px;padding:8px;");
        tr.appendChild(th4);

        // 添加表头行
        thead.appendChild(tr);
        table.appendChild(thead);

        if(data.length){
            data.forEach(function(item,index){
                let tr = document.createElement("tr");
                let td1 = document.createElement("td");
                let a = document.createElement("a");
                a.href = item.magnet;
                a.innerText = "磁力链";
                td1.appendChild(a);
                td1.setAttribute("class","pl");
                td1.setAttribute("style","border:1px dashed #dddddd;text-align:center;width:50px;padding:8px;");
                tr.appendChild(td1);
                let td2 = document.createElement("td");
                td2.innerHTML = item.hot;
                td2.setAttribute("class","pl");
                td2.setAttribute("style","border:1px dashed #dddddd;width:40px;padding:8px;");
                tr.appendChild(td2);
                let td3 = document.createElement("td");
                td3.innerHTML = item.description;
                td3.setAttribute("class","pl");
                td3.setAttribute("style","border:1px dashed #dddddd;width:70px;padding:8px;");
                tr.appendChild(td3);
                let td4 = document.createElement("td");
                var p = document.createElement("a");
                p.innerText = item.title.replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi,'').replace(/<[^>]+?>/g,'').replace(/\s+/g,' ').replace(/ /g,' ').replace(/>/g,' ');
                p.title = item.title;
                p.href=item.url;
                p.target="_blank";
                td4.appendChild(p);
                td4.setAttribute("class","pl");
                td4.setAttribute("style","border:1px dashed #dddddd;padding:8px;");
                tr.appendChild(td4);
                tbody.appendChild(tr);
            });
            table.appendChild(tbody);
        }
        else{
            let tr_error = document.createElement("tr");
            let td_error = document.createElement("td");
            td_error.setAttribute("colspan","4");
            td_error.setAttribute("style","border:1px dashed #dddddd;padding:12px;text-align:center;color:#dc3545;font-size:16px;font-weight:bold;");
            td_error.innerText ="当前电影无可用磁力资源!";
            tr_error.appendChild(td_error);
            tbody.appendChild(tr_error);
            table.appendChild(tbody);
        }
        return table;
    }

    GM.xmlHttpRequest({
        method: "GET",
        url: "http://www.wcs123.com/s/"+key+"-hot-desc-1",
        //         headers: {
        //             "User-Agent": "Mozilla/5.0",    // If not specified, navigator.userAgent will be used.
        //             "Accept": "text/xml"            // If not specified, browser defaults will be used.
        //         },
        onload: function(response) {
            // var responseXML = null;
            // Inject responseXML into existing Object (only appropriate for XML content).
            //             if (!response.responseXML) {
            //                 responseXML = new DOMParser()
            //                     .parseFromString(response.responseText, "text/xml");
            //             }
            let result = parsetext(response.responseText);
            let mags = result.querySelectorAll("table.table tbody tr td.x-item");

            data = make_data(mags);
            console.log(data);
            info.parentNode.insertBefore(create_table(data),info);
        }
    });

})();