NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Pastebin Beautifier // @namespace http://pajacyk.pl // @version 0.2 // @description Beautifuje pastebinowe JSONy // @author Marcin Ciarka // @include http://pastebin.* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js // @grant none // ==/UserScript== function isValidJson(text) { if (text.length === 0) return false; if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { console.log('treu'); return true; } console.log('false'); return false; } document.querySelector('textarea').addEventListener("blur", () => { const ugly = document.querySelector('textarea').value; if (isValidJson(ugly)) { const obj = JSON.parse(ugly); const pretty = JSON.stringify(obj, undefined, 4); document.querySelector('textarea').value = pretty; } }); console.log(';)');