Greasy Fork

Greasy Fork is available in English.

ygg

make a link to the torrent into the front page

当前为 2020-01-10 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ygg
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  make a link to the torrent into the front page
// @author       You
// @include        *://*.yggtorrent.ws/*
// @grant        none
// @require http://greasyfork.icu/scripts/394721-w84kel/code/w84Kel.js?version=763614
// ==/UserScript==

(function() {
    'use strict';
    waitForKeyElements( "#\\#torrents", el => display(el), false );
})();

function display() {
    let el = arguments[0];
    let movies = [];
    let rows = el.querySelector('table').rows;

    for (let i = 1; i < rows.length; i++) {
        let movieCell = rows[i].cells[1];
        let movieLink = movieCell.childNodes[0];
        let movieLinkButton = document.createElement('button');
        let movieId = movieLink.href.split("/").pop().split("-")[0];
        movieCell.classList.add('movieCell');
        movieLink.classList.add('movieLink');
        movieLinkButton.innerText = "download";
        movieLinkButton.classList.add('directLink');
        movieLinkButton.onclick = function() {torrentLink(movieLink.href, movieId)};
        movieCell.appendChild(movieLinkButton);
        movies.push(movieCell);
    }

}

function torrentLink(ref, id) {
    fetch("https://www2.yggtorrent.ws/engine/download_torrent?id=" + id, {
        "credentials":"include",
        "headers":{
            "accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
            "accept-language":"fr-FR,fr;q=0.9,en;q=0.8,en-US;q=0.7",
            "sec-fetch-mode":"navigate",
            "sec-fetch-site":"same-origin",
            "sec-fetch-user":"?1",
            "upgrade-insecure-requests":"1"
        },
        "referrer":ref,
        "referrerPolicy":"no-referrer-when-downgrade",
        "body":null,
        "method":"GET",
        "mode":"cors"
    })
        .then(rep => rep.blob())
        .then(blob => {
        var url = window.URL.createObjectURL(blob);
        var a = document.createElement('a');
        a.href = url;
        a.download = "filename.torrent";
        document.body.appendChild(a); //we need to append the element to the dom -> otherwise it will not work in firefox
        a.click();
        a.remove(); //afterwards we remove the element again
    });
}