JSON Format

format json for Chromium based browsers

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         JSON Format
// @description  format json for Chromium based browsers
// @namespace    https://www.kookxiang.com/
// @version      1.0
// @author       kookxiang
// @match        https://*/*
// @match        http://*/*
// @grant        GM_addElement
// @run-at       document-body
// ==/UserScript==

if (document.all.length === 4 && document.contentType === 'application/json') {
    var interval;
    var pre = document.querySelector('pre');

    pre.innerHTML = JSON.stringify(JSON.parse(pre.innerHTML), null, 2);
    pre.className = 'language-json';

    GM_addElement('script', { src: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js', onload: 'hljs.highlightElement(document.querySelector("pre"))' });
    GM_addElement('link', { rel: "stylesheet", type: "text/css", href: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/github.min.css" });
}