11window . onload = function ( ) {
22 //MARK: Update
3- const version = "v5.0 .0" ;
3+ const version = "v5.1 .0" ;
44
55 checkForUpdates = async ( ) => {
66 const url = 'https://api.github.com/repos/IPdotSetAF/NeoMatrix/tags' ;
@@ -15,6 +15,7 @@ window.onload = function () {
1515
1616 //MARK: Options
1717 var gui ;
18+ var defaultOptions ;
1819 var options = {
1920 ui_rain_matrixSpeed : 24 ,
2021 fpsInterval : calculateFpsInterval ( 24 ) ,
@@ -56,6 +57,10 @@ window.onload = function () {
5657 ui_message_scale : 1 ,
5758 ui_message_positionX : 0 ,
5859 ui_message_positionY : 0 ,
60+ Share ( ) {
61+ copyToClipboard ( paramsToUrl ( { preset : btoa ( JSON . stringify ( gui . save ( ) ) ) } , { } , [ ] ) ) ;
62+ Log ( "Copied Preset URL to clipboard." ) ;
63+ } ,
5964 Save ( ) {
6065 window . localStorage . setItem ( "preset" , JSON . stringify ( gui . save ( ) ) ) ;
6166 Log ( "Saved preset." ) ;
@@ -71,6 +76,14 @@ window.onload = function () {
7176 Reset ( ) {
7277 gui . reset ( ) ;
7378 Log ( "Settings reset to default." ) ;
79+ } ,
80+ LoadFrom ( params ) {
81+ let preset = gui . load ( JSON . parse ( atob ( params . preset ) ) ) ;
82+ if ( preset ) {
83+ gui . load ( preset ) ;
84+ Log ( "Loaded preset from URL." ) ;
85+ } else
86+ Log ( "Preset URl is not correct." ) ;
7487 }
7588 }
7689
@@ -83,6 +96,9 @@ window.onload = function () {
8396
8497 //MARK: GUI
8598 function drawGui ( ) {
99+ defaultOptions = JSON . parse ( JSON . stringify ( options ) ) ;
100+ const params = getUrlParams ( ) ;
101+
86102 readProjectConfig ( ) . then ( ( config ) => {
87103 gui = new lil . GUI ( { autoPlace : false , width : 300 } ) ;
88104
@@ -156,14 +172,18 @@ window.onload = function () {
156172 initialAnimation ( ) ;
157173 } ) ;
158174
175+ gui . add ( options , "Share" ) ;
159176 gui . add ( options , "Save" ) ;
160177 gui . add ( options , "Load" ) ;
161178 gui . add ( options , "Reset" ) ;
162179
163180 customContainer = document . getElementById ( 'gui' ) ;
164181 customContainer . appendChild ( gui . domElement ) ;
165182
166- options . Load ( ) ;
183+ if ( params )
184+ options . LoadFrom ( params ) ;
185+ else
186+ options . Load ( ) ;
167187 } ) ;
168188 }
169189
@@ -707,5 +727,44 @@ window.onload = function () {
707727 return acc ;
708728 } , { } ) ;
709729 }
730+
731+ function paramsToUrl ( urlParams , paramDefaults , filter ) {
732+ var defaults = new URLSearchParams ( paramDefaults )
733+ var params = new URLSearchParams ( urlParams )
734+
735+ filter . forEach ( key => {
736+ params . delete ( key ) ;
737+ defaults . delete ( key ) ;
738+ } ) ;
739+
740+ defaults . forEach ( ( value , key ) => {
741+ if ( params . get ( key ) === value )
742+ params . delete ( key ) ;
743+ } ) ;
744+
745+ return window . location . protocol + "//" + window . location . host + "/?" + params . toString ( ) ;
746+ }
747+
748+ function copyToClipboard ( text ) {
749+ const el = document . createElement ( 'textarea' ) ;
750+ el . value = text ;
751+ el . setAttribute ( 'readonly' , '' ) ;
752+ document . body . appendChild ( el ) ;
753+ el . select ( ) ;
754+ document . execCommand ( 'copy' ) ;
755+ document . body . removeChild ( el ) ;
756+ }
757+
758+ function getUrlParams ( ) {
759+ urlParams = new URLSearchParams ( window . location . search ) ;
760+ if ( urlParams . size == 0 )
761+ return null ;
762+
763+ params = { } ;
764+ for ( const [ key , value ] of urlParams )
765+ params [ key ] = value ;
766+
767+ return params ;
768+ }
710769} ;
711770
0 commit comments