Skip to content

Instantly share code, notes, and snippets.

@dinh
Forked from jr-codes/open-json.user.js
Created December 21, 2022 21:37
Show Gist options
  • Save dinh/fa340de398d3bfbc093103bd46c34636 to your computer and use it in GitHub Desktop.
Save dinh/fa340de398d3bfbc093103bd46c34636 to your computer and use it in GitHub Desktop.
Userscript for opening JSON in the Chrome JSON Viewer extension
// ==UserScript==
// @name Open JSON
// @version 1.0.0
// @description Opens JSON in a json-viewer window
// @match http://*/*
// @match https://*/*
// ==/UserScript==
const exec = fn => {
const script = document.createElement('script');
script.textContent = `(${fn})()`;
document.head.appendChild(script);
};
const main = () => {
window.openJSON = obj => {
const url = 'chrome-extension://gbmdgpbipfallnflgajpaliibnhdgobh/pages/omnibox.html';
const json = JSON.stringify(obj);
window.open(`${url}?json=${encodeURIComponent(json)}`, '_blank');
};
};
exec(main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment