frisch's Utilities

Combines several userscripts. Includes Shift-Copy, Image Transformation, Html Element Deletion

目前為 2017-01-17 提交的版本,檢視 最新版本

// ==UserScript==
// @name         frisch's Utilities
// @namespace    http://null.frisch-live.de/
// @version      0.27
// @description  Combines several userscripts. Includes Shift-Copy, Image Transformation, Html Element Deletion
// @author       frisch
// @grant        GM_openInTab
// @include        *
// ==/UserScript==
console.log("Initializing frisch Utilities...");

var jq = document.fExt.jq;
var ctxUtil = document.fExt.ctxMenu.addCtxSub("Utilities");

// #################### Shift-Copy - Start
var cpyText = '';

function clickOverride(e){
    var retVal = true;
    if(e.shiftKey){
        e.preventDefault();
        var src =  document.fExt.getSelection() || document.fExt.getSource(e.target);
        switch(e.which){
            case 1:
                document.fExt.clipboard("Copy", src);
                retVal = false;
                break;
            case 2:
                cpyText += src + '\n';
                retVal = false;
                break;
            case 3:
                break;
            default:
                break;
        }
    }

    return retVal;
}

jq(document).on("auxclick", clickOverride);
jq(document).on("click", clickOverride);

jq(document).keyup(function(e) {
    if (e.which === 16){ // Shift
        if(cpyText.length > 0)
            document.fExt.clipboard("Copy", cpyText);

        cpyText = '';
    }
});
// #################### Shift-Copy - End

// #################### Html Elements Deleter - Start

var ctxDelHtml = document.fExt.ctxMenu.addCtxItem("Delete Element", ctxUtil);
ctxDelHtml.Action = function(event, sender, actor) {
    if(delHtmlTarget !== undefined) {
        jq(delHtmlTarget).remove();
        delHtmlTarget = undefined;
    }
};
var delHtmlTarget;


// #################### Html Elements Deleter - End

// #################### GENERAL CTX HANDLING - Start
jq("#fExtContextMenu").on("fExtContextMenuOpening", function(event, actor){
    delHtmlTarget = actor;
});
// #################### GENERAL CTX HANDLING - End

// #################### Image Rotation - Start

var subTransf = document.fExt.ctxMenu.addCtxSub("Transformation", ctxUtil);

document.fExt.ctxMenu.addCtxItem("Rotate left", subTransf).Action = function(event, sender, actor){
    document.fExt.rotate(actor, -90);
};

document.fExt.ctxMenu.addCtxItem("Rotate right", subTransf).Action = function(event, sender, actor){
    document.fExt.rotate(actor, 90);
};

document.fExt.ctxMenu.addCtxItem("Zoom in", subTransf).Action = function(event, sender, actor){
    document.fExt.zoomIn(actor, 20);
};

document.fExt.ctxMenu.addCtxItem("Zoom out", subTransf).Action = function(event, sender, actor){
    document.fExt.zoomOut(actor, 20);
};

// #################### Image Rotation - End

// #################### Cloud Converter - Start
var allowedExtensions = ["webm", "gif"];
var cApiKey = 'pUrKocUqgi32gMrbsDNgqhfTu6leQzBhpI5PhqgzWkdOoysidU892f0M9AvjJUBW5gVpgWWhTQdybz54ygK3cQ'; // Enter your API-Key here, get it at https://cloudconvert.com/

if(cApiKey.length > 0) {
    var jq = document.fExt.jq;
    var ccContainer = jq("<div id='ccContainer' style='display:none; width: 60px; height: 18px; border: 2px solid black; font-weight: bold; text-align: center; padding: 2px 4px; position: absolute; background-color: #fff;' ><a href='#' id='ccLink' style=''>Convert</a></div>");
    ccContainer.appendTo("body");

    var ctxItemConv = document.fExt.ctxMenu.addCtxItem('Convert to MP4', ctxUtil);
    ctxItemConv.Action = function(event, sender){
        document.fExt.message("Starting conversion...");
        var src = jq("#ccLink").attr("href");
        var ext = grabExtension(src);

        jq.ajax({
            url: "https://api.cloudconvert.com/process",
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Authorization", cApiKey);
            },
            type: 'POST',
            dataType: 'json',
            data: {
                "apikey": cApiKey,
                "inputformat" : ext,
                "outputformat": "mp4"
            },
            success: function (data) {
                var convertLnk = "https:" + data.url;
                startConversion(src, convertLnk);
                console.log("Process URL = " + convertLnk);
            },
            error: function(data){
                document.fExt.message("Error converting file: " + data.responseText);
            }
        });
        return false;
    };

    jq("#fExtContextMenu").on("fExtContextMenuOpening", function(event, actor){
        var src = document.fExt.getSource(actor.get(0));
        var ext = grabExtension(src);

        ctxItemConv.Toggle(jq.inArray(ext, allowedExtensions) >= 0);
        jq("#ccLink").attr("href",src);
    });
}
else {
    console.log("No CloudConverter APIKey found.");
}

function startConversion(srcLnk, convLnk){
    document.fExt.message("Processing item...");

    jq.ajax({
        url: convLnk,
        type: 'POST',
        dataType: 'json',
        data: {
            "wait": true,
            "input": "download",
            "file": srcLnk,
            "outputformat": "mp4"
        },
        success: function(data){
            var url = "https:" + data.output.url;
            GM_openInTab(url, true);
            document.fExt.message();
        },
        error: function(data){
            document.fExt.message("Error converting " + srcLnk + ": " + data.responseText);
        }
    });
}

function grabExtension(src){
    var start, end;

    start = src.lastIndexOf(".") + 1;
    if(src.lastIndexOf("?") >= 0)
        end = src.lastIndexOf("?");
    else
        end = src.length;

    return src.substring(start, end);
}

// #################### Cloud Converter - End

// #################### Image Info - Start
/*
document.fExt.ctxMenu.addCtxItem("View Image Info", ctxUtil).Action = function(event, sender, actor){
    $.getImageData({
        url: actor.get(0).src,
        success: function(image){
            // Do something with the now local version of the image
            debugger;
        },
        error: function(xhr, text_status){
            // Handle your error here
        }
    });
};
*/
// #################### Image Info - End
// YouTubeInMP4 - Start
var ytimp4Url = "http://youtubeinmp4.com/youtube.php?video=";
document.fExt.ctxMenu.addCtxItem("Download on Youtubeinmp4.com", ctxUtil).Action = function(event, sender, actor){
    var src = window.location.href;
    if(src.indexOf("/watch") < 0)
        src = document.fExt.getSource(actor.get(0));

    var url = encodeURI(ytimp4Url + src);
    GM_openInTab(url);
};
// YouTubeInMP4 - End

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址