imgur output formatter

Adds fully formatted output containers

Tính đến 01-12-2014. Xem phiên bản mới nhất.

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

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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.

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

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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           imgur output formatter
// @namespace      surrealmoviez.info
// @description    Adds fully formatted output containers
// @include        http://imgur.com/*
// @include        http://www.imgur.com/*
// @include        https://imgur.com/*
// @include        https://www.imgur.com/*
// @version        0.1.5
// @grant          none
// ==/UserScript==

function extractUrls() {

    var imgUrls = [];

    var html = $('body').html();

    var startScript = html.indexOf("var imgurShare = new ImgurShare({");
    var endScript = html.indexOf("imgurShare.init()", startScript);
    var script = html.substring(startScript, endScript);

    var startRowHashes = script.indexOf("hashes:");
    var startHashes = script.indexOf("[{", startRowHashes) + 2;
    var endHashes = script.indexOf("}]", startHashes);
    var hashesString = script.substring(startHashes, endHashes);
    var hashes = hashesString.split("},{");

    var startRowCdnUrl = script.indexOf("cdnUrl:");
    var startCdnUrl = script.indexOf("//", startRowCdnUrl);
    var endCdnUrl = script.indexOf(",", startCdnUrl) - 1;
    var cdnUrl = "http:" + script.substring(startCdnUrl, endCdnUrl);

    $.each(hashes, function (i, v) {

        var startImgID = v.indexOf("hash") + 7;
        var endImgID = v.indexOf(",", startImgID) - 1;
        var imgID = v.substring(startImgID, endImgID);

        var startExt = v.indexOf("ext\":") + 6;
        var endExt = v.indexOf(",", startExt) - 1;
        var ext = v.substring(startExt, endExt);

        imgUrls.push(cdnUrl + "/" + imgID + ext);
    });

    return imgUrls;
}

$(".panel > .social").hide(); // Hide social crap (is duplicated anyway)

var imgUrls = extractUrls();
var plainText = imgUrls.join("\n");
var formattedText = '<center><img src="' + imgUrls.join('">\n\n<img src="') + '"></center>';

var textareaCss = "cursor:pointer; overflow: auto; height: 100px; background-color: #181817; border: 0 none; border-radius: 4px 4px 4px 4px; color: #ABABA1; font-size: 12px; margin-bottom: 5px; padding: 6px; width: 95%;";
var formattedTextBox = '<h3>Formatted images</h3><textarea style="' + textareaCss + '" wrap="off" onclick="this.select();" title="Click to select">' + formattedText + '</textarea>';
var plainTextBox = '<h3>Unformatted images</h3><textarea style="' + textareaCss + '" wrap="off" onclick="this.select();" title="Click to select">' + plainText + '</textarea>';

$(formattedTextBox + plainTextBox).prependTo("#link-codes > div");