de4js helper

Enable Unreadable option in de4js

当前为 2018-07-11 提交的版本,查看 最新版本

  1. ---
  2. ---
  3. // ==UserScript==
  4. // @name de4js helper
  5. // @namespace https://baivong.github.io/de4js/
  6. // @description Enable Unreadable option in de4js
  7. // @version {{ site.version }}
  8. // @icon https://i.imgur.com/CJ5MfxV.png
  9. // @author {{ site.author }}
  10. // @license {{ site.license }}
  11. // @match {{ site.url }}/de4js/
  12. // @include http://127.0.0.1:4000/de4js/
  13. // @include http://localhost:4000/de4js/
  14. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js?v=a834d46
  15. // @noframes
  16. // @connect jsnice.org
  17. // @supportURL https://github.com/lelinhtinh/de4js/issues
  18. // @run-at document-idle
  19. // @grant GM_xmlhttpRequest
  20. // @grant GM.xmlHttpRequest
  21. // ==/UserScript==
  22.  
  23. (function () {
  24. 'use strict';
  25.  
  26. var nicify = document.getElementById('nicify'),
  27. input = document.getElementById('input'),
  28. output = document.getElementById('output'),
  29. view = document.getElementById('view'),
  30. redecode = document.getElementById('redecode');
  31.  
  32. function jsnice() {
  33. if (!isOnine()) return;
  34. if (input.value.trim() === '') return;
  35.  
  36. view.classList.add('waiting');
  37. GM.xmlHttpRequest({
  38. method: 'POST',
  39. url: 'http://jsnice.org/beautify?pretty=0&rename=1&types=0&packers=0&transpile=0&suggest=0',
  40. responseType: 'json',
  41. data: input.value,
  42. onload: function (response) {
  43. var source = response.response.js;
  44.  
  45. if (source.indexOf('Error compiling input') === 0) {
  46. source = input.value;
  47. } else {
  48. source = response.response.js;
  49. }
  50.  
  51. output.value = source;
  52. document.getElementById('highlight').onchange();
  53. },
  54. onerror: function (e) {
  55. console.error(e); // eslint-disable-line no-console
  56. }
  57. });
  58. }
  59.  
  60. function isOnine() {
  61. nicify.disabled = !navigator.onLine;
  62. return navigator.onLine;
  63. }
  64.  
  65. nicify.disabled = false;
  66. nicify.onchange = jsnice;
  67.  
  68. input.addEventListener('input', function () {
  69. if (nicify.checked) jsnice();
  70. });
  71.  
  72. redecode.addEventListener('click', function () {
  73. if (nicify.checked) jsnice();
  74. });
  75.  
  76. window.addEventListener('online', isOnine);
  77. window.addEventListener('offline', isOnine);
  78. isOnine();
  79.  
  80. })();