@zjy4fun/json-open 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.html +60 -17
  2. package/package.json +1 -1
package/index.html CHANGED
@@ -477,9 +477,10 @@
477
477
  <div class="panel panel-left" id="panel-left">
478
478
  <div class="panel-header">
479
479
  <span class="label">Input</span>
480
- <button id="btn-format" class="primary">Format</button>
481
- <button id="btn-sample">Sample</button>
480
+ <button id="btn-format" class="primary">✨ Format</button>
481
+ <button id="btn-copy">📋 Copy</button>
482
482
  <button id="btn-clear">Clear</button>
483
+ <button id="btn-share">🔗 Share</button>
483
484
  </div>
484
485
  <textarea class="input-area" id="json-input" placeholder="Paste or type JSON here..." spellcheck="false"></textarea>
485
486
  </div>
@@ -661,8 +662,9 @@
661
662
  var jsonInput = document.getElementById('json-input')
662
663
  var viewer = document.getElementById('viewer')
663
664
  var btnFormat = document.getElementById('btn-format')
664
- var btnSample = document.getElementById('btn-sample')
665
+ var btnCopy = document.getElementById('btn-copy')
665
666
  var btnClear = document.getElementById('btn-clear')
667
+ var btnShare = document.getElementById('btn-share')
666
668
  var btnExpandAll = document.getElementById('expand-all')
667
669
  var btnCollapseAll = document.getElementById('collapse-all')
668
670
  var searchInput = document.getElementById('search-input')
@@ -731,20 +733,14 @@
731
733
  // ===== Buttons =====
732
734
  btnFormat.addEventListener('click', doFormat)
733
735
 
734
- btnSample.addEventListener('click', function () {
735
- jsonInput.value = JSON.stringify({
736
- name: 'json-open',
737
- version: '0.2.1',
738
- description: 'Open JSON in browser with interactive tree view',
739
- features: ['collapsible tree', 'search & highlight', 'dark theme', 'auto-parse nested JSON'],
740
- author: { name: 'zjy4fun', github: 'https://github.com/zjy4fun' },
741
- stats: { stars: 42, forks: 7, issues: 3 },
742
- tags: ['json', 'viewer', 'cli', 'browser'],
743
- nested_json: '{"deeply": {"embedded": "json string"}}',
744
- active: true,
745
- license: 'MIT'
746
- }, null, 2)
747
- doFormat()
736
+ btnCopy.addEventListener('click', function () {
737
+ var text = jsonInput.value.trim()
738
+ if (!text) return
739
+ navigator.clipboard.writeText(text).then(function () {
740
+ var orig = btnCopy.textContent
741
+ btnCopy.textContent = ' Copied!'
742
+ setTimeout(function () { btnCopy.textContent = orig }, 1500)
743
+ })
748
744
  })
749
745
 
750
746
  btnClear.addEventListener('click', function () {
@@ -758,6 +754,33 @@
758
754
  clearSearch()
759
755
  })
760
756
 
757
+ // ===== Share =====
758
+ btnShare.addEventListener('click', function () {
759
+ var input = jsonInput.value.trim()
760
+ if (!input) return
761
+ try {
762
+ // Validate JSON first
763
+ JSON.parse(input)
764
+ } catch (e) {
765
+ // Try smart parse
766
+ try {
767
+ var parsed = smartParse(input)
768
+ input = JSON.stringify(parsed)
769
+ } catch (e2) {
770
+ statusInfo.textContent = 'Cannot share: invalid JSON'
771
+ return
772
+ }
773
+ }
774
+ var encoded = encodeURIComponent(input)
775
+ var url = location.origin + location.pathname + '#json=' + encoded
776
+ navigator.clipboard.writeText(url).then(function () {
777
+ var orig = btnShare.textContent
778
+ btnShare.textContent = '✅ Link copied!'
779
+ statusInfo.textContent = 'Share link copied (' + formatBytes(url.length) + ')'
780
+ setTimeout(function () { btnShare.textContent = orig }, 2000)
781
+ })
782
+ })
783
+
761
784
  // Ctrl+Enter to format
762
785
  jsonInput.addEventListener('keydown', function (e) {
763
786
  if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
@@ -972,6 +995,26 @@
972
995
  }, 0)
973
996
  })
974
997
 
998
+ // ===== Load from URL hash =====
999
+ ;(function () {
1000
+ function loadFromHash() {
1001
+ var hash = location.hash
1002
+ if (!hash || !hash.startsWith('#json=')) return
1003
+ var encoded = hash.slice(6) // remove '#json='
1004
+ try {
1005
+ var json = decodeURIComponent(encoded)
1006
+ if (json) {
1007
+ jsonInput.value = json
1008
+ doFormat()
1009
+ }
1010
+ } catch (e) {
1011
+ statusInfo.textContent = 'Failed to load shared JSON'
1012
+ }
1013
+ }
1014
+ loadFromHash()
1015
+ window.addEventListener('hashchange', loadFromHash)
1016
+ })()
1017
+
975
1018
  // ===== Theme Toggle =====
976
1019
  ;(function () {
977
1020
  var themeBtn = document.getElementById('theme-toggle')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zjy4fun/json-open",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "JSON Formatter — A fast, zero-dependency JSON formatter & viewer (CLI + Web)",
5
5
  "type": "module",
6
6
  "bin": {