pinokiod 3.2.151 → 3.2.152

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