de4js helper

Enable Nicify option in de4js

As of 2017-09-25. See the latest version.

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

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 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.

(I already have a user script manager, let me install it!)

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         de4js helper
// @namespace    https://baivong.github.io/de4js/
// @description  Enable Nicify option in de4js
// @version      0.4.0
// @icon         https://i.imgur.com/CJ5MfxV.png
// @author       Zzbaivong
// @license      MIT
// @match        https://baivong.github.io/de4js/
// @noframes
// @connect      jsnice.org
// @supportURL   https://github.com/baivong/de4js/issues
// @run-at       document-idle
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function () {
    'use strict';

    var nicify = document.getElementById('nicify'),
        input = document.getElementById('input'),
        view = document.getElementById('view'),
        redecode = document.getElementById('redecode');

    function jsnice() {
        if (input.value.trim() === '') return;

        view.textContent = 'Please waiting...';
        GM_xmlhttpRequest({
            method: 'POST',
            url: 'http://www.jsnice.org/beautify?pretty=0&rename=1&types=0&suggest=0',
            responseType: 'json',
            data: input.value,
            onload: function (response) {
                output.value = response.response.js;
                document.getElementById('highlight').onchange();
            },
            onerror: function (e) {
                console.error(e);
                view.textContent = 'Internal error. Please try again later.';
            }
        });
    }

    nicify.disabled = false;
    nicify.onchange = jsnice;

    input.addEventListener('input', function () {
        if (nicify.checked) jsnice();
    });

    redecode.addEventListener('click', function () {
        if (nicify.checked) jsnice();
    });

})();