Greasy Fork

Greasy Fork is available in English.

Redacted Preview

Preview songs on Redacted

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Redacted Preview
// @namespace    http://benzy.org/
// @version      0.1
// @description  Preview songs on Redacted
// @author       John Bednarczyk
// @match        https://redacted.ch/torrents*
// @grant        none
// @require      http://code.jquery.com/jquery-latest.js
// ==/UserScript==


(function () {
    'use strict';

    // API KEY
    var apiKey = "YOUR_API_HERE"; // Enter your youtube API here keeping the quotation marks

    // URL to add video link to
    var youtubeURL = "https://www.youtube.com/watch?v=";

    // Get list of all songs
    var song = $("span").filter( function() {
        return ($(this).text().indexOf('(') > -1);
    }); // anywhere match

    // Change the text for every song, also assigns class to each song
    for(var i = 0 ; i < song.length ; i++){
        song[i].setAttribute("class","song");
        song[i].setAttribute("id","song"+i);

        // Create Button
        var button = document.createElement('button');
        button.setAttribute("class","play");

        // Set Style
        button.style.background='LightBlue';
        button.style.borderRadius = "3px";
        button.style.padding = "3px 3px 3px 3px";

        button.innerHTML = "Play";

        // Add Spacing
        song[i].appendChild(document.createTextNode(" "));

        // Add link to end of song
        song[i].appendChild(button);
    }

    // Detect button click
    $('button.play').click(function() {

        // Get Artist/songTitle
        var artist = document.getElementsByTagName("h2")[0].firstChild.text;
        var songTitle = this.previousSibling.parentElement.previousSibling.textContent;

        window.open(youtubeURL + getLink(artist, songTitle));
    });

    // Function to get a VideoID
    function getLink(artist, song){

        // Setup url for api
        var url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&q=' +
            encodeURIComponent(artist) + "-" +
            encodeURIComponent(song) + '&maxResults=1&fields=items(id(videoId))&key=' + apiKey;

        // call api and get videoId
        var xhReq = new XMLHttpRequest();
        xhReq.open("GET", url, false);
        xhReq.send(null);
        var id = JSON.parse(xhReq.responseText);

        return id.items[0].id.videoId;
    }
})();