Uloz.to Direct Link

Přímé odkazy ve vyhledávání na Uloz.to

目前為 2017-12-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Uloz.to Direct Link
// @namespace    https://github.com/d4nkeroni/ulozto-direct-link
// @version      0.2.0
// @author       d4nkeroni
// @description  Přímé odkazy ve vyhledávání na Uloz.to
// @icon         http://uloz.to/favicon.ico
// @homepageURL  https://github.com/d4nkeroni/ulozto-direct-link
// @supportURL   https://github.com/d4nkeroni/ulozto-direct-link/issues
// @copyright    2015-2018, d4nkeroni
// @license      MIT License
// @include		 http*://*uloz.to/hledej*
// @include		 http*://*ulozto.cz/hledej*
// @include		 http*://*ulozto.sk/hledej*
// @include		 http*://*ulozto.net/hledej*
// @include		 http*://*zachowajto.pl/hledej*
// @include		 http*://*pornfile.cz/hledej*
// @grant        none
// ==/UserScript==
/*jshint multistr: true */

var maxTries = 20;
var time = 500;
var tries = 0;

function fixLinks() {
    tries++;
    if ($(".js-result-item").length > 0) {
        $('<li class="no-txt addToFavourites copyLink"> \
             <a class="t-button-add-to-favourites" rel="tooltip" title="Zobrazit přímý odkaz"> \
               <i class="fi fi-share-alt"></i> \
               <span>Zobrazit přímý odkaz</span> \
             </a> \
           </li>"').insertAfter(".quickDownload");

        $('<div id="confirmCopy" style=" \
          position: fixed; \
          z-index: 999; \
          left: 20%; \
          top: 1%; \
          width: 59%; \
          border: 1px solid #cfcfcf; \
          border-radius: 5px; \
          background-color: #fbfbfb; \
          padding: 5px; \
          display: none; \
          "><input type="text" value="Generování odkazu..." readonly="readonly">\
          <button type="button" style="\
          margin-left: 10px;" id="btnCopy">Zkopírovat</button>\
          <button type="button" style="\
          margin-left: 10px;" id="btnClose">Zavřít</button>\
          </div>').appendTo("body");


        $(".copyLink").on("click", function(event){
            ready = false;
            var item = $(event.target).closest(".js-result-item");
            var link = item.find(".name").find(".jsTrackingLinkRefresh");
            var url = link.attr("href");
            $("#confirmCopy input").attr("value", "Generování odkazu...");
            $("#confirmCopy").css("display", "unset");
            if (url.indexOf("file-tracking") != -1){
                var xhr = new XMLHttpRequest();
                xhr.open("GET", url, true);
                xhr.onreadystatechange = function(e) {
                    if (xhr.status == 200 | 401 && xhr.readyState == 2) {
                        if (url != xhr.responseURL) {
                            link.attr("href", xhr.responseURL);
                            item.find(".media").find(".jsTrackingLinkRefresh").attr("href", xhr.responseURL);
                            item.find(".tools").find(".jsTrackingLinkRefresh").attr("href", xhr.responseURL + "?showDialog=1");
                            $("#confirmCopy input").attr("value", xhr.responseURL);
                            $("#confirmCopy input").select();
                        }
                        else if (url.indexOf("limit-exceeded") != -1) alert("limit-exceeded");
                    }
                };
                xhr.send();
            }
            else {
               $("#confirmCopy input").attr("value", url);
               $("#confirmCopy input").select();
            }
        });

        $("#btnCopy").on("click", function(event){
            $("#confirmCopy input").select();
            try {
                var successful = document.execCommand('copy');
                var msg = successful ? 'successful' : 'unsuccessful';
                console.log('Copying text command was ' + msg);
            } catch (err) {
                console.log('Oops, unable to copy');
            }
            $("#confirmCopy").css("display", "none");
        });
        $("#btnClose").on("click", function(event){
            $("#confirmCopy").css("display", "none");
        });
    } else if (tries < maxTries) window.setTimeout(fixLinks, time);
}
window.setTimeout(fixLinks, time);