pinokiod 3.2.151 → 3.2.153

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.
@@ -399,17 +399,30 @@ nav .logo {
399
399
  font-size: 14px;
400
400
  padding: 10px;
401
401
  }
402
- nav.error-message .btn {
402
+ .error-message .btn i {
403
+ margin-right: 10px;
404
+ }
405
+ .error-message .btn {
406
+ margin-top: 20px;
407
+ align-items: center;
408
+ display: flex;
403
409
  letter-spacing: 0px;
404
- background: royalblue;
410
+ background: black;
411
+ color: yellow;
405
412
  font-size: 20px;
406
- padding: 10px 20px;
413
+ padding: 10px 30px;
407
414
  }
408
- nav.error-message {
415
+ .error-message {
416
+ display: flex;
417
+ flex-direction: column;
418
+ justify-content: center;
419
+ align-items: center;
420
+ font-weight: bold;
409
421
  background: yellow !important;
410
422
  flex-grow: 1;
411
- padding: 50px;
423
+ padding: 0 50px;
412
424
  font-size: 40px;
425
+ line-height: 40px;
413
426
  color: black;
414
427
  letter-spacing: -2px;
415
428
  }
@@ -629,11 +642,11 @@ body.dark .loader-container {
629
642
  -->
630
643
  </aside>
631
644
  <% if (error) { %>
632
- <nav class='error-message'>
633
- <div><i class="fa-solid fa-rotate"></i> <%=error%></div>
634
- <div class='flexible'></div>
635
- <a class='btn' target="_blank" href="https://program.pinokio.computer/#/?id=install">Download</a>
636
- </nav>
645
+ <div class='error-message'>
646
+ <h1><i class="fa-solid fa-rotate"></i></h1>
647
+ <div><%=error%></div>
648
+ <a class='btn' target="_blank" href="https://program.pinokio.computer/#/?id=install"><i class="fa-solid fa-square-arrow-up-right"></i> Download</a>
649
+ </div>
637
650
  <% } else { %>
638
651
  <div class='container'>
639
652
  <nav>
@@ -670,892 +683,892 @@ body.dark .loader-container {
670
683
  <% } %>
671
684
  </main>
672
685
  </div>
673
- <% } %>
674
- <script>
675
- let loaded = {}
676
- let cursorIndex = 0;
677
- const n = new N()
678
- const getTarget = (href) => {
679
- let u
680
- if (href.startsWith("http")) {
681
- return href
682
- } else if (href.startsWith("/")) {
683
- u = new URL("http://localhost" + href)
684
- u.search = ""
685
- return u.pathname
686
- } else {
687
- u = new URL("http://localhost/" + href)
688
- u.search = ""
689
- return u.pathname
686
+ <script>
687
+ let loaded = {}
688
+ let cursorIndex = 0;
689
+ const n = new N()
690
+ const getTarget = (href) => {
691
+ let u
692
+ if (href.startsWith("http")) {
693
+ return href
694
+ } else if (href.startsWith("/")) {
695
+ u = new URL("http://localhost" + href)
696
+ u.search = ""
697
+ return u.pathname
698
+ } else {
699
+ u = new URL("http://localhost/" + href)
700
+ u.search = ""
701
+ return u.pathname
702
+ }
690
703
  }
691
- }
692
- const subUrlOf = (s, f) => {
704
+ const subUrlOf = (s, f) => {
693
705
 
694
- let subsetUrl = (s.startsWith("http") ? s : "http://localhost" + s)
695
- let fullUrl = (f.startsWith("http") ? f: "http://localhost" + f)
706
+ let subsetUrl = (s.startsWith("http") ? s : "http://localhost" + s)
707
+ let fullUrl = (f.startsWith("http") ? f: "http://localhost" + f)
696
708
 
697
- const subsetParsed = new URL(subsetUrl)
698
- const fullParsed = new URL(fullUrl)
709
+ const subsetParsed = new URL(subsetUrl)
710
+ const fullParsed = new URL(fullUrl)
699
711
 
700
- if (subsetParsed.pathname !== fullParsed.pathname) {
701
- return false;
702
- }
712
+ if (subsetParsed.pathname !== fullParsed.pathname) {
713
+ return false;
714
+ }
703
715
 
704
- // Check if all search parameters in the subset URL are present in the full URL
705
- for (const [key, val] of subsetParsed.searchParams) {
716
+ // Check if all search parameters in the subset URL are present in the full URL
717
+ for (const [key, val] of subsetParsed.searchParams) {
706
718
 
707
- if (!fullParsed.searchParams.has(key)) {
708
- return false
709
- }
710
- if (fullParsed.searchParams.get(key) !== val) {
711
- return false
719
+ if (!fullParsed.searchParams.has(key)) {
720
+ return false
721
+ }
722
+ if (fullParsed.searchParams.get(key) !== val) {
723
+ return false
724
+ }
712
725
  }
713
- }
714
726
 
715
- return true;
716
- }
717
- const renderCursor = () => {
718
- document.querySelectorAll(".selectable").forEach((el) => {
719
- el.classList.remove("cursor")
720
- })
721
- const target = document.querySelector(".selectable[data-index='" + cursorIndex + "']")
722
- target.classList.add("cursor")
723
- }
724
- const nav = (type) => {
725
- let targetFrame = document.querySelector("iframe:not(.hidden)")
726
- if (type === "back") {
727
- // targetFrame.contentWindow.history.back()
728
- targetFrame.contentWindow.postMessage({
729
- action: "back"
730
- }, "*")
731
- } else if (type === "forward") {
732
- // targetFrame.contentWindow.history.forward()
733
- targetFrame.contentWindow.postMessage({
734
- action: "forward"
735
- }, "*")
727
+ return true;
736
728
  }
729
+ const renderCursor = () => {
730
+ document.querySelectorAll(".selectable").forEach((el) => {
731
+ el.classList.remove("cursor")
732
+ })
733
+ const target = document.querySelector(".selectable[data-index='" + cursorIndex + "']")
734
+ target.classList.add("cursor")
735
+ }
736
+ const nav = (type) => {
737
+ let targetFrame = document.querySelector("iframe:not(.hidden)")
738
+ if (type === "back") {
739
+ // targetFrame.contentWindow.history.back()
740
+ targetFrame.contentWindow.postMessage({
741
+ action: "back"
742
+ }, "*")
743
+ } else if (type === "forward") {
744
+ // targetFrame.contentWindow.history.forward()
745
+ targetFrame.contentWindow.postMessage({
746
+ action: "forward"
747
+ }, "*")
748
+ }
737
749
 
738
750
 
739
751
 
740
- // if (location.hash && location.hash.length > 0) {
741
- //// let id = getTarget(location.hash.slice(1))
742
- //// let target = document.querySelector("aside [target='" + id + "']")
743
- // let id = location.hash.slice(1)
744
- // let type = id[0]
745
- // let index = id.slice(1)
746
- // let target = document.querySelector(`aside .${type} [data-index='${index}']`)
747
- // let targetFrame = document.querySelector(`iframe[name='${target.target}']`)
748
- // console.log({ target, targetFrame })
749
- // if (type === "back") {
750
- // targetFrame.contentWindow.history.back()
751
- // } else if (type === "forward") {
752
- // targetFrame.contentWindow.history.forward()
753
- // }
754
- // /*
755
- // targetFrame.contentWindow.postMessage({
756
- // action: type
757
- // }, "*")
758
- // */
759
- // }
760
- }
761
- const renderSelection = (e, force) => {
762
- // if the menu has a default item, or if the url specifies a selection
763
- let selection = document.querySelector("[data-default]")
764
- if (selection || location.hash && location.hash.length > 0) {
765
- let target
766
- if (location.hash && location.hash.length > 0) {
767
- // document.querySelector(".bar").classList.remove("hidden")
768
- //let id = getTarget(location.hash.slice(1))
769
- let id = location.hash.slice(1)
770
-
771
-
772
- let selector
773
- if (id.startsWith("@")) {
774
- //selector = `aside [target='${id.slice(1)}']`
775
- selector = `aside [target='${id}']`
776
- } else {
777
- let type = id[0]
778
- let index = id.slice(1)
779
- console.log({ type, index })
780
- selector = `aside .${type} [data-index='${index}']`
781
- }
752
+ // if (location.hash && location.hash.length > 0) {
753
+ //// let id = getTarget(location.hash.slice(1))
754
+ //// let target = document.querySelector("aside [target='" + id + "']")
755
+ // let id = location.hash.slice(1)
756
+ // let type = id[0]
757
+ // let index = id.slice(1)
758
+ // let target = document.querySelector(`aside .${type} [data-index='${index}']`)
759
+ // let targetFrame = document.querySelector(`iframe[name='${target.target}']`)
760
+ // console.log({ target, targetFrame })
761
+ // if (type === "back") {
762
+ // targetFrame.contentWindow.history.back()
763
+ // } else if (type === "forward") {
764
+ // targetFrame.contentWindow.history.forward()
765
+ // }
766
+ // /*
767
+ // targetFrame.contentWindow.postMessage({
768
+ // action: type
769
+ // }, "*")
770
+ // */
771
+ // }
772
+ }
773
+ const renderSelection = (e, force) => {
774
+ // if the menu has a default item, or if the url specifies a selection
775
+ let selection = document.querySelector("[data-default]")
776
+ if (selection || location.hash && location.hash.length > 0) {
777
+ let target
778
+ if (location.hash && location.hash.length > 0) {
779
+ // document.querySelector(".bar").classList.remove("hidden")
780
+ //let id = getTarget(location.hash.slice(1))
781
+ let id = location.hash.slice(1)
782
+
783
+
784
+ let selector
785
+ if (id.startsWith("@")) {
786
+ //selector = `aside [target='${id.slice(1)}']`
787
+ selector = `aside [target='${id}']`
788
+ } else {
789
+ let type = id[0]
790
+ let index = id.slice(1)
791
+ console.log({ type, index })
792
+ selector = `aside .${type} [data-index='${index}']`
793
+ }
782
794
 
783
795
 
784
- // select the selected link
785
- // document.querySelectorAll(".frame-link").forEach((el) => {
786
- // el.classList.remove("selected")
787
- // })
796
+ // select the selected link
797
+ // document.querySelectorAll(".frame-link").forEach((el) => {
798
+ // el.classList.remove("selected")
799
+ // })
788
800
 
789
801
 
790
802
 
791
- // const target = document.querySelector(`[target='${id}']`)
803
+ // const target = document.querySelector(`[target='${id}']`)
792
804
 
793
805
 
794
- if (e) {
795
- // If the renderSelection is triggered by an event, look for the frame-link that's triggering the event
796
- if (e.target.classList.contains("frame-link")) {
797
- target = e.target
806
+ if (e) {
807
+ // If the renderSelection is triggered by an event, look for the frame-link that's triggering the event
808
+ if (e.target.classList.contains("frame-link")) {
809
+ target = e.target
810
+ } else {
811
+ target = e.target.closest(".frame-link")
812
+ }
798
813
  } else {
799
- target = e.target.closest(".frame-link")
814
+ // if not triggered by an event, look for the target from the location hash
815
+ target = document.querySelector(selector)
800
816
  }
801
817
  } else {
802
- // if not triggered by an event, look for the target from the location hash
803
- target = document.querySelector(selector)
804
- }
805
- } else {
806
- if (selection) {
807
- target = selection
818
+ if (selection) {
819
+ target = selection
820
+ }
808
821
  }
809
- }
810
822
 
811
823
 
812
- // if the target was found either through:
813
- // 1. looking for the frame-link that triggered the event
814
- // 2. or by looking at the location hash
815
- //
816
- // => select that tab and frame
824
+ // if the target was found either through:
825
+ // 1. looking for the frame-link that triggered the event
826
+ // 2. or by looking at the location hash
827
+ //
828
+ // => select that tab and frame
817
829
 
818
- if (target) {
830
+ if (target) {
819
831
 
820
- // display the menu button at the top
821
- // maximize container
822
- // minimize aside
832
+ // display the menu button at the top
833
+ // maximize container
834
+ // minimize aside
823
835
 
824
- document.querySelector(".container").classList.add("active")
825
- document.querySelector("aside").classList.remove("active")
826
- } else {
827
- document.querySelector(".container").classList.remove("active")
828
- document.querySelector("aside").classList.add("active")
829
- }
836
+ document.querySelector(".container").classList.add("active")
837
+ document.querySelector("aside").classList.remove("active")
838
+ } else {
839
+ document.querySelector(".container").classList.remove("active")
840
+ document.querySelector("aside").classList.add("active")
841
+ }
830
842
 
831
- if (target) {
843
+ if (target) {
832
844
 
833
845
 
834
- // Instantiate a frame with the selected target's href
835
- let url = target.href
836
- document.querySelector("#open-browser").href = url
837
- document.querySelector("#clone-tab").setAttribute("data-href", url)
838
- document.querySelector("#location").value = url
846
+ // Instantiate a frame with the selected target's href
847
+ let url = target.href
848
+ document.querySelector("#open-browser").href = url
849
+ document.querySelector("#clone-tab").setAttribute("data-href", url)
850
+ document.querySelector("#location").value = url
839
851
 
840
852
 
841
- // select the selected target element (tab)
842
- target.classList.add("selected")
853
+ // select the selected target element (tab)
854
+ target.classList.add("selected")
843
855
 
844
- // hide all frames
845
- document.querySelectorAll("iframe").forEach((el) => {
846
- el.classList.add("hidden")
847
- })
856
+ // hide all frames
857
+ document.querySelectorAll("iframe").forEach((el) => {
858
+ el.classList.add("hidden")
859
+ })
848
860
 
849
861
 
850
862
 
851
- // Look for the frame
852
- // 1. if it's hard (".h")
853
- // look for the url that matches
854
- // 2. if it's soft (".s")
855
- // find using the name attribute
856
- let targetFrame;
857
- if (target.closest(".h")) {
858
- let hardFrames = document.querySelectorAll(".browserview iframe[name^='@']")
859
- let port = new URL(target.href).port || 80
860
- for(let frame of hardFrames) {
861
- console.log({ src: frame.src, href: target.href, target: target.target })
862
- // Types of links in the tab
863
- if (String(port) === "<%=port%>") {
864
- // 1. running from <%=port%> => find a frame whose base URL matches the tab's base URL
865
- // Pinokio links
866
- let targetPath = new URL(target.href).pathname
867
- let framePath = new URL(frame.src).pathname
868
- if (targetPath === framePath) {
869
- let beforeName = frame.name
870
- frame.name = target.target
871
- console.log("SET FRAME", { before: beforeName, after: frame.name, target: target.target })
872
- targetFrame = frame
873
- break
874
- }
875
- } else {
876
- // 2. rest => find the frame whose src exactly matches the tab's url
877
- if (target.href === frame.src) {
878
- frame.name = target.target
879
- targetFrame = frame
880
- break
863
+ // Look for the frame
864
+ // 1. if it's hard (".h")
865
+ // look for the url that matches
866
+ // 2. if it's soft (".s")
867
+ // find using the name attribute
868
+ let targetFrame;
869
+ if (target.closest(".h")) {
870
+ let hardFrames = document.querySelectorAll(".browserview iframe[name^='@']")
871
+ let port = new URL(target.href).port || 80
872
+ for(let frame of hardFrames) {
873
+ console.log({ src: frame.src, href: target.href, target: target.target })
874
+ // Types of links in the tab
875
+ if (String(port) === "<%=port%>") {
876
+ // 1. running from <%=port%> => find a frame whose base URL matches the tab's base URL
877
+ // Pinokio links
878
+ let targetPath = new URL(target.href).pathname
879
+ let framePath = new URL(frame.src).pathname
880
+ if (targetPath === framePath) {
881
+ let beforeName = frame.name
882
+ frame.name = target.target
883
+ console.log("SET FRAME", { before: beforeName, after: frame.name, target: target.target })
884
+ targetFrame = frame
885
+ break
886
+ }
887
+ } else {
888
+ // 2. rest => find the frame whose src exactly matches the tab's url
889
+ if (target.href === frame.src) {
890
+ frame.name = target.target
891
+ targetFrame = frame
892
+ break
893
+ }
881
894
  }
895
+ // find the frame whose path matches
882
896
  }
883
- // find the frame whose path matches
897
+ } else if (target.closest(".s")) {
898
+ targetFrame = document.querySelector(`iframe[name='${target.target}']`)
899
+ } else if (target.closest(".n")) {
900
+ targetFrame = document.querySelector(`iframe[name='${target.target}']`)
884
901
  }
885
- } else if (target.closest(".s")) {
886
- targetFrame = document.querySelector(`iframe[name='${target.target}']`)
887
- } else if (target.closest(".n")) {
888
- targetFrame = document.querySelector(`iframe[name='${target.target}']`)
889
- }
890
902
 
891
- /*
892
- // Load the link in the frame
903
+ /*
904
+ // Load the link in the frame
893
905
 
894
- 1. if the frame was found:
895
- - if "refresh": true => refresh
896
- - otherwise,
897
- - if the target frame has been already loaded, don't do anything
898
- - frame: start.json?mode=abc, link: start.json?mode=abc => don't touch
899
- - link === frame
900
- - frame: start.json?mode=abc, link: start.json?mode=def => should load
901
- - link !== frame && !frame.includes(link)
902
- - frame: start.json?mode=abc, link: start.json => don't touch
903
- - link !== frame && frame.includes(link)
906
+ 1. if the frame was found:
907
+ - if "refresh": true => refresh
908
+ - otherwise,
909
+ - if the target frame has been already loaded, don't do anything
910
+ - frame: start.json?mode=abc, link: start.json?mode=abc => don't touch
911
+ - link === frame
912
+ - frame: start.json?mode=abc, link: start.json?mode=def => should load
913
+ - link !== frame && !frame.includes(link)
914
+ - frame: start.json?mode=abc, link: start.json => don't touch
915
+ - link !== frame && frame.includes(link)
904
916
 
905
917
 
906
918
 
907
- if the link is different
919
+ if the link is different
908
920
 
909
- - if the target frame has not been loaded, refresh
910
- 2. if the frame was NOT found => create one
921
+ - if the target frame has not been loaded, refresh
922
+ 2. if the frame was NOT found => create one
911
923
 
912
- */
924
+ */
913
925
 
914
- if (targetFrame) {
915
- targetFrame.classList.remove("hidden")
916
- let mode = target.getAttribute("data-mode")
917
- if (mode === "refresh") {
918
- targetFrame.src = target.href
919
- } else {
920
- if (e) {
921
- if (target.closest(".h")) {
922
- e.preventDefault()
923
- e.stopPropagation()
924
- let sub = subUrlOf(target.href, targetFrame.src)
925
- if (!sub) {
926
+ if (targetFrame) {
927
+ targetFrame.classList.remove("hidden")
928
+ let mode = target.getAttribute("data-mode")
929
+ if (mode === "refresh") {
930
+ targetFrame.src = target.href
931
+ } else {
932
+ if (e) {
933
+ if (target.closest(".h")) {
934
+ e.preventDefault()
935
+ e.stopPropagation()
936
+ let sub = subUrlOf(target.href, targetFrame.src)
937
+ if (!sub) {
938
+ targetFrame.src = target.href
939
+ }
940
+ //if (target.href === targetFrame.src) {
941
+ // // same url. don't do anything
942
+ // e.preventDefault()
943
+ // e.stopPropagation()
944
+ //} else {
945
+ // if (targetFrame.src.includes(target.href)) {
946
+ // // different url, but the frame's url contains the tab url => don't touch
947
+ // e.preventDefault()
948
+ // e.stopPropagation()
949
+ // } else {
950
+ // // different url, and the frame's url does not contain the tab url => change the src of the frame and load
951
+ // targetFrame.src = target.href
952
+ // e.preventDefault()
953
+ // e.stopPropagation()
954
+ // }
955
+ //}
956
+ } else if (target.closest(".s")) {
957
+ // load unconditionally => .s doesn't change
958
+ e.preventDefault()
959
+ e.stopPropagation()
960
+ } else if (target.closest(".n")) {
961
+ // load unconditionally => .n doesn't change
962
+ e.preventDefault()
963
+ e.stopPropagation()
964
+ }
965
+ } else {
966
+ if (force) {
926
967
  targetFrame.src = target.href
927
968
  }
928
- //if (target.href === targetFrame.src) {
929
- // // same url. don't do anything
930
- // e.preventDefault()
931
- // e.stopPropagation()
932
- //} else {
933
- // if (targetFrame.src.includes(target.href)) {
934
- // // different url, but the frame's url contains the tab url => don't touch
935
- // e.preventDefault()
936
- // e.stopPropagation()
937
- // } else {
938
- // // different url, and the frame's url does not contain the tab url => change the src of the frame and load
939
- // targetFrame.src = target.href
940
- // e.preventDefault()
941
- // e.stopPropagation()
942
- // }
943
- //}
944
- } else if (target.closest(".s")) {
945
- // load unconditionally => .s doesn't change
946
- e.preventDefault()
947
- e.stopPropagation()
948
- } else if (target.closest(".n")) {
949
- // load unconditionally => .n doesn't change
950
- e.preventDefault()
951
- e.stopPropagation()
952
- }
953
- } else {
954
- if (force) {
955
- targetFrame.src = target.href
956
969
  }
970
+ targetFrame.contentWindow.postMessage({
971
+ action: "foreground"
972
+ }, "*")
957
973
  }
958
- targetFrame.contentWindow.postMessage({
959
- action: "foreground"
960
- }, "*")
974
+ } else {
975
+ let frame = document.createElement("iframe")
976
+ frame.name = target.target
977
+ frame.src = target.href
978
+ frame.setAttribute(
979
+ "allow",
980
+ "clipboard-read *; clipboard-write *; accelerometer *; ambient-light-sensor *; autoplay *; battery *; camera *; display-capture *; gamepad *; geolocation *; gyroscope *; hid *; identity-credentials-get *; microphone *; midi *; otp-credentials *; serial *;"
981
+ )
982
+ document.querySelector("main").appendChild(frame)
983
+ loaded[target.target] = true
961
984
  }
985
+
986
+ // if (targetFrame) {
987
+ // targetFrame.classList.remove("hidden")
988
+ //
989
+ // // if the iframe already exists, do not
990
+ // if (loaded[target.target]){
991
+ //
992
+ // // Force refresh option
993
+ // //
994
+ // // menu := [{
995
+ // // text,
996
+ // // icon,
997
+ // // mode: "refresh" => refresh regardless of any condition
998
+ // // }]
999
+ // let mode = target.getAttribute("data-mode")
1000
+ // if (mode === "refresh") {
1001
+ // targetFrame.src = target.href
1002
+ // } else {
1003
+ // console.log("# 4")
1004
+ // if (e) {
1005
+ // // if triggered by a click event,
1006
+ // // 1. if it's a hard link (".h")
1007
+ // // - ignore if the pathname is the same
1008
+ // // - reload if
1009
+ // console.log("# 5", { src: targetFrame.src, href: target.href, target: target.target })
1010
+ // // triggered with a click
1011
+ // // do not reload iframe if the href and the src is the same
1012
+ // if (target.closest(".h")) {
1013
+ // // if (targetFrame.src.includes(target.target)) {
1014
+ // if (targetFrame.src.includes(target.href)) {
1015
+ // // if (targetFrame.src === target.href) {
1016
+ // e.preventDefault()
1017
+ // e.stopPropagation()
1018
+ // }
1019
+ // } else if (target.closest(".s")) {
1020
+ // e.preventDefault()
1021
+ // e.stopPropagation()
1022
+ // }
1023
+ // } else {
1024
+ // // if not triggered by event
1025
+ // // refresh ONLY if programmatically forced refresh
1026
+ // console.log("# 6")
1027
+ // if (force) {
1028
+ // console.log("# 7")
1029
+ // targetFrame.src = target.href
1030
+ // }
1031
+ // }
1032
+ // }
1033
+ //
1034
+ // } else {
1035
+ // console.log("# 8")
1036
+ // //targetFrame.contentWindow.addEventListener("load", () => {
1037
+ // if (e) {
1038
+ // console.log("# 9")
1039
+ // // coming from a click => don't need to set the src
1040
+ // } else {
1041
+ // console.log("# 10")
1042
+ // // load without click
1043
+ // if (targetFrame.src !== target.href) {
1044
+ // console.log("# 11")
1045
+ // targetFrame.src = target.href
1046
+ // }
1047
+ // }
1048
+ // loaded[target.target] = true
1049
+ // //});
1050
+ // }
1051
+ // } else {
1052
+ // console.log("# 12")
1053
+ // let frame = document.createElement("iframe")
1054
+ // frame.name = target.target
1055
+ // frame.src = target.href
1056
+ // frame.setAttribute(
1057
+ // "allow",
1058
+ // "clipboard-read *; clipboard-write *; accelerometer *; ambient-light-sensor *; autoplay *; battery *; camera *; display-capture *; gamepad *; geolocation *; gyroscope *; hid *; identity-credentials-get *; microphone *; midi *; otp-credentials *; serial *;"
1059
+ // )
1060
+ // document.querySelector("main").appendChild(frame)
1061
+ // loaded[target.target] = true
1062
+ // }
962
1063
  } else {
963
- let frame = document.createElement("iframe")
964
- frame.name = target.target
965
- frame.src = target.href
966
- frame.setAttribute(
967
- "allow",
968
- "clipboard-read *; clipboard-write *; accelerometer *; ambient-light-sensor *; autoplay *; battery *; camera *; display-capture *; gamepad *; geolocation *; gyroscope *; hid *; identity-credentials-get *; microphone *; midi *; otp-credentials *; serial *;"
969
- )
970
- document.querySelector("main").appendChild(frame)
971
- loaded[target.target] = true
1064
+ console.log("# 13")
1065
+ // couldn't find item,
1066
+ // clear the hash
1067
+ //
1068
+ location.hash = ""
972
1069
  }
973
-
974
- // if (targetFrame) {
975
- // targetFrame.classList.remove("hidden")
976
- //
977
- // // if the iframe already exists, do not
978
- // if (loaded[target.target]){
979
- //
980
- // // Force refresh option
981
- // //
982
- // // menu := [{
983
- // // text,
984
- // // icon,
985
- // // mode: "refresh" => refresh regardless of any condition
986
- // // }]
987
- // let mode = target.getAttribute("data-mode")
988
- // if (mode === "refresh") {
989
- // targetFrame.src = target.href
990
- // } else {
991
- // console.log("# 4")
992
- // if (e) {
993
- // // if triggered by a click event,
994
- // // 1. if it's a hard link (".h")
995
- // // - ignore if the pathname is the same
996
- // // - reload if
997
- // console.log("# 5", { src: targetFrame.src, href: target.href, target: target.target })
998
- // // triggered with a click
999
- // // do not reload iframe if the href and the src is the same
1000
- // if (target.closest(".h")) {
1001
- // // if (targetFrame.src.includes(target.target)) {
1002
- // if (targetFrame.src.includes(target.href)) {
1003
- // // if (targetFrame.src === target.href) {
1004
- // e.preventDefault()
1005
- // e.stopPropagation()
1006
- // }
1007
- // } else if (target.closest(".s")) {
1008
- // e.preventDefault()
1009
- // e.stopPropagation()
1010
- // }
1011
- // } else {
1012
- // // if not triggered by event
1013
- // // refresh ONLY if programmatically forced refresh
1014
- // console.log("# 6")
1015
- // if (force) {
1016
- // console.log("# 7")
1017
- // targetFrame.src = target.href
1018
- // }
1019
- // }
1020
- // }
1021
- //
1022
- // } else {
1023
- // console.log("# 8")
1024
- // //targetFrame.contentWindow.addEventListener("load", () => {
1025
- // if (e) {
1026
- // console.log("# 9")
1027
- // // coming from a click => don't need to set the src
1028
- // } else {
1029
- // console.log("# 10")
1030
- // // load without click
1031
- // if (targetFrame.src !== target.href) {
1032
- // console.log("# 11")
1033
- // targetFrame.src = target.href
1034
- // }
1035
- // }
1036
- // loaded[target.target] = true
1037
- // //});
1038
- // }
1039
- // } else {
1040
- // console.log("# 12")
1041
- // let frame = document.createElement("iframe")
1042
- // frame.name = target.target
1043
- // frame.src = target.href
1044
- // frame.setAttribute(
1045
- // "allow",
1046
- // "clipboard-read *; clipboard-write *; accelerometer *; ambient-light-sensor *; autoplay *; battery *; camera *; display-capture *; gamepad *; geolocation *; gyroscope *; hid *; identity-credentials-get *; microphone *; midi *; otp-credentials *; serial *;"
1047
- // )
1048
- // document.querySelector("main").appendChild(frame)
1049
- // loaded[target.target] = true
1050
- // }
1051
1070
  } else {
1052
- console.log("# 13")
1053
- // couldn't find item,
1054
- // clear the hash
1055
- //
1056
- location.hash = ""
1057
- }
1058
- } else {
1059
- console.log("# 14")
1060
- document.querySelector(".container").classList.remove("active")
1061
- document.querySelector("aside").classList.add("active")
1071
+ console.log("# 14")
1072
+ document.querySelector(".container").classList.remove("active")
1073
+ document.querySelector("aside").classList.add("active")
1062
1074
 
1075
+ }
1063
1076
  }
1064
- }
1065
- console.log("loaded before", loaded)
1066
- <% if (type === "run" && env.PINOKIO_SCRIPT_DEFAULT && env.PINOKIO_SCRIPT_DEFAULT.toString().toLowerCase() === "true") { %>
1067
- renderSelection()
1068
- <% } %>
1069
- //renderCursor()
1070
- console.log("loaded after", loaded)
1071
- //Reporter()
1072
- document.querySelector("#reload").addEventListener("click", (e) => {
1073
- /*
1074
- // get selected
1075
- let target = document.querySelector(".selected").target
1076
- location.hash = target
1077
- // force refresh
1078
- renderSelection(null, true)
1079
- */
1080
- let frame = document.querySelector("iframe:not(.hidden)")
1081
- frame.src = frame.src
1082
- // frame.contentWindow.location.reload();
1083
- })
1084
- <% if (agent === "electron") { %>
1085
- document.querySelector("#back").addEventListener("click", (e) => {
1086
- nav("back")
1087
- })
1088
- document.querySelector("#forward").addEventListener("click", (e) => {
1089
- nav("forward")
1077
+ console.log("loaded before", loaded)
1078
+ <% if (type === "run" && env.PINOKIO_SCRIPT_DEFAULT && env.PINOKIO_SCRIPT_DEFAULT.toString().toLowerCase() === "true") { %>
1079
+ renderSelection()
1080
+ <% } %>
1081
+ //renderCursor()
1082
+ console.log("loaded after", loaded)
1083
+ //Reporter()
1084
+ document.querySelector("#reload").addEventListener("click", (e) => {
1085
+ /*
1086
+ // get selected
1087
+ let target = document.querySelector(".selected").target
1088
+ location.hash = target
1089
+ // force refresh
1090
+ renderSelection(null, true)
1091
+ */
1092
+ let frame = document.querySelector("iframe:not(.hidden)")
1093
+ frame.src = frame.src
1094
+ // frame.contentWindow.location.reload();
1090
1095
  })
1091
- <% } %>
1096
+ <% if (agent === "electron") { %>
1097
+ document.querySelector("#back").addEventListener("click", (e) => {
1098
+ nav("back")
1099
+ })
1100
+ document.querySelector("#forward").addEventListener("click", (e) => {
1101
+ nav("forward")
1102
+ })
1103
+ <% } %>
1092
1104
 
1093
- document.querySelector("#new-tab").addEventListener("click", async (e) => {
1094
- const u = prompt("url")
1105
+ document.querySelector("#new-tab").addEventListener("click", async (e) => {
1106
+ const u = prompt("url")
1095
1107
 
1096
- if (u) {
1097
- let url
1098
- if (/^[ ]*http:/i.test(u)) {
1099
- url = u
1100
- } else if (/^[ ]*https:/i.test(u)) {
1101
- url = u
1102
- } else {
1103
- let o = {}
1104
- if (/^[0-9.:]/.test(u)) {
1105
- o.forceHttp = true
1106
- } else if (/^localhost/.test(u)) {
1107
- o.forceHttp = true
1108
+ if (u) {
1109
+ let url
1110
+ if (/^[ ]*http:/i.test(u)) {
1111
+ url = u
1112
+ } else if (/^[ ]*https:/i.test(u)) {
1113
+ url = u
1108
1114
  } else {
1109
- o.forceHttps = true
1115
+ let o = {}
1116
+ if (/^[0-9.:]/.test(u)) {
1117
+ o.forceHttp = true
1118
+ } else if (/^localhost/.test(u)) {
1119
+ o.forceHttp = true
1120
+ } else {
1121
+ o.forceHttps = true
1122
+ }
1123
+ url = normalizeURL(u, o)
1110
1124
  }
1111
- url = normalizeURL(u, o)
1112
- }
1113
1125
 
1126
+ if (url && url.trim().length > 0) {
1127
+ console.log("url", url)
1128
+ const { tab, frame } = await addTab(url)
1129
+ tab.click()
1130
+ }
1131
+ }
1132
+ })
1133
+ document.querySelector("#clone-tab").addEventListener("click", async (e) => {
1134
+ const url = document.querySelector("#clone-tab").getAttribute("data-href")
1114
1135
  if (url && url.trim().length > 0) {
1115
1136
  console.log("url", url)
1116
1137
  const { tab, frame } = await addTab(url)
1117
1138
  tab.click()
1118
1139
  }
1119
- }
1120
- })
1121
- document.querySelector("#clone-tab").addEventListener("click", async (e) => {
1122
- const url = document.querySelector("#clone-tab").getAttribute("data-href")
1123
- if (url && url.trim().length > 0) {
1124
- console.log("url", url)
1125
- const { tab, frame } = await addTab(url)
1126
- tab.click()
1127
- }
1128
- })
1129
-
1130
- const syncTabs = async () => {
1131
- let tabs = []
1132
- document.querySelectorAll(".temp-menu .frame-link").forEach((el) => {
1133
- tabs.push(el.href)
1134
1140
  })
1135
1141
 
1136
-
1137
- // persist
1138
- console.log("sync tabs", tabs)
1139
-
1140
- await fetch("/pinokio/tabs", {
1141
- method: "POST",
1142
- headers: {
1143
- "Content-Type": "application/json"
1144
- },
1145
- body: JSON.stringify({
1146
- name: "<%=name%>",
1147
- tabs
1142
+ const syncTabs = async () => {
1143
+ let tabs = []
1144
+ document.querySelectorAll(".temp-menu .frame-link").forEach((el) => {
1145
+ tabs.push(el.href)
1148
1146
  })
1149
- })
1150
- }
1151
- const addTab = async (url) => {
1152
- let item = document.createElement("a")
1153
- //let id = "ts" + Date.now()
1154
- let index = document.querySelectorAll("aside .s .frame-link").length
1155
1147
 
1156
- let id = "s" + index
1157
- // let id = url
1158
- item.target = id
1159
- item.href = url
1160
- item.setAttribute("data-index", index)
1161
- item.className = "btn header-item frame-link"
1162
- item.innerHTML = `<div class='tab'><i class="fa-solid fa-link"></i><div class='display'>${url}</div><div class='flexible'></div><button class='btn2 del'><i class="fa-solid fa-xmark"></i></button></div>`
1163
1148
 
1164
- document.querySelector(".temp-menu").appendChild(item)
1149
+ // persist
1150
+ console.log("sync tabs", tabs)
1165
1151
 
1166
- let frame = document.createElement("iframe")
1167
- frame.name = id
1168
- frame.src = item.href
1169
- frame.setAttribute(
1170
- "allow",
1171
- "clipboard-read *; clipboard-write *; accelerometer *; ambient-light-sensor *; autoplay *; battery *; camera *; display-capture *; gamepad *; geolocation *; gyroscope *; hid *; identity-credentials-get *; microphone *; midi *; otp-credentials *; serial *;"
1172
- )
1173
- document.querySelector("main").appendChild(frame)
1174
-
1175
- await syncTabs()
1152
+ await fetch("/pinokio/tabs", {
1153
+ method: "POST",
1154
+ headers: {
1155
+ "Content-Type": "application/json"
1156
+ },
1157
+ body: JSON.stringify({
1158
+ name: "<%=name%>",
1159
+ tabs
1160
+ })
1161
+ })
1162
+ }
1163
+ const addTab = async (url) => {
1164
+ let item = document.createElement("a")
1165
+ //let id = "ts" + Date.now()
1166
+ let index = document.querySelectorAll("aside .s .frame-link").length
1167
+
1168
+ let id = "s" + index
1169
+ // let id = url
1170
+ item.target = id
1171
+ item.href = url
1172
+ item.setAttribute("data-index", index)
1173
+ item.className = "btn header-item frame-link"
1174
+ item.innerHTML = `<div class='tab'><i class="fa-solid fa-link"></i><div class='display'>${url}</div><div class='flexible'></div><button class='btn2 del'><i class="fa-solid fa-xmark"></i></button></div>`
1175
+
1176
+ document.querySelector(".temp-menu").appendChild(item)
1177
+
1178
+ let frame = document.createElement("iframe")
1179
+ frame.name = id
1180
+ frame.src = item.href
1181
+ frame.setAttribute(
1182
+ "allow",
1183
+ "clipboard-read *; clipboard-write *; accelerometer *; ambient-light-sensor *; autoplay *; battery *; camera *; display-capture *; gamepad *; geolocation *; gyroscope *; hid *; identity-credentials-get *; microphone *; midi *; otp-credentials *; serial *;"
1184
+ )
1185
+ document.querySelector("main").appendChild(frame)
1176
1186
 
1187
+ await syncTabs()
1177
1188
 
1178
- return {
1179
- tab: item,
1180
- frame
1181
- }
1182
1189
 
1183
- }
1190
+ return {
1191
+ tab: item,
1192
+ frame
1193
+ }
1184
1194
 
1195
+ }
1185
1196
 
1186
1197
 
1187
1198
 
1188
- if (document.querySelector("#menu-mobile")) {
1189
- document.querySelector("#menu-mobile").addEventListener("click", async (e) => {
1190
- location.hash = ""
1191
- refresh(false, { nodelay: true })
1192
- })
1193
- }
1194
- if (document.querySelector("#menu")) {
1195
- document.querySelector("#menu").addEventListener("click", async (e) => {
1196
- document.querySelector("aside").classList.toggle("hidden")
1197
- document.querySelector("#menu").classList.toggle("margin")
1198
- })
1199
- }
1200
- document.querySelector(".app-info").addEventListener("click", async (e) => {
1201
- e.preventDefault()
1202
- e.stopPropagation()
1203
- location.hash = ""
1204
- renderSelection()
1205
1199
 
1206
- })
1207
- document.querySelector("#delete").addEventListener("click", async (e) => {
1208
- e.preventDefault()
1209
- e.stopPropagation()
1210
- const confirmed = confirm("Are you sure you wish to delete the app?")
1211
- if (confirmed) {
1212
- let name = document.querySelector("#delete").getAttribute("data-name")
1213
- console.log("delete", name)
1214
- Swal.fire({
1215
- html: '<i class="fa-solid fa-circle-notch fa-spin"></i> Deleting',
1216
- customClass: {
1217
- container: "loader-container",
1218
- popup: "loader-popup",
1219
- htmlContainer: "loader-dialog",
1220
- footer: "hidden",
1221
- actions: "hidden"
1222
- }
1223
- });
1224
- let res = await fetch("/pinokio/delete", {
1225
- method: "post",
1226
- headers: {
1227
- "Content-Type": "application/json"
1228
- },
1229
- body: JSON.stringify({ name })
1230
- }).then((res) => {
1231
- return res.json()
1200
+ if (document.querySelector("#menu-mobile")) {
1201
+ document.querySelector("#menu-mobile").addEventListener("click", async (e) => {
1202
+ location.hash = ""
1203
+ refresh(false, { nodelay: true })
1232
1204
  })
1233
- console.log("res", res)
1234
- Swal.close()
1235
- if (res) {
1236
- if (res.success) {
1237
- location.href = "/"
1238
- } else if (res.error) {
1239
- alert(res.error)
1240
- }
1241
- }
1242
- } else {
1243
1205
  }
1244
- })
1245
- document.querySelector("aside").addEventListener("click", async (e) => {
1246
- let target
1247
-
1248
-
1249
- // 1. handle delete
1250
- if (e.target.classList.contains("del")) {
1251
- target = e.target
1252
- } else {
1253
- target = e.target.closest(".del")
1206
+ if (document.querySelector("#menu")) {
1207
+ document.querySelector("#menu").addEventListener("click", async (e) => {
1208
+ document.querySelector("aside").classList.toggle("hidden")
1209
+ document.querySelector("#menu").classList.toggle("margin")
1210
+ })
1254
1211
  }
1212
+ document.querySelector(".app-info").addEventListener("click", async (e) => {
1213
+ e.preventDefault()
1214
+ e.stopPropagation()
1215
+ location.hash = ""
1216
+ renderSelection()
1255
1217
 
1256
- if (target) {
1218
+ })
1219
+ document.querySelector("#delete").addEventListener("click", async (e) => {
1257
1220
  e.preventDefault()
1258
1221
  e.stopPropagation()
1259
- // Delete
1260
- // delete link
1261
- let el = target.closest(".frame-link")
1262
- console.log("target", el.target)
1263
- let iframe = document.querySelector("iframe[name='" + el.target + "']")
1264
- console.log("iframe", iframe)
1265
- if (iframe) {
1266
- // delete iframe
1267
- iframe.remove()
1222
+ const confirmed = confirm("Are you sure you wish to delete the app?")
1223
+ if (confirmed) {
1224
+ let name = document.querySelector("#delete").getAttribute("data-name")
1225
+ console.log("delete", name)
1226
+ Swal.fire({
1227
+ html: '<i class="fa-solid fa-circle-notch fa-spin"></i> Deleting',
1228
+ customClass: {
1229
+ container: "loader-container",
1230
+ popup: "loader-popup",
1231
+ htmlContainer: "loader-dialog",
1232
+ footer: "hidden",
1233
+ actions: "hidden"
1234
+ }
1235
+ });
1236
+ let res = await fetch("/pinokio/delete", {
1237
+ method: "post",
1238
+ headers: {
1239
+ "Content-Type": "application/json"
1240
+ },
1241
+ body: JSON.stringify({ name })
1242
+ }).then((res) => {
1243
+ return res.json()
1244
+ })
1245
+ console.log("res", res)
1246
+ Swal.close()
1247
+ if (res) {
1248
+ if (res.success) {
1249
+ location.href = "/"
1250
+ } else if (res.error) {
1251
+ alert(res.error)
1252
+ }
1253
+ }
1254
+ } else {
1268
1255
  }
1269
- el.remove()
1270
- // update tabs
1271
- await syncTabs()
1272
- return
1273
- }
1256
+ })
1257
+ document.querySelector("aside").addEventListener("click", async (e) => {
1258
+ let target
1274
1259
 
1275
1260
 
1276
- // 2. handle shudown
1277
- if (e.target.classList.contains("shutdown")) {
1278
- target = e.target
1279
- } else {
1280
- target = e.target.closest(".shutdown")
1281
- }
1282
- if (target) {
1283
- e.preventDefault()
1284
- e.stopPropagation()
1285
- let link = target.closest("[href]")
1286
- let src = new URL(link.href).pathname
1287
- target.querySelector("i.fa-square").className = "fa-solid fa-check"
1288
- n.Noty({
1289
- text: `stopping ${src}`,
1290
- silent: true,
1291
- timeout: 2000
1292
- })
1293
- console.log("src", src)
1261
+ // 1. handle delete
1262
+ if (e.target.classList.contains("del")) {
1263
+ target = e.target
1264
+ } else {
1265
+ target = e.target.closest(".del")
1266
+ }
1294
1267
 
1295
- let socket = new Socket()
1296
- socket.run({
1297
- method: "kernel.api.stop",
1298
- params: {
1299
- uri: "~" + src
1300
- }
1301
- }, (packet) => {
1302
- if (packet.type === "result") {
1303
- socket.close()
1304
- n.Noty({
1305
- timeout: 2000,
1306
- text: `stopped`,
1307
- silent: true
1308
- })
1309
- console.log("Refresh 4")
1310
- refresh(true)
1268
+ if (target) {
1269
+ e.preventDefault()
1270
+ e.stopPropagation()
1271
+ // Delete
1272
+ // delete link
1273
+ let el = target.closest(".frame-link")
1274
+ console.log("target", el.target)
1275
+ let iframe = document.querySelector("iframe[name='" + el.target + "']")
1276
+ console.log("iframe", iframe)
1277
+ if (iframe) {
1278
+ // delete iframe
1279
+ iframe.remove()
1311
1280
  }
1312
- })
1313
-
1314
- return
1315
- }
1281
+ el.remove()
1282
+ // update tabs
1283
+ await syncTabs()
1284
+ return
1285
+ }
1316
1286
 
1317
1287
 
1288
+ // 2. handle shudown
1289
+ if (e.target.classList.contains("shutdown")) {
1290
+ target = e.target
1291
+ } else {
1292
+ target = e.target.closest(".shutdown")
1293
+ }
1294
+ if (target) {
1295
+ e.preventDefault()
1296
+ e.stopPropagation()
1297
+ let link = target.closest("[href]")
1298
+ let src = new URL(link.href).pathname
1299
+ target.querySelector("i.fa-square").className = "fa-solid fa-check"
1300
+ n.Noty({
1301
+ text: `stopping ${src}`,
1302
+ silent: true,
1303
+ timeout: 2000
1304
+ })
1305
+ console.log("src", src)
1318
1306
 
1319
- // 3. handle select
1320
- if (e.target.classList.contains("frame-link")) {
1321
- target = e.target
1322
- } else {
1323
- target = e.target.closest(".frame-link")
1324
- }
1307
+ let socket = new Socket()
1308
+ socket.run({
1309
+ method: "kernel.api.stop",
1310
+ params: {
1311
+ uri: "~" + src
1312
+ }
1313
+ }, (packet) => {
1314
+ if (packet.type === "result") {
1315
+ socket.close()
1316
+ n.Noty({
1317
+ timeout: 2000,
1318
+ text: `stopped`,
1319
+ silent: true
1320
+ })
1321
+ console.log("Refresh 4")
1322
+ refresh(true)
1323
+ }
1324
+ })
1325
1325
 
1326
+ return
1327
+ }
1326
1328
 
1327
1329
 
1328
- if (target) {
1329
1330
 
1330
- // if data-confirm exists, ask for confirmation
1331
- // if not, then just go forward
1332
- let confirmText = target.getAttribute("data-confirm")
1333
- if (confirmText && confirmText.length > 0) {
1334
- const confirmed = confirm(confirmText)
1335
- if (!confirmed) {
1336
- e.preventDefault()
1337
- e.stopPropagation()
1338
- return
1339
- }
1331
+ // 3. handle select
1332
+ if (e.target.classList.contains("frame-link")) {
1333
+ target = e.target
1334
+ } else {
1335
+ target = e.target.closest(".frame-link")
1340
1336
  }
1341
1337
 
1342
- if (target.getAttribute("data-action")) {
1343
- let actionStr = target.getAttribute("data-action")
1344
- let action = JSON.parse(actionStr)
1345
- console.log("action", action)
1346
- if (action.method === "stop" && action.uri) {
1347
- let socket = new Socket()
1348
- socket.run({
1349
- method: "kernel.api.stop",
1350
- params: {
1351
- uri: action.uri//"~" + location.pathname
1352
- }
1353
- }, (packet) => {
1354
- if (packet.type === "result") {
1355
- socket.close()
1356
- // location.href = location.href
1357
- }
1358
- })
1338
+
1339
+
1340
+ if (target) {
1341
+
1342
+ // if data-confirm exists, ask for confirmation
1343
+ // if not, then just go forward
1344
+ let confirmText = target.getAttribute("data-confirm")
1345
+ if (confirmText && confirmText.length > 0) {
1346
+ const confirmed = confirm(confirmText)
1347
+ if (!confirmed) {
1348
+ e.preventDefault()
1349
+ e.stopPropagation()
1350
+ return
1351
+ }
1359
1352
  }
1360
- } else if (target.getAttribute("data-filepath")) {
1361
- return
1362
- } else if (target.target === "_blank") {
1363
- // nothing
1364
- } else {
1365
- if (target.classList.contains("reveal")) {
1366
- // nested menu
1367
- target.closest(".nested-menu").querySelector(".submenu").classList.toggle("hidden")
1368
- e.preventDefault()
1369
- e.stopPropagation()
1353
+
1354
+ if (target.getAttribute("data-action")) {
1355
+ let actionStr = target.getAttribute("data-action")
1356
+ let action = JSON.parse(actionStr)
1357
+ console.log("action", action)
1358
+ if (action.method === "stop" && action.uri) {
1359
+ let socket = new Socket()
1360
+ socket.run({
1361
+ method: "kernel.api.stop",
1362
+ params: {
1363
+ uri: action.uri//"~" + location.pathname
1364
+ }
1365
+ }, (packet) => {
1366
+ if (packet.type === "result") {
1367
+ socket.close()
1368
+ // location.href = location.href
1369
+ }
1370
+ })
1371
+ }
1372
+ } else if (target.getAttribute("data-filepath")) {
1373
+ return
1374
+ } else if (target.target === "_blank") {
1375
+ // nothing
1370
1376
  } else {
1371
- //location.hash = target.target
1377
+ if (target.classList.contains("reveal")) {
1378
+ // nested menu
1379
+ target.closest(".nested-menu").querySelector(".submenu").classList.toggle("hidden")
1380
+ e.preventDefault()
1381
+ e.stopPropagation()
1382
+ } else {
1383
+ //location.hash = target.target
1372
1384
 
1373
1385
 
1374
- // let id = getTarget(target.getAttribute("href"))
1375
- // console.log("ID", id, target.href)
1376
- // location.hash = id
1386
+ // let id = getTarget(target.getAttribute("href"))
1387
+ // console.log("ID", id, target.href)
1388
+ // location.hash = id
1377
1389
 
1378
- //location.hash = target.getAttribute("href")
1390
+ //location.hash = target.getAttribute("href")
1379
1391
 
1380
- if (target.closest(".h")) {
1381
- location.hash = target.target
1382
- } else {
1383
- let index = target.getAttribute("data-index")
1384
- let type = target.closest(".m").getAttribute("data-type")
1392
+ if (target.closest(".h")) {
1393
+ location.hash = target.target
1394
+ } else {
1395
+ let index = target.getAttribute("data-index")
1396
+ let type = target.closest(".m").getAttribute("data-type")
1385
1397
 
1386
1398
 
1387
- location.hash = type + index
1388
- }
1399
+ location.hash = type + index
1400
+ }
1389
1401
 
1390
- document.querySelectorAll(".frame-link").forEach((el) => {
1391
- el.classList.remove("selected")
1392
- })
1393
- target.classList.add("selected")
1402
+ document.querySelectorAll(".frame-link").forEach((el) => {
1403
+ el.classList.remove("selected")
1404
+ })
1405
+ target.classList.add("selected")
1394
1406
 
1395
- renderSelection(e)
1407
+ renderSelection(e)
1408
+ }
1396
1409
  }
1397
1410
  }
1398
- }
1399
1411
 
1400
1412
 
1401
1413
 
1402
- })
1403
- const refresh_du = () => {
1404
- console.log("REFRESH DU")
1405
- fetch("/du/<%=name%>").then((res) => {
1406
- return res.json()
1407
- }).then((res) => {
1408
- let val
1409
- //let k = 1024
1410
- let k = 1000
1411
- if (res.du > k * k * k) {
1412
- // GB
1413
- val = `${Math.floor(res.du/k/k/k * 100) / 100} GB`
1414
- } else if (res.du > k * k) {
1415
- // MB
1416
- val = `${Math.floor(res.du/k/k * 100) / 100} MB`
1417
- } else {
1418
- // KB
1419
- val = `${Math.floor(res.du/k * 100) / 100} KB`
1420
- }
1421
- console.log("DU VAL", val)
1422
- //document.querySelector(".disk-usage").innerHTML = `<i class="fa-regular fa-hard-drive"></i> ${val}`
1423
- document.querySelector(".disk-usage").innerHTML = val
1424
1414
  })
1425
- }
1426
- const refresh = async (silent, options) => {
1427
- if (options && options.nodelay) {
1428
- } else {
1429
- await new Promise((resolve, reject) => {
1430
- setTimeout(() => {
1431
- resolve()
1432
- }, 1000)
1415
+ const refresh_du = () => {
1416
+ console.log("REFRESH DU")
1417
+ fetch("/du/<%=name%>").then((res) => {
1418
+ return res.json()
1419
+ }).then((res) => {
1420
+ let val
1421
+ //let k = 1024
1422
+ let k = 1000
1423
+ if (res.du > k * k * k) {
1424
+ // GB
1425
+ val = `${Math.floor(res.du/k/k/k * 100) / 100} GB`
1426
+ } else if (res.du > k * k) {
1427
+ // MB
1428
+ val = `${Math.floor(res.du/k/k * 100) / 100} MB`
1429
+ } else {
1430
+ // KB
1431
+ val = `${Math.floor(res.du/k * 100) / 100} KB`
1432
+ }
1433
+ console.log("DU VAL", val)
1434
+ //document.querySelector(".disk-usage").innerHTML = `<i class="fa-regular fa-hard-drive"></i> ${val}`
1435
+ document.querySelector(".disk-usage").innerHTML = val
1433
1436
  })
1434
1437
  }
1435
- const html = await fetch("<%=sidebar%>").then((res) => {
1436
- return res.text()
1437
- })
1438
- document.querySelector(".menu").innerHTML = html
1439
- location.hash = ""
1440
-
1441
- // render the selected frame only if not silent
1442
- if (silent) {
1443
- } else {
1438
+ const refresh = async (silent, options) => {
1444
1439
  if (options && options.nodelay) {
1445
1440
  } else {
1446
- // await new Promise((resolve, reject) => {
1447
- // setTimeout(() => {
1448
- // resolve()
1449
- // }, 500)
1450
- // })
1441
+ await new Promise((resolve, reject) => {
1442
+ setTimeout(() => {
1443
+ resolve()
1444
+ }, 1000)
1445
+ })
1446
+ }
1447
+ const html = await fetch("<%=sidebar%>").then((res) => {
1448
+ return res.text()
1449
+ })
1450
+ document.querySelector(".menu").innerHTML = html
1451
+ location.hash = ""
1452
+
1453
+ // render the selected frame only if not silent
1454
+ if (silent) {
1455
+ } else {
1456
+ if (options && options.nodelay) {
1457
+ } else {
1458
+ // await new Promise((resolve, reject) => {
1459
+ // setTimeout(() => {
1460
+ // resolve()
1461
+ // }, 500)
1462
+ // })
1463
+ }
1464
+ renderSelection()
1451
1465
  }
1452
- renderSelection()
1453
1466
  }
1454
- }
1455
- if (document.querySelector("#genlog")) {
1456
- document.querySelector("#genlog").addEventListener("click", (e) => {
1457
- e.preventDefault()
1458
- e.stopPropagation()
1459
- e.target.innerHTML = '<i class="fa-solid fa-circle-notch fa-spin"></i>'
1460
- fetch("/pinokio/log", {
1461
- method: "post",
1462
- }).then((res) => {
1463
- let btn = document.querySelector("#genlog")
1464
- let btn2 = document.querySelector("#downloadlogs")
1465
- btn2.classList.remove("hidden")
1466
- btn.classList.add("hidden")
1467
- btn.innerHTML = '<i class="fa-solid fa-circle-check"></i> Generated!'
1468
- //btn.classList.add("hidden")
1467
+ if (document.querySelector("#genlog")) {
1468
+ document.querySelector("#genlog").addEventListener("click", (e) => {
1469
+ e.preventDefault()
1470
+ e.stopPropagation()
1471
+ e.target.innerHTML = '<i class="fa-solid fa-circle-notch fa-spin"></i>'
1472
+ fetch("/pinokio/log", {
1473
+ method: "post",
1474
+ }).then((res) => {
1475
+ let btn = document.querySelector("#genlog")
1476
+ let btn2 = document.querySelector("#downloadlogs")
1477
+ btn2.classList.remove("hidden")
1478
+ btn.classList.add("hidden")
1479
+ btn.innerHTML = '<i class="fa-solid fa-circle-check"></i> Generated!'
1480
+ //btn.classList.add("hidden")
1481
+ })
1469
1482
  })
1470
- })
1471
- }
1472
- window.addEventListener('message', (event) => {
1473
-
1474
- // only process the event it's coming from pinokio
1475
- let origin = event.origin
1476
- if (origin) {
1477
- let port = new URL(origin).port || 80
1478
- console.log("port", port)
1479
- if (String(port) === "<%=port%>") {
1480
- console.log("Message received from the child: ", event); // Message received from child
1481
- if (event.data) {
1482
- if (event.data.action) {
1483
- if (event.data.action.type === "newtab") {
1484
- console.log("create tab", event.data.action.url)
1485
- addTab(event.data.action.url)
1486
- } else if (event.data.action.type === "title") {
1487
- console.log("title", event.data)
1488
- } else if (event.data.action.type === "location") {
1489
- let url = event.data.action.url
1490
- console.log({ action: event.data.action })
1491
- document.querySelector("#open-browser").href = url
1492
- //document.querySelector("#location").innerHTML = url
1493
- document.querySelector("#location").value = url
1494
- }
1495
- } else if (event.data.type) {
1496
- let asideHidden = (window.getComputedStyle(document.querySelector("aside")).display === "none")
1497
- console.log("asideHidden", asideHidden)
1498
- if (!asideHidden) {
1499
- // refresh only if aside
1500
- if (event.data.type === 'disconnect') {
1501
- console.log("Refresh 1")
1502
- refresh()
1503
- } else {
1504
- console.log("Refresh 2")
1505
- refresh()
1483
+ }
1484
+ window.addEventListener('message', (event) => {
1485
+
1486
+ // only process the event it's coming from pinokio
1487
+ let origin = event.origin
1488
+ if (origin) {
1489
+ let port = new URL(origin).port || 80
1490
+ console.log("port", port)
1491
+ if (String(port) === "<%=port%>") {
1492
+ console.log("Message received from the child: ", event); // Message received from child
1493
+ if (event.data) {
1494
+ if (event.data.action) {
1495
+ if (event.data.action.type === "newtab") {
1496
+ console.log("create tab", event.data.action.url)
1497
+ addTab(event.data.action.url)
1498
+ } else if (event.data.action.type === "title") {
1499
+ console.log("title", event.data)
1500
+ } else if (event.data.action.type === "location") {
1501
+ let url = event.data.action.url
1502
+ console.log({ action: event.data.action })
1503
+ document.querySelector("#open-browser").href = url
1504
+ //document.querySelector("#location").innerHTML = url
1505
+ document.querySelector("#location").value = url
1506
+ }
1507
+ } else if (event.data.type) {
1508
+ let asideHidden = (window.getComputedStyle(document.querySelector("aside")).display === "none")
1509
+ console.log("asideHidden", asideHidden)
1510
+ if (!asideHidden) {
1511
+ // refresh only if aside
1512
+ if (event.data.type === 'disconnect') {
1513
+ console.log("Refresh 1")
1514
+ refresh()
1515
+ } else {
1516
+ console.log("Refresh 2")
1517
+ refresh()
1518
+ }
1519
+ }
1520
+ if (event.data.type === 'result') {
1521
+ refresh_du()
1506
1522
  }
1507
1523
  }
1508
- if (event.data.type === 'result') {
1509
- refresh_du()
1510
- }
1524
+ } else {
1525
+ console.log("Refresh 3")
1526
+ refresh()
1511
1527
  }
1512
- } else {
1513
- console.log("Refresh 3")
1514
- refresh()
1515
1528
  }
1516
1529
  }
1517
- }
1518
1530
 
1519
1531
 
1520
- });
1521
- refresh_du()
1522
- /*
1523
- document.addEventListener("keydown", (e) => {
1524
- let size = document.querySelectorAll(".selectable").length
1525
- console.log("size", size)
1526
- e = e || window.event;
1527
- if (e.key === "ArrowUp") {
1528
- console.log("up arrow pressed");
1529
- if (cursorIndex > 0) {
1530
- cursorIndex--;
1531
- } else {
1532
- cursorIndex = size-1;
1533
- }
1534
- //renderCursor()
1535
- //let cursor = document.querySelector(".selectable.cursor")
1536
- //cursor.scrollIntoView(false)
1537
- //
1538
- } else if (e.key === "ArrowDown") {
1539
- if (cursorIndex < size-1) {
1540
- cursorIndex++;
1541
- } else {
1542
- cursorIndex = 0;
1543
- }
1544
- //renderCursor()
1545
- console.log("down arrow pressed");
1546
- //let cursor = document.querySelector(".selectable.cursor")
1547
- //cursor.scrollIntoView(false)
1548
- } else if (e.key === "Enter") {
1549
- //let selected = document.querySelector(".line.selected:not(.hidden) .btns a.selected")
1550
- let cursor = document.querySelector(".selectable.cursor")
1551
- if (cursor) {
1552
- e.preventDefault()
1553
- e.stopPropagation()
1554
- cursor.click()
1532
+ });
1533
+ refresh_du()
1534
+ /*
1535
+ document.addEventListener("keydown", (e) => {
1536
+ let size = document.querySelectorAll(".selectable").length
1537
+ console.log("size", size)
1538
+ e = e || window.event;
1539
+ if (e.key === "ArrowUp") {
1540
+ console.log("up arrow pressed");
1541
+ if (cursorIndex > 0) {
1542
+ cursorIndex--;
1543
+ } else {
1544
+ cursorIndex = size-1;
1545
+ }
1546
+ //renderCursor()
1547
+ //let cursor = document.querySelector(".selectable.cursor")
1548
+ //cursor.scrollIntoView(false)
1549
+ //
1550
+ } else if (e.key === "ArrowDown") {
1551
+ if (cursorIndex < size-1) {
1552
+ cursorIndex++;
1553
+ } else {
1554
+ cursorIndex = 0;
1555
+ }
1556
+ //renderCursor()
1557
+ console.log("down arrow pressed");
1558
+ //let cursor = document.querySelector(".selectable.cursor")
1559
+ //cursor.scrollIntoView(false)
1560
+ } else if (e.key === "Enter") {
1561
+ //let selected = document.querySelector(".line.selected:not(.hidden) .btns a.selected")
1562
+ let cursor = document.querySelector(".selectable.cursor")
1563
+ if (cursor) {
1564
+ e.preventDefault()
1565
+ e.stopPropagation()
1566
+ cursor.click()
1567
+ }
1555
1568
  }
1556
- }
1557
- });
1558
- */
1559
- </script>
1569
+ });
1570
+ */
1571
+ </script>
1572
+ <% } %>
1560
1573
  </body>
1561
1574
  </html>