@zjy4fun/json-open 0.3.0 → 0.3.1

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 +61 -0
  2. package/package.json +1 -1
package/index.html CHANGED
@@ -478,8 +478,10 @@
478
478
  <div class="panel-header">
479
479
  <span class="label">Input</span>
480
480
  <button id="btn-format" class="primary">Format</button>
481
+ <button id="btn-copy">Copy</button>
481
482
  <button id="btn-sample">Sample</button>
482
483
  <button id="btn-clear">Clear</button>
484
+ <button id="btn-share">Share</button>
483
485
  </div>
484
486
  <textarea class="input-area" id="json-input" placeholder="Paste or type JSON here..." spellcheck="false"></textarea>
485
487
  </div>
@@ -661,8 +663,10 @@
661
663
  var jsonInput = document.getElementById('json-input')
662
664
  var viewer = document.getElementById('viewer')
663
665
  var btnFormat = document.getElementById('btn-format')
666
+ var btnCopy = document.getElementById('btn-copy')
664
667
  var btnSample = document.getElementById('btn-sample')
665
668
  var btnClear = document.getElementById('btn-clear')
669
+ var btnShare = document.getElementById('btn-share')
666
670
  var btnExpandAll = document.getElementById('expand-all')
667
671
  var btnCollapseAll = document.getElementById('collapse-all')
668
672
  var searchInput = document.getElementById('search-input')
@@ -731,6 +735,16 @@
731
735
  // ===== Buttons =====
732
736
  btnFormat.addEventListener('click', doFormat)
733
737
 
738
+ btnCopy.addEventListener('click', function () {
739
+ var text = jsonInput.value.trim()
740
+ if (!text) return
741
+ navigator.clipboard.writeText(text).then(function () {
742
+ var orig = btnCopy.textContent
743
+ btnCopy.textContent = 'Copied!'
744
+ setTimeout(function () { btnCopy.textContent = orig }, 1500)
745
+ })
746
+ })
747
+
734
748
  btnSample.addEventListener('click', function () {
735
749
  jsonInput.value = JSON.stringify({
736
750
  name: 'json-open',
@@ -758,6 +772,33 @@
758
772
  clearSearch()
759
773
  })
760
774
 
775
+ // ===== Share =====
776
+ btnShare.addEventListener('click', function () {
777
+ var input = jsonInput.value.trim()
778
+ if (!input) return
779
+ try {
780
+ // Validate JSON first
781
+ JSON.parse(input)
782
+ } catch (e) {
783
+ // Try smart parse
784
+ try {
785
+ var parsed = smartParse(input)
786
+ input = JSON.stringify(parsed)
787
+ } catch (e2) {
788
+ statusInfo.textContent = 'Cannot share: invalid JSON'
789
+ return
790
+ }
791
+ }
792
+ var encoded = encodeURIComponent(input)
793
+ var url = location.origin + location.pathname + '#json=' + encoded
794
+ navigator.clipboard.writeText(url).then(function () {
795
+ var orig = btnShare.textContent
796
+ btnShare.textContent = 'Link copied!'
797
+ statusInfo.textContent = 'Share link copied (' + formatBytes(url.length) + ')'
798
+ setTimeout(function () { btnShare.textContent = orig }, 2000)
799
+ })
800
+ })
801
+
761
802
  // Ctrl+Enter to format
762
803
  jsonInput.addEventListener('keydown', function (e) {
763
804
  if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
@@ -972,6 +1013,26 @@
972
1013
  }, 0)
973
1014
  })
974
1015
 
1016
+ // ===== Load from URL hash =====
1017
+ ;(function () {
1018
+ function loadFromHash() {
1019
+ var hash = location.hash
1020
+ if (!hash || !hash.startsWith('#json=')) return
1021
+ var encoded = hash.slice(6) // remove '#json='
1022
+ try {
1023
+ var json = decodeURIComponent(encoded)
1024
+ if (json) {
1025
+ jsonInput.value = json
1026
+ doFormat()
1027
+ }
1028
+ } catch (e) {
1029
+ statusInfo.textContent = 'Failed to load shared JSON'
1030
+ }
1031
+ }
1032
+ loadFromHash()
1033
+ window.addEventListener('hashchange', loadFromHash)
1034
+ })()
1035
+
975
1036
  // ===== Theme Toggle =====
976
1037
  ;(function () {
977
1038
  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.1",
4
4
  "description": "JSON Formatter — A fast, zero-dependency JSON formatter & viewer (CLI + Web)",
5
5
  "type": "module",
6
6
  "bin": {