diff --git a/README.md b/README.md index 11db2eff..2833c026 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Introduction Seekr is a multi-purpose toolkit for gathering and managing OSINT-data with a sleek web interface. Our desktop view enables you to have all of your favourite OSINT tools integrated in one. The backend is written in Go with BadgerDB as database and it offers a wide range of features for data collection, organization, and analysis. Whether you're a researcher, investigator, or just someone looking to gather information, seekr makes it easy to find and manage the data you need. Give it a try and see how it can streamline your OSINT workflow! -Check the wiki for setup guide, etc. +Check the wiki for setup guide, API-docs, etc. diff --git a/flake.nix b/flake.nix index afd6b5e4..8186a634 100644 --- a/flake.nix +++ b/flake.nix @@ -102,7 +102,7 @@ #"-X main.version=${version}" ]; - vendorSha256 = "sha256-KB9T++h6cvOvPmnDauE/r882E9qs4aNt8T7tKjlVrIE="; + vendorSha256 = "sha256-6/oUypEcri/TulwNVllB9Z8HxTxj+0pNLJ8Hqsb2NsQ="; }; }); diff --git a/generate/generate.go b/generate/generate.go index b0157bd8..b9c8bfd3 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -10,13 +10,14 @@ import ( "sync" //"github.com/seekr-osint/seekr/api" + "github.com/seekr-osint/seekr/api" "github.com/seekr-osint/seekr/api/config" "github.com/tkrajina/typescriptify-golang-structs/typescriptify" ) func main() { wg := &sync.WaitGroup{} - //GenType(api.Person{}, wg) + GenType(api.Person{}, wg) GenType(config.Config{}, wg) wg.Wait() diff --git a/go.mod b/go.mod index d4dd435c..f044d161 100644 --- a/go.mod +++ b/go.mod @@ -20,11 +20,11 @@ require ( github.com/pelletier/go-toml v1.9.5 github.com/pemistahl/lingua-go v1.3.4 github.com/projectdiscovery/subfinder/v2 v2.5.9 - github.com/rocketlaunchr/google-search v1.1.5 + github.com/rocketlaunchr/google-search v1.1.6 github.com/src-d/enry/v2 v2.1.0 - github.com/sundowndev/phoneinfoga/v2 v2.10.5 + github.com/sundowndev/phoneinfoga/v2 v2.10.7 github.com/tkrajina/typescriptify-golang-structs v0.1.10 - golang.org/x/oauth2 v0.8.0 + golang.org/x/oauth2 v0.10.0 ) require ( @@ -155,16 +155,16 @@ require ( go.uber.org/multierr v1.11.0 // indirect go4.org v0.0.0-20200411211856-f5505b9728dd // indirect golang.org/x/arch v0.3.0 // indirect - golang.org/x/crypto v0.9.0 // indirect + golang.org/x/crypto v0.11.0 // indirect golang.org/x/exp v0.0.0-20230420155640-133eef4313cb // indirect golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/net v0.12.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.8.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.30.0 // indirect + google.golang.org/protobuf v1.31.0 // indirect gopkg.in/djherbis/times.v1 v1.3.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect gopkg.in/toqueteos/substring.v1 v1.0.2 // indirect diff --git a/go.sum b/go.sum index 8e11a731..17c2ebe9 100644 --- a/go.sum +++ b/go.sum @@ -393,8 +393,8 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rocketlaunchr/google-search v1.1.5 h1:C4TsvRJ/MnBqqObs7iOjDllQYr78Tzwqq0W7GZWpO+8= -github.com/rocketlaunchr/google-search v1.1.5/go.mod h1:/IXrZI7HaBmdh75AoBpOnewFfg70ufG7KcA82Y7C6Mw= +github.com/rocketlaunchr/google-search v1.1.6 h1:DcSluQWDWEMqo6jp6OGllMTI9SBECpSmUZFntAX4j/o= +github.com/rocketlaunchr/google-search v1.1.6/go.mod h1:fk5J/qPpaRDjLWdFxT+dmuiqG7kxXArC7K8A+gj88Nk= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= @@ -431,8 +431,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/sundowndev/phoneinfoga/v2 v2.10.5 h1:+SRR7IfV19O+ctnFtShA+1ffwyMrhNxCfOK2fv38+2Y= -github.com/sundowndev/phoneinfoga/v2 v2.10.5/go.mod h1:iJy1IgGZfZErQ4JgRqh6cwJ4Ds1vqikc/Ez9LtlA+9U= +github.com/sundowndev/phoneinfoga/v2 v2.10.7 h1:RMYC4GRRVV0I7dnLln+UZ85MAdKwqpri0wqyM5FkRgQ= +github.com/sundowndev/phoneinfoga/v2 v2.10.7/go.mod h1:iJy1IgGZfZErQ4JgRqh6cwJ4Ds1vqikc/Ez9LtlA+9U= github.com/temoto/robotstxt v1.1.1/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo= github.com/temoto/robotstxt v1.1.2 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg= github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo= @@ -497,8 +497,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -561,15 +561,16 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8= -golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= +golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8= +golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -617,8 +618,9 @@ golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -626,7 +628,8 @@ golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= -golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -637,11 +640,11 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -730,8 +733,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/web/ts/framework.ts b/web/ts/framework.ts index 6374367d..ce934b9f 100644 --- a/web/ts/framework.ts +++ b/web/ts/framework.ts @@ -167,10 +167,10 @@ function checkDropdownValue(windowType: "edit" | "create", dropdownType: "gender ethnicity[translateText("indigenous_slash_native_american")!] = "Indigenous/Native American"; ethnicity[translateText("multiracial_slash_mixed")!] = "Multiracial/Mixed"; } - console.log(ethnicity[selectedEthnicity]) + return ethnicity[selectedEthnicity]; } else if (dropdownType == "religion") { - const selectedReligion = document.querySelector("body > div." + windowType + "-container > div > div.scroll-box > div:nth-child(14) > div > div.select-selected")?.innerHTML ?? ""; + const selectedReligion = document.querySelector("body > div." + windowType + "-container > div > div.scroll-box > div:nth-child(15) > div > div.select-selected")!.innerHTML ?? ""; const religion: { [key: string]: string } = {}; // English @@ -201,7 +201,7 @@ function checkDropdownValue(windowType: "edit" | "create", dropdownType: "gender return religion[selectedReligion]; } else if (dropdownType == "civilstatus") { - const selectedCivilstatus = document.querySelector("body > div." + windowType + "-container > div > div.scroll-box > div:nth-child(6) > div > div.select-selected")?.innerHTML ?? ""; + const selectedCivilstatus = document.querySelector("body > div." + windowType + "-container > div > div.scroll-box > div:nth-child(7) > div > div.select-selected")?.innerHTML ?? ""; const civilstatus: { [key: string]: string } = {}; // English diff --git a/web/ts/script.ts b/web/ts/script.ts index 496d682e..95b40b6e 100644 --- a/web/ts/script.ts +++ b/web/ts/script.ts @@ -1,1818 +1,1734 @@ import { saveAsFile, checkDropdownValue, getDropdownElementIndex, apiCall } from "./framework.js"; -//import * as person from "../ts-gen/person.js"; +import * as person from "../ts-gen/person.js"; -const searchBar = document.getElementById("searchbar"); +class Person extends person.Person { + Post(loadingSpinner?: HTMLDivElement): void { + const requestOptions = { + method: "POST", + body: JSON.stringify(this), + }; + fetch(apiCall("/person"), requestOptions) + .then(() => { + if (loadingSpinner) { + loadingSpinner.style.display = "none"; + } + location.reload(); + }) + .catch((error) => { + console.error("Error:", error); + }); + } -// Listen for messages on the broadcast channel -const channel = new BroadcastChannel("seekr-channel"); + Edit(): void { + let obj = this; + mainContainer.style.display = "none"; + editContainer.style.display = "flex"; -channel.addEventListener("message", (event) => { - if (event.data.type === "theme") { - const theme = event.data.theme; - - document.documentElement.setAttribute("data-theme", theme); - } else if (event.data.type === "language") { - translate() - } -}); + editShowID.innerHTML = obj.id; -if (!localStorage.getItem("language")) { - setLanguage("en"); // Default language -} + editNameTag.value = obj.name; -// Interface for IonIcons -interface IonIconElement extends HTMLElement { - name: string; -} + if (obj.gender != "") { + const genderSelect = document.querySelector(".edit-container > .components > .scroll-box > div:nth-child(1) > .gender-select") as HTMLElement; + const selectItems = genderSelect.querySelector(".select-items") as HTMLElement; + const selectSelected = genderSelect.querySelector(".select-selected") as HTMLElement; -// Variables for HTML elements + const genderIndex: string | undefined = getDropdownElementIndex("gender", obj.gender); - // General + if (genderIndex != undefined) { + const genderElement = selectItems.children[parseInt(genderIndex)]; -const mainContainer = document.querySelector(".main") as HTMLDivElement; -const container = document.querySelector(".container") as HTMLDivElement; -const editContainer = document.querySelector(".edit-container") as HTMLDivElement; -const createContainer = document.querySelector(".create-container") as HTMLDivElement; + selectSelected.innerHTML = translateRawWord(obj.gender)!; + genderElement.className = "same-as-selected"; + } + } -// View + if (obj.ethnicity != "") { + const ethnicitySelect = document.querySelector(".edit-container > .components > .scroll-box > div:nth-child(2) > .ethnicity-select") as HTMLElement; + const selectItems = ethnicitySelect.querySelector(".select-items") as HTMLElement; + const selectSelected = ethnicitySelect.querySelector(".select-selected") as HTMLElement; -const viewShowId = document.querySelector("#v-showid") as HTMLParagraphElement; -const viewNameTag = document.querySelector(".name-tag") as HTMLInputElement; + const ethnicityIndex: string | undefined = getDropdownElementIndex("ethnicity", obj.ethnicity); -const viewGender = document.querySelector(".gender") as HTMLParagraphElement; -const viewEthnicity = document.querySelector(".ethnicity") as HTMLParagraphElement; -const viewAge = document.querySelector(".age") as HTMLParagraphElement; -const viewBday = document.querySelector(".bday") as HTMLParagraphElement; -const viewAddress = document.querySelector(".address") as HTMLParagraphElement; -const viewCivilStatus = document.querySelector(".civilstatus") as HTMLParagraphElement; -const viewKids = document.querySelector(".kids") as HTMLParagraphElement; -const viewOccupation = document.querySelector(".occupation") as HTMLParagraphElement; -const viewPrevOccupation = document.querySelector(".prevoccupation") as HTMLParagraphElement; -const viewEducation = document.querySelector(".education") as HTMLParagraphElement; -const viewReligion = document.querySelector(".religion") as HTMLParagraphElement; -const viewPets = document.querySelector(".pets") as HTMLParagraphElement; -const viewLegal = document.querySelector(".legal") as HTMLParagraphElement; -const viewPolitical = document.querySelector(".political") as HTMLParagraphElement; -const viewNotes = document.getElementById("notes") as HTMLDivElement; + if (ethnicityIndex != undefined) { + const ethnicityElement = selectItems.children[parseInt(ethnicityIndex)]; -// Edit + selectSelected.innerHTML = translateRawWord(obj.ethnicity)!; -const editShowID = document.querySelector("#e-showid") as HTMLParagraphElement; -const editNameTag = document.querySelector(".e-name-tag") as HTMLInputElement; + ethnicityElement.className = "same-as-selected"; + } + } -const editAge = document.querySelector(".e-age") as HTMLInputElement; -const editBday = document.querySelector(".e-bday") as HTMLInputElement; -const editAddress = document.querySelector(".e-address") as HTMLInputElement; -const editKids = document.querySelector(".e-kids") as HTMLInputElement; -const editOccupation = document.querySelector(".e-occupation") as HTMLInputElement; -const editPrevOccupation = document.querySelector(".e-prevoccupation") as HTMLInputElement; -const editEducation = document.querySelector(".e-education") as HTMLInputElement; -const editPets = document.querySelector(".e-pets") as HTMLInputElement; -const editLegal = document.querySelector(".e-legal") as HTMLInputElement; -const editPolitical = document.querySelector(".e-political") as HTMLInputElement; -const editNotes = document.getElementById("e-notes") as HTMLDivElement; + editAge.innerHTML = obj.age.toString() || ""; + editBday.innerHTML = obj.bday; + editAddress.innerHTML = obj.address; -// Create + // Phone -const createNameTag = document.querySelector(".c-name-tag") as HTMLInputElement; + const phoneBase = document.querySelector(".phone-base") as HTMLDivElement; -// Accs + if (Object.keys(obj.phone).length >= 1) { + for (const [_, phone] of Object.entries(obj.phone)) { + const phoneVar = (phone as { number: string, valid: boolean, phoneinfoga: { Country: string } }) -const accNameTag = document.getElementById("acc-name-tag") as HTMLInputElement; -const accContainer = document.querySelector(".acc-container") as HTMLDivElement; -const accSearchChip = document.getElementById("acc-search-chip") as HTMLDivElement; -const accNoResults = document.getElementById("acc-no-results") as HTMLDivElement; -const accScrollBox = document.getElementById("acc-scroll-box") as HTMLDivElement; -const accAccounts = document.getElementById("accounts") as HTMLDivElement; + const container = document.createElement("div"); + container.className = "phone-container"; -const accLoadingSpinner = document.getElementById("loading-spinner") as HTMLDivElement; + const subContainer = document.createElement("div"); + subContainer.className = "phone-subcontainer"; -async function getData(): Promise { - const res = await fetch(apiCall("/")); + const phone_input = document.createElement("input"); + phone_input.className = "form-input phone"; + phone_input.id = "e-phone"; + phone_input.type = "tel"; + phone_input.placeholder = "Enter phone number"; + phone_input.spellcheck = false; + phone_input.setAttribute("lng-tag", "enter_phone_number") + phone_input.required = true; + phone_input.value = phoneVar.number; - let data = await res.json(); + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - return data; -} + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; -searchBar!.addEventListener("keyup", searchEntries); + container.appendChild(subContainer); + subContainer.appendChild(phone_input); + phoneBase.appendChild(container); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); -document.getElementById("savemdbtn")!.onclick = async function () { - const getId = document.getElementById("v-showid") as HTMLParagraphElement; - const getName = document.getElementById("name-tag") as HTMLInputElement; - const request = await fetch(apiCall("/people/" + getId!.innerHTML + "/markdown")); - const textToSave = await request.json(); + del_btn.onclick = function () { + container.remove(); + } + refreshTranslation(); + }; + } - saveAsFile(textToSave.markdown, getName!.value.toLowerCase().replace(/ /g, "") + ".md"); -} + document.getElementById("phone-add-btn")!.onclick = function () { + const phone_container = document.createElement("div"); + phone_container.className = "phone-container"; -document.getElementById("newbtn")!.onclick = function () { - mainContainer.style.display = "none"; - createContainer.style.display = "flex"; -} + const subContainer = document.createElement("div"); + subContainer.className = "phone-subcontainer"; -document.getElementById("exportbtn")!.onclick = function () { - saveAsFile(JSON.stringify(getData()), "data.json"); -} + const phone_input = document.createElement("input"); + phone_input.className = "form-input e-phone"; + phone_input.id = "phone"; + phone_input.type = "tel"; + phone_input.placeholder = "Enter phone number"; + phone_input.spellcheck = false; + phone_input.setAttribute("lng-tag", "enter_phone_number") + //phone_input.maxLength = "15"; // FIXME some formattings can have more then 15 chars. + phone_input.required = true; -function createCards(obj: any) { - let x = document.querySelector('#list-holder')!; + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - // Basic + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - const base_div = document.createElement("div"); - base_div.className = "chip"; + phoneBase.appendChild(phone_container); + phone_container.appendChild(subContainer); + subContainer.appendChild(phone_input); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - const hitbox_abbr = document.createElement("abbr"); - hitbox_abbr.title = "View" - hitbox_abbr.className = "hitbox-abbr"; + del_btn_div.onclick = function () { + phone_container.remove(); + } - const hitbox_div = document.createElement("div"); - hitbox_div.className = "hitbox"; + refreshTranslation(); + } - const p_icon_div = document.createElement("div"); - p_icon_div.className = "chip-icon"; + if (obj.civilstatus != "") { + const civilstatusSelect = document.querySelector(".edit-container > .components > .scroll-box > div:nth-child(7) > .civilstatus-select") as HTMLElement; + const selectItems = civilstatusSelect.querySelector(".select-items"); + const selectSelected = civilstatusSelect.querySelector(".select-selected"); - const p_icon = document.createElement("ion-icon"); - p_icon.className = "icon" - p_icon.setAttribute("name", "person"); + const civilstatusIndex = getDropdownElementIndex("civilstatus", obj.civilstatus); - const txt_div = document.createElement("div"); - txt_div.className = "text-container"; + if (civilstatusIndex != undefined) { + const civilstatusElement = selectItems!.children[parseInt(civilstatusIndex)]; - const name_p = document.createElement("p"); - name_p.className = "card-text"; + selectSelected!.innerHTML = translateRawWord(obj.civilstatus)!; + civilstatusElement.className = "same-as-selected"; + } + } - // Edit + editKids.innerHTML = obj.kids; - const e_icon_div = document.createElement("div"); - e_icon_div.className = "chip-edit"; + // Hobbies - const e_abbr = document.createElement("abbr"); - e_abbr.title = "Edit" + const hobbyBase = document.querySelector(".e-hobby-base") as HTMLDivElement; - const e_icon = document.createElement("ion-icon"); - e_icon.className = "icon" - e_icon.setAttribute("name", "create-outline"); + if (Object.keys(obj.hobbies).length >= 1) { + for (const [_, hobby] of Object.entries(obj.hobbies)) { + const hobbyVar = (hobby as { hobby: string }) - // Accounts + const container = document.createElement("div"); + container.className = "hobby-container"; - const acc_icon_div = document.createElement("div"); - acc_icon_div.className = "chip-acc"; + const subContainer = document.createElement("div"); + subContainer.className = "hobby-subcontainer"; - const acc_abbr = document.createElement("abbr"); - acc_abbr.title = "Add Accounts" + const hobby_input = document.createElement("input") as HTMLInputElement; + hobby_input.className = "form-input hobby"; + hobby_input.id = "e-hobby"; + hobby_input.placeholder = "Enter hobby"; + hobby_input.spellcheck = false; + hobby_input.setAttribute("lng-tag", "enter_hobby") + hobby_input.value = hobbyVar.hobby; - const acc_icon = document.createElement("ion-icon"); - acc_icon.className = "icon" - acc_icon.setAttribute("name", "person-circle-outline"); + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - // Delete + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - const d_icon_div = document.createElement("div"); - d_icon_div.className = "chip-delete"; + container.appendChild(subContainer); + subContainer.appendChild(hobby_input); + hobbyBase.appendChild(container); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - const d_abbr = document.createElement("abbr"); - d_abbr.title = "Delete" + del_btn.onclick = function () { + container.remove(); + } - const d_icon = document.createElement("ion-icon"); - d_icon.className = "icon" - d_icon.setAttribute("name", "trash-outline"); + refreshTranslation(); + }; + } - d_icon_div.onclick = function () { - fetch(apiCall("/people/" + obj.id + "/delete"), { - method: "GET", - mode: "no-cors" - }).then(function () { - location.reload(); - }); - } + document.getElementById("hobby-add-btn")!.onclick = function () { + const hobby_container = document.createElement("div"); + hobby_container.className = "hobby-container"; - acc_icon_div.onclick = function () { - editShowID.innerHTML = obj.id; - mainContainer.style.display = "none"; - accContainer.style.display = "flex"; - } + const subContainer = document.createElement("div"); + subContainer.className = "hobby-subcontainer"; - accSearchChip.onclick = search; + const hobby_input = document.createElement("input"); + hobby_input.className = "form-input e-hobby"; + hobby_input.id = "hobby"; + hobby_input.type = "text"; + hobby_input.placeholder = "Enter hobby"; + hobby_input.setAttribute("lng-tag", "enter_hobby") + hobby_input.spellcheck = false; + hobby_input.required = true; - accNameTag.onkeypress = function (event) { - // Check if the pressed key is the Enter key - if (event.key === "Enter") { - event.preventDefault(); - // Execute the search function - search(); - } + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - if (event.key == " ") { - event.preventDefault(); - } - }; + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - let isButtonEnabled = true; + hobbyBase.appendChild(hobby_container); + hobby_container.appendChild(subContainer); + subContainer.appendChild(hobby_input); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - async function search() { - if (accNameTag.value == "") { - return; - } - // Check if the button is enabled - if (!isButtonEnabled) { - return; + del_btn_div.onclick = function () { + hobby_container.remove(); + } + + refreshTranslation(); } - // Disable the button - isButtonEnabled = false; + editOccupation.innerHTML = obj.occupation; + editPrevOccupation.innerHTML = obj.prevoccupation; + editEducation.innerHTML = obj.education; - accLoadingSpinner.style.display = "inline-block"; + if (obj.religion != "") { + const religionSelect = document.querySelector(".edit-container > .components > .scroll-box > div:nth-child(15) > .religion-select") as HTMLElement; + const selectItems = religionSelect.querySelector(".select-items") as HTMLElement; + const selectSelected = religionSelect.querySelector(".select-selected") as HTMLElement; - // Set the flag to indicate that a request is in progress - const response = await fetch(apiCall('/getAccounts/' + accNameTag.value)); - const data = await response.json(); + const religionIndex = getDropdownElementIndex("religion", obj.religion); - const term_container = document.createElement("div"); - term_container.className = "term-container"; + if (religionIndex != undefined) { + const religionElement = selectItems.children[parseInt(religionIndex)]; - const term_header = document.createElement("p"); - term_header.className = "term-header"; - term_header.textContent = accNameTag.value; + selectSelected.innerHTML = translateRawWord(obj.religion)!; + religionElement.className = "same-as-selected"; + } + } - term_container.appendChild(term_header); + editPets.innerHTML = obj.pets; - if (data != null && Object.entries(data).length >= 1) { - accNoResults.style.display = "none"; - accScrollBox.style.display = "block"; + // Clubs - const row_div = document.createElement("div"); - row_div.className = "acc-row"; + const clubBase = document.querySelector(".e-club-base") as HTMLDivElement; - accAccounts.appendChild(row_div); + if (Object.keys(obj.clubs).length >= 1) { + for (const [_, club] of Object.entries(obj.clubs)) { + const clubVar = (club as { club: string }) + const container = document.createElement("div"); + container.className = "club-container"; - for (const [i, _] of Object.entries(data)) { - let accObj = data[i]; + const subContainer = document.createElement("div"); + subContainer.className = "club-subcontainer"; - const manage_acc_chip = document.createElement("div"); - manage_acc_chip.className = "manage-acc-chip" + const club_input = document.createElement("input"); + club_input.className = "form-input club"; + club_input.id = "e-club"; + club_input.type = "text"; + club_input.placeholder = "Enter club"; + club_input.spellcheck = false; + club_input.setAttribute("lng-tag", "enter_club") + club_input.value = clubVar.club; - const outer_div = document.createElement("div"); - outer_div.className = "acc-chip"; + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - const user_pfp = document.createElement("img"); - user_pfp.className = "userPfp"; + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - if (accObj.profilePicture != null) { - user_pfp.src = "data:image/png;base64," + accObj.profilePicture["1"].img; - } else { - user_pfp.src = "https://as2.ftcdn.net/v2/jpg/03/32/59/65/1000_F_332596535_lAdLhf6KzbW6PWXBWeIFTovTii1drkbT.jpg"; - } + container.appendChild(subContainer); + subContainer.appendChild(club_input); + clubBase.appendChild(container); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - const info_container = document.createElement("div"); - info_container.className = "info-container"; + del_btn.onclick = function () { + container.remove(); + } - const service_name = document.createElement("p"); - service_name.className = "serviceName"; - service_name.innerHTML = accObj.service; + refreshTranslation(); + }; + } - const user_name = document.createElement("a"); - user_name.className = "userName"; - user_name.innerHTML = accObj.username; - user_name.href = accObj.url; - user_name.target = "_blank"; + document.getElementById("club-add-btn")!.onclick = function () { + const club_container = document.createElement("div"); + club_container.className = "club-container"; - row_div.appendChild(term_container); - term_container.appendChild(manage_acc_chip); - manage_acc_chip.appendChild(outer_div); - outer_div.appendChild(user_pfp); - outer_div.appendChild(info_container); - info_container.appendChild(service_name); - info_container.appendChild(user_name); + const subContainer = document.createElement("div"); + subContainer.className = "club-subcontainer"; - if (accObj.bio != null) { - const user_bio = document.createElement("p"); - user_bio.className = "userBio"; - user_bio.innerHTML = accObj.bio["1"].bio; + const club_input = document.createElement("input"); + club_input.className = "form-input e-club"; + club_input.id = "club"; + club_input.type = "text"; + club_input.placeholder = "Enter club"; + club_input.spellcheck = false; + club_input.setAttribute("lng-tag", "enter_club") + club_input.required = true; - info_container.appendChild(user_bio); - } + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - const btn_container = document.createElement("div"); - btn_container.className = "manage-btn-container"; + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - const reject_btn = document.createElement("div"); - reject_btn.id = "acc-rejectbtn"; - reject_btn.className = "btn btn-secondary"; + clubBase.appendChild(club_container); + club_container.appendChild(subContainer); + subContainer.appendChild(club_input); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - const reject_p = document.createElement("p"); - reject_p.innerHTML = "Reject"; + del_btn_div.onclick = function () { + club_container.remove(); + } - const accept_btn = document.createElement("div"); - accept_btn.id = "acc-acceptbtn"; - accept_btn.className = "btn btn-secondary"; + refreshTranslation(); + } - const accept_p = document.createElement("p"); - accept_p.innerHTML = "Accept"; + editLegal.innerHTML = obj.legal; + editPolitical.innerHTML = obj.political; - manage_acc_chip.appendChild(btn_container); - btn_container.appendChild(reject_btn); - btn_container.appendChild(accept_btn); - reject_btn.appendChild(reject_p); - accept_btn.appendChild(accept_p); + // Sources + const sourceBase = document.querySelector(".e-source-base") as HTMLDivElement; + if (Object.keys(obj.sources).length >= 1) { + for (const [_, url] of Object.entries(obj.sources)) { + const sourceVar = (url as { url: string }) + const container = document.createElement("div"); + container.className = "source-container"; - accept_btn.onclick = async function () { - // Check if accObj.service and accObj.username are also in accounts object at obj.accounts - let getId = editShowID.innerHTML + const subContainer = document.createElement("div"); + subContainer.className = "source-subcontainer"; - const res = await fetch(apiCall("/people/" + getId)) + const source_input = document.createElement("input"); + source_input.className = "form-input source"; + source_input.id = "e-source"; + source_input.type = "text"; + source_input.placeholder = "Enter source"; + source_input.spellcheck = false; + source_input.setAttribute("lng-tag", "enter_source") + source_input.value = sourceVar.url; - let data = await res.json(); + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - data.accounts[accObj.service + "-" + accObj.username] = accObj; + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - fetch(apiCall("/person"), { - method: 'POST', - body: JSON.stringify(data) - }); + container.appendChild(subContainer); + subContainer.appendChild(source_input); + sourceBase.appendChild(container); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - accept_p.innerHTML = "Accepted!"; + del_btn.onclick = function () { + container.remove(); } - reject_btn.onclick = async function () { - let elementCount = term_container.childElementCount; + refreshTranslation(); + }; + } - if (elementCount > 2) { - manage_acc_chip.remove(); - } else { - row_div.remove(); - } - } - } - } else { - // No accounts found + document.getElementById("source-add-btn")!.onclick = function () { + const source_container = document.createElement("div"); + source_container.className = "source-container"; - if (accAccounts.childElementCount <= 0) { - accNoResults.style.display = "flex"; - accScrollBox.style.display = "none"; - } - } + const subContainer = document.createElement("div"); + subContainer.className = "source-subcontainer"; - accLoadingSpinner.style.display = "none"; - isButtonEnabled = true; - } + const source_input = document.createElement("input"); + source_input.className = "form-input e-source"; + source_input.id = "source"; + source_input.type = "text"; + source_input.placeholder = "Enter source"; + source_input.spellcheck = false; + source_input.setAttribute("lng-tag", "enter_source") + source_input.required = true; - base_div.appendChild(hitbox_abbr); - hitbox_abbr.appendChild(hitbox_div); - hitbox_div.appendChild(p_icon_div); - hitbox_div.appendChild(txt_div); - txt_div.appendChild(name_p); - base_div.appendChild(e_abbr); - e_abbr.appendChild(e_icon_div); - base_div.appendChild(acc_abbr); - base_div.appendChild(d_abbr); - acc_abbr.appendChild(acc_icon_div); - d_abbr.appendChild(d_icon_div); - p_icon_div.appendChild(p_icon); - e_icon_div.appendChild(e_icon); - acc_icon_div.appendChild(acc_icon); - d_icon_div.appendChild(d_icon); + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - name_p.innerHTML = `${obj.name}` - x.appendChild(base_div); + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - hitbox_div.onclick = async function () { - mainContainer.style.display = "none"; - container.style.display = "flex"; + sourceBase.appendChild(source_container); + source_container.appendChild(subContainer); + subContainer.appendChild(source_input); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - viewShowId.innerHTML = obj.id; + del_btn_div.onclick = function () { + source_container.remove(); + } - viewNameTag.value = obj.name; + refreshTranslation(); + } - viewGender.innerHTML = translateRawWord("Gender:")! + " " + translateRawWord(obj.gender); - viewEthnicity.innerHTML = translateRawWord("Ethnicity:")! + " " + translateRawWord(obj.ethnicity); - viewAge.innerHTML = translateRawWord("Age:")! + " " + obj.age; - viewBday.innerHTML = translateRawWord("Birthday:")! + " " + obj.bday; - viewAddress.innerHTML = translateRawWord("Address:")! + " " + obj.address; - viewCivilStatus.innerHTML = translateRawWord("Civil status:")! + " " + translateRawWord(obj.civilstatus); - viewKids.innerHTML = translateRawWord("Kids:") + " " + obj.kids; - viewOccupation.innerHTML = translateRawWord("Occupation:")! + " " + obj.occupation; - viewPrevOccupation.innerHTML = translateRawWord("Previous Occupation:")! + obj.prevoccupation; - viewEducation.innerHTML = translateRawWord("Education:")! + " " + obj.education; - viewReligion.innerHTML = translateRawWord("Religion:")! + " " + translateRawWord(obj.religion); - viewPets.innerHTML = translateRawWord("Pets:")! + " " + obj.pets; - viewLegal.innerHTML = translateRawWord("Legal:")! + " " + obj.legal; - viewPolitical.innerHTML = translateRawWord("Political:")! + " " + obj.political; - viewNotes.innerHTML = obj.notes; + editNotes.innerHTML = obj.notes; + // IPs - const allObjectsAtStart = document.querySelectorAll(".viewtag"); + const ipBase = document.querySelector(".e-ip-base") as HTMLDivElement; - allObjectsAtStart.forEach((object) => { - object.style.display = "flex"; - }); + if (Object.keys(obj.ips).length >= 1) { + for (const [_, ip] of Object.entries(obj.ips)) { + const ipVar = (ip as { ip: string }) + const container = document.createElement("div"); + container.className = "ip-container"; - // Get all the elements with the class "viewtag" and store them in a variable called "allObjects" - let allObjects = document.getElementsByClassName("viewtag"); + const subContainer = document.createElement("div"); + subContainer.className = "ip-subcontainer"; - // Loop through all the objects in the array - for (let i = 0; i < allObjects.length; i++) { + const ip_input = document.createElement("input"); + ip_input.className = "form-input ip"; + ip_input.id = "e-ip"; + ip_input.type = "text"; + ip_input.placeholder = "Enter IP"; + ip_input.spellcheck = false; + ip_input.setAttribute("lng-tag", "enter_ip") + ip_input.value = ipVar.ip; - // Store the current object's HTML in a variable called "item" - let item = allObjects[i] as HTMLElement; - // Get the text from the object's HTML and store it in a variable called "tempText" - let tempText = item.innerHTML.substring(item.innerHTML.indexOf(':') + 1).trim(); + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - // Check if the text is empty, null, or undefined - if (tempText.length <= 0 || tempText.replace(" ","") == "" || tempText == null || tempText == undefined || tempText == "0") { - // Remove the object from the page - // allObjects[i].remove(); + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - item.style.display = "none"; - // i--; - } - } + container.appendChild(subContainer); + subContainer.appendChild(ip_input); + ipBase.appendChild(container); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - if (viewNotes.innerHTML.length <= 0) { - document.getElementById("space-maker")!.style.display = "none"; - } + del_btn.onclick = function () { + container.remove(); + } - // Hobbies + refreshTranslation(); + }; + } - const viewHobbyBase = document.querySelector(".v-hobby-base") as HTMLDivElement; - const viewHobbySpacemaker = document.querySelector(".v-hobby-space-maker") as HTMLDivElement; + document.getElementById("ip-add-btn")!.onclick = function () { + const ip_container = document.createElement("div"); + ip_container.className = "ip-container"; - viewHobbyBase.style.display = "block"; + const subContainer = document.createElement("div"); + subContainer.className = "ip-subcontainer"; - if (Object.keys(obj.hobbies).length >= 1) { - const hobbyContainer = document.querySelector(".v-hobby-base") as HTMLDivElement; + const ip_input = document.createElement("input"); + ip_input.className = "form-input e-ip"; + ip_input.id = "ip"; + ip_input.type = "text"; + ip_input.placeholder = "Enter IP"; + ip_input.spellcheck = false; + ip_input.setAttribute("lng-tag", "enter_ip") + ip_input.required = true; - for (const [_, hobby] of Object.entries(obj.hobbies)) { - const hobbyVar = (hobby as { hobby: string }) + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - if (hobbyVar.hobby != "" && hobbyVar.hobby != null && hobbyVar.hobby != undefined) { - viewHobbySpacemaker.style.display = "block"; - const container = document.createElement("div"); - container.className = "v-hobby-container"; + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - const subContainer = document.createElement("div"); - subContainer.className = "hobby-subcontainer"; + ipBase.appendChild(ip_container); + ip_container.appendChild(subContainer); + subContainer.appendChild(ip_input); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - const hobby_input = document.createElement("input") as HTMLInputElement; - hobby_input.className = "form-input v-hobby"; - hobby_input.id = "v-hobby"; - hobby_input.type = "hobby"; - hobby_input.required = true; - hobby_input.value = hobbyVar.hobby; - hobby_input.disabled = true; + del_btn_div.onclick = function () { + ip_container.remove(); + } - hobbyContainer.appendChild(container); - container.appendChild(subContainer); - subContainer.appendChild(hobby_input); - }; - }; - } else { - viewHobbySpacemaker.style.display = "none"; + refreshTranslation(); } - // IPs + // Email - const viewIpBase = document.querySelector(".v-ip-base") as HTMLDivElement; - const viewIpSpacemaker = document.querySelector(".v-ip-space-maker") as HTMLDivElement; + const emailBase = document.querySelector(".email-base") as HTMLDivElement; - viewIpBase.style.display = "block"; + if (Object.keys(obj.email).length >= 1) { + for (const [_, email] of Object.entries(obj.email)) { + const emailVar = (email as { mail: string, services: {} }); - if (Object.keys(obj.ips).length >= 1) { - const ipContainer = document.querySelector(".v-ip-base") as HTMLDivElement; + const container = document.createElement("div"); + container.className = "email-container"; - for (const [_, ip] of Object.entries(obj.ips)) { - const ipVar = (ip as { ip: string }) + const subContainer = document.createElement("div"); + subContainer.className = "email-subcontainer"; - if (ipVar.ip != "" && ipVar.ip != null && ipVar.ip != undefined) { - viewIpSpacemaker.style.display = "block"; - const container = document.createElement("div"); - container.className = "v-ip-container"; + const email_input = document.createElement("input"); + email_input.className = "form-input e-mail"; + email_input.id = "e-mail"; + email_input.type = "email"; + email_input.placeholder = "Enter email address"; + email_input.spellcheck = false; + email_input.setAttribute("lng-tag", "enter_email_address") + email_input.required = true; + email_input.value = emailVar.mail; - const subContainer = document.createElement("div"); - subContainer.className = "ip-subcontainer"; + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - const ip_input = document.createElement("input"); - ip_input.className = "form-input v-ip"; - ip_input.id = "v-ip"; - ip_input.type = "ip"; - ip_input.spellcheck = false; - ip_input.value = ipVar.ip; - ip_input.disabled = true; + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - ipContainer.appendChild(container); - container.appendChild(subContainer); - subContainer.appendChild(ip_input); + container.appendChild(subContainer); + subContainer.appendChild(email_input); + emailBase.appendChild(container); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); + + if (emailVar.services != undefined && emailVar.services != null && emailVar.services != "") { + const hidden_email_save = document.createElement("p"); + hidden_email_save.className = "hidden-email-save"; + + hidden_email_save.innerHTML = JSON.stringify(emailVar.services); + container.appendChild(hidden_email_save); + } + + del_btn.onclick = function () { + container.remove(); } + + refreshTranslation(); }; - } else { - viewIpSpacemaker.style.display = "none"; } - // Clubs - const viewClubBase = document.querySelector(".v-club-base") as HTMLDivElement; - const viewClubSpacemaker = document.querySelector(".v-club-space-maker") as HTMLDivElement; - viewClubBase.style.display = "block"; + document.getElementById("email-add-btn")!.onclick = function () { + const email_base = document.querySelector(".email-base"); - if (Object.keys(obj.clubs).length >= 1) { - const clubContainer = document.querySelector(".v-club-base") as HTMLDivElement; + const email_container = document.createElement("div"); + email_container.className = "email-container"; - for (const [_, club] of Object.entries(obj.clubs)) { - const clubVar = (club as { club: string }) + const subContainer = document.createElement("div"); + subContainer.className = "email-subcontainer"; - if (clubVar.club != "" && clubVar.club != null && clubVar.club != undefined) { - viewClubSpacemaker.style.display = "block"; - const container = document.createElement("div"); - container.className = "v-club-container"; + const email_input = document.createElement("input"); + email_input.className = "form-input e-mail"; + email_input.id = "e-mail"; + email_input.type = "email"; + email_input.placeholder = "Enter email address"; + email_input.spellcheck = false; + email_input.setAttribute("lng-tag", "enter_email_address") + email_input.required = true; - const subContainer = document.createElement("div"); - subContainer.className = "club-subcontainer"; + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - const club_input = document.createElement("input"); - club_input.className = "form-input v-club"; - club_input.id = "v-club"; - club_input.type = "club"; - club_input.spellcheck = false; - club_input.value = clubVar.club; - club_input.disabled = true; + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - clubContainer.appendChild(container); - container.appendChild(subContainer); - subContainer.appendChild(club_input); - } - }; - } else { - viewClubSpacemaker.style.display = "none"; - } + emailBase.appendChild(email_container); + email_container.appendChild(subContainer); + subContainer.appendChild(email_input); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - // Sources + const hidden_email_save = document.createElement("p"); + hidden_email_save.className = "hidden-email-save"; + email_container.appendChild(hidden_email_save); - const viewSourceBase = document.querySelector(".v-source-base") as HTMLDivElement; - const viewSourceSpacemaker = document.querySelector(".v-source-space-maker") as HTMLDivElement; + del_btn_div.onclick = function () { + email_container.remove(); + } - viewSourceBase.style.display = "block"; + refreshTranslation(); + } - if (Object.keys(obj.sources).length >= 1) { - const sourceContainer = document.querySelector(".v-source-base") as HTMLDivElement; + // Accounts - for (const [_, url] of Object.entries(obj.sources)) { - const sourceVar = (url as { url: string }) + if (Object.keys(obj.accounts).length != 0 && obj.accounts != null) { + for (const [_, accObj] of Object.entries(obj.accounts)) { + const accVar = (accObj as { service: string, id: string, username: string, url: string, profilePicture: { [key: number]: { img: string, img_hash: number } }, bio: { [key: number]: { bio: string } } }); - if (sourceVar.url != "" && sourceVar.url != null && sourceVar.url != undefined) { - viewSourceSpacemaker.style.display = "block"; - const container = document.createElement("div"); - container.className = "v-source-container"; + //let accObj = obj.accounts[i]; - const subContainer = document.createElement("div"); - subContainer.className = "source-subcontainer"; + // Creating elements - const source_field = document.createElement("a"); - source_field.className = "source-link v-source"; - source_field.id = "v-source"; - source_field.type = "source"; - source_field.spellcheck = false; - source_field.innerHTML = sourceVar.url; - source_field.href = sourceVar.url; - source_field.target = "_blank"; + const base_div = document.createElement("div"); // Outer div + base_div.className = "acc-chip"; - sourceContainer.appendChild(container); - container.appendChild(subContainer); - subContainer.appendChild(source_field); - } - }; - } else { - viewSourceSpacemaker.style.display = "none"; - } + const pfp_img = document.createElement("img"); // Pfp img + pfp_img.className = "userPfp"; - // Phone + if (accVar.profilePicture != null) { + pfp_img.src = "data:image/png;base64," + accVar.profilePicture["1"].img; + } else { + pfp_img.src = "https://as2.ftcdn.net/v2/jpg/03/32/59/65/1000_F_332596535_lAdLhf6KzbW6PWXBWeIFTovTii1drkbT.jpg" + } - const viewPhoneBase = document.querySelector(".v-phone-base") as HTMLDivElement; - const viewPhoneSpacemaker = document.querySelector(".v-phone-space-maker") as HTMLDivElement; + const info_div = document.createElement("div"); // Info div + info_div.className = "info-container"; - viewPhoneBase.style.display = "block"; + const icon_space = document.createElement("div"); + icon_space.className = "icon-space"; - if (Object.keys(obj.phone).length >= 1) { - const phoneContainer = document.querySelector(".v-phone-base") as HTMLDivElement; + const service_p = document.createElement("a"); + service_p.className = "serviceName"; + service_p.innerHTML = accVar.service; + service_p.href = accVar.url; + service_p.target = "_blank"; - for (const [_, phone] of Object.entries(obj.phone)) { - const phoneVar = (phone as { number: string, valid: boolean, phoneinfoga: { Country: string } }) + const name_p = document.createElement("a"); + name_p.className = "userName"; + name_p.innerHTML = accVar.username; + name_p.href = accVar.url; + name_p.target = "_blank"; - if (phoneVar.number != "" && phoneVar.number != null && phoneVar.number != undefined) { - viewPhoneSpacemaker.style.display = "block"; - const container = document.createElement("div"); - container.className = "v-phone-container"; + document.querySelector(".e-accounts")!.appendChild(base_div); + base_div.appendChild(pfp_img); + base_div.appendChild(info_div); + base_div.appendChild(icon_space); + info_div.appendChild(service_p); + info_div.appendChild(name_p); - const subContainer = document.createElement("div"); - subContainer.className = "phone-subcontainer"; + if (accVar.service.toLowerCase() == "github") { // If the service is github, add a deep investigation button + const deep_btn = document.createElement("div"); + deep_btn.className = "deepInvBtn btn btn-secondary"; + deep_btn.id = "deepInvBtn"; - const phone_input = document.createElement("input"); - phone_input.className = "form-input v-phone"; - phone_input.id = "v-phone"; - phone_input.type = "phone"; - phone_input.value = phoneVar.number; - phone_input.disabled = true; + const deep_btn_txt = document.createElement("p"); + deep_btn_txt.className = "deepInvBtnTxt"; + deep_btn_txt.innerHTML = "Deep Investigation"; + base_div.appendChild(deep_btn); + deep_btn.appendChild(deep_btn_txt); - const infoBtn = document.createElement("div"); - infoBtn.className = "v-info-btn"; + const del_btn_div = document.createElement("div"); + del_btn_div.className = "delAccBtn-deep btn btn-secondary"; - const icon = document.createElement("ion-icon"); - icon.setAttribute("name", "information-outline"); + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - container.appendChild(subContainer); - infoBtn.appendChild(icon); - subContainer.appendChild(phone_input); - subContainer.appendChild(infoBtn); - phoneContainer.appendChild(container); + base_div.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - infoBtn.onclick = function () { - const infoDiv = container.querySelector(".v-info-div"); - if (!infoDiv) { - const infoDiv = document.createElement("div"); - infoDiv.className = "v-info-div"; + // Deep investigation + deep_btn.onclick = async function () { + if (icon_space.firstChild) { + icon_space.firstChild.remove(); + } - container.appendChild(infoDiv); - // use a function and parse the arg valid/invalid and use the literal string everywhere - if (phoneVar.valid == true) { - const abbrContainerValidity = document.createElement("abbr") - abbrContainerValidity.className = "validity-abbr"; - abbrContainerValidity.title = "Valid Phone Number"; + deep_btn_txt.innerHTML = "This may take up to an hour..."; - const iconDivValid = document.createElement("div"); - iconDivValid.className = "valid-icon-div"; + const loadingSpinner = document.createElement("div"); + loadingSpinner.className = "neu"; + loadingSpinner.id = "deepInvLoadingSpinner"; + loadingSpinner.style.display = "flex"; - const iconValid = document.createElement("img"); - iconValid.className = "valid-icon phone-icon"; - iconValid.src = "./images/valid-phone.png"; + const loadingSpinnerShape = document.createElement("div"); + loadingSpinnerShape.className = "neu_shape"; - infoDiv.appendChild(abbrContainerValidity); - abbrContainerValidity.appendChild(iconDivValid); - iconDivValid.appendChild(iconValid); - } else if (phoneVar.valid == false) { - const abbrContainerValidity = document.createElement("abbr") - abbrContainerValidity.className = "validity-abbr"; - abbrContainerValidity.title = "Invalid Phone Number"; + const loadingSpinnerInner = document.createElement("div"); + loadingSpinnerInner.className = "neu_inner"; - const iconDivValid = document.createElement("div"); - iconDivValid.className = "valid-icon-div"; + const loadingSpinnerBall = document.createElement("div"); + loadingSpinnerBall.className = "neu_ball"; - const iconValid = document.createElement("img"); - iconValid.className = "valid-icon phone-icon"; - iconValid.src = "./images/invalid-phone.png"; - infoDiv.appendChild(abbrContainerValidity); - abbrContainerValidity.appendChild(iconDivValid); - iconDivValid.appendChild(iconValid); - } + icon_space.appendChild(loadingSpinner) + loadingSpinner.appendChild(loadingSpinnerShape); + loadingSpinnerShape.appendChild(loadingSpinnerInner); + loadingSpinnerInner.appendChild(loadingSpinnerBall); + loadingSpinnerInner.appendChild(loadingSpinnerBall.cloneNode()); + loadingSpinnerInner.appendChild(loadingSpinnerBall.cloneNode()); + loadingSpinnerInner.appendChild(loadingSpinnerBall.cloneNode()); - // This should almost never fail - if (phoneVar.phoneinfoga.Country != "" && phoneVar.phoneinfoga.Country != null && phoneVar.phoneinfoga.Country != undefined) { - const abbrContainer = document.createElement("abbr") - abbrContainer.className = "phone-info-abbr"; - abbrContainer.title = phoneVar.phoneinfoga.Country; - const iconDiv = document.createElement("div"); - iconDiv.className = "service-icon-div"; + const res = await fetch(apiCall("/deep/github/" + accVar.username)) + let data = await res.json(); - const icon = document.createElement("img"); - icon.className = "country-icon"; - icon.src = "./images/flags/" + phoneVar.phoneinfoga.Country + ".png"; + loadingSpinner.remove(); - infoDiv.appendChild(abbrContainer); - abbrContainer.appendChild(iconDiv); - iconDiv.appendChild(icon); - } - } else { - container.removeChild(infoDiv); - } - } - } - }; - } else { - viewPhoneSpacemaker.style.display = "none"; - } + const deepInvResIcon = document.createElement("ion-icon") as IonIconElement; + deepInvResIcon.className = "deepInvResIcon"; + icon_space.appendChild(deepInvResIcon); - // Email + if (data != null && data != "{}" && res.status == 200) { + deep_btn_txt.innerHTML = "Deep Investigation"; - const viewEmailBase = document.querySelector(".v-email-base") as HTMLDivElement; - const viewEmailSpacemaker = document.querySelector(".v-email-space-maker") as HTMLDivElement; + deepInvResIcon.name = "checkmark-outline"; + deepInvResIcon.style.filter = "drop-shadow(0.3rem 0.3rem 0.2rem var(--greyLight-2)) drop-shadow(-0.2rem -0.2rem 0.5rem var(--white));" - viewEmailBase.style.display = "block"; + for (const [i, _] of Object.entries(data)) { + let obj = data[i]; - if (Object.keys(obj.email).length >= 1) { - for (const [_, email] of Object.entries(obj.email)) { - const emailVar = (email as { mail: string, valid: boolean, services: { service: { name: string, icon: string, link: string } } }) + const email_container = document.createElement("div"); + email_container.className = "email-container"; - if (emailVar.mail != "" && emailVar.mail != null && emailVar.mail != undefined) { - viewEmailSpacemaker.style.display = "block"; - const container = document.createElement("div"); - container.className = "v-email-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "email-subcontainer"; - - const email_input = document.createElement("input"); - email_input.className = "form-input v-mail"; - email_input.id = "v-e-mail"; - email_input.type = "email"; - email_input.required = true; - email_input.value = emailVar.mail; - email_input.disabled = true; - - - const infoBtn = document.createElement("div"); - infoBtn.className = "v-info-btn"; - - const icon = document.createElement("ion-icon"); - icon.setAttribute("name", "information-outline"); - - container.appendChild(subContainer); - infoBtn.appendChild(icon); - subContainer.appendChild(email_input); - subContainer.appendChild(infoBtn); - viewEmailBase.appendChild(container); - - infoBtn.onclick = function () { - const infoDiv = container.querySelector(".v-info-div"); - - if (!infoDiv) { - const infoDiv = document.createElement("div"); - infoDiv.className = "v-info-div"; - - container.appendChild(infoDiv); - - if (emailVar.valid == true) { - const abbrContainerValidity = document.createElement("abbr") - abbrContainerValidity.className = "validity-abbr"; - abbrContainerValidity.title = "Valid Email"; - - const iconDivValid = document.createElement("div"); - iconDivValid.className = "valid-icon-div"; - - const iconValid = document.createElement("img"); - iconValid.className = "valid-icon"; - iconValid.src = "./images/valid.png"; - - infoDiv.appendChild(abbrContainerValidity); - abbrContainerValidity.appendChild(iconDivValid); - iconDivValid.appendChild(iconValid); - } else if (emailVar.valid == false) { - const abbrContainerValidity = document.createElement("abbr") - abbrContainerValidity.className = "validity-abbr"; - abbrContainerValidity.title = "Invalid Email"; - - const iconDivValid = document.createElement("div"); - iconDivValid.className = "valid-icon-div"; - - const iconValid = document.createElement("img"); - iconValid.className = "valid-icon"; - iconValid.src = "./images/invalid.png"; + const subContainer = document.createElement("div"); + subContainer.className = "email-subcontainer"; - infoDiv.appendChild(abbrContainerValidity); - abbrContainerValidity.appendChild(iconDivValid); - iconDivValid.appendChild(iconValid); - } + const email_input = document.createElement("input"); + email_input.className = "form-input e-mail"; + email_input.id = "e-mail"; + email_input.type = "email"; + email_input.placeholder = "Enter email address"; + email_input.spellcheck = false; + email_input.setAttribute("lng-tag", "enter_email_address") + email_input.value = obj.mail; - if (emailVar.services != undefined && emailVar.services != null) { - for (const [_, service] of Object.entries(emailVar.services)) { - const abbrContainer = document.createElement("abbr") - abbrContainer.className = "service-abbr"; - abbrContainer.title = service.name; + const del_btn_div = document.createElement("div"); + del_btn_div.className = "del-btn"; - const iconDiv = document.createElement("div"); - iconDiv.className = "service-icon-div"; + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - const icon = document.createElement("img"); - icon.className = "service-icon"; - icon.src = service.icon; + const hidden_email_save = document.createElement("p"); + hidden_email_save.className = "hidden-email-save"; + hidden_email_save.innerHTML = JSON.stringify(obj.services); - infoDiv.appendChild(abbrContainer); - abbrContainer.appendChild(iconDiv); - iconDiv.appendChild(icon); + emailBase.appendChild(email_container); + email_container.appendChild(subContainer); + subContainer.appendChild(email_input); + subContainer.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); + email_container.appendChild(hidden_email_save); - iconDiv.onclick = function () { - if (service.link != "") { - window.open(service.link, "_blank"); - } - } - }; + del_btn_div.onclick = function () { + email_container.remove(); + } - container.appendChild(infoDiv); + refreshTranslation(); } + } else if (res.status == 403 && data["fatal"] == "rate limited") { + deepInvResIcon.name = "timer-outline"; + deepInvResIcon.style.filter = "drop-shadow(0.3rem 0.3rem 0.15rem var(--greyLight-2)) drop-shadow(-0.2rem -0.2rem 0.5rem var(--white));" } else { - container.removeChild(infoDiv); + deepInvResIcon.name = "close-outline"; + deepInvResIcon.style.filter = "drop-shadow(0.3rem 0.3rem 0.2rem var(--greyLight-2)) drop-shadow(-0.2rem -0.2rem 0.5rem var(--white));" } } - } - }; - } else { - viewEmailSpacemaker.style.display = "none"; - } - - - // Accounts - - if (obj.accounts.length != 0 && obj.accounts != null) { - for (const [_, accObj] of Object.entries(obj.accounts)) { - const accVar = (accObj as { service: string, id: string, username: string, url: string, profilePicture: { [key: number]: { img: string, img_hash: number } }, bio: { [key: number]: { bio: string } } }); - - //let accObj = obj.accounts[i]; - - // Creating elements - const base_div = document.createElement("div"); // Outer div - base_div.className = "acc-chip"; - const pfp_img = document.createElement("img"); // Pfp img - pfp_img.className = "userPfp"; + del_btn_div.onclick = function () { + fetch(apiCall("/people/" + document.querySelector("#e-showid")!.innerHTML + "/accounts/" + accVar.service + "-" + accVar.username + "/delete"), { + method: "GET", + mode: "no-cors" + }); - if (accVar.profilePicture != null) { - pfp_img.src = "data:image/png;base64," + accVar.profilePicture[1]!.img; + base_div.remove(); + // TODO Add stuff here + } } else { - pfp_img.src = "https://as2.ftcdn.net/v2/jpg/03/32/59/65/1000_F_332596535_lAdLhf6KzbW6PWXBWeIFTovTii1drkbT.jpg" - } + const del_btn_div = document.createElement("div"); + del_btn_div.className = "delAccBtn btn btn-secondary"; - const info_div = document.createElement("div"); // Info div - info_div.className = "info-container"; + const del_btn = document.createElement("ion-icon") as IonIconElement; + del_btn.name = "remove-outline"; - const service_p = document.createElement("a"); - service_p.className = "serviceName"; - service_p.innerHTML = accVar.service; - service_p.href = accVar.url; - service_p.target = "_blank"; + base_div.appendChild(del_btn_div); + del_btn_div.appendChild(del_btn); - const name_p = document.createElement("a"); - name_p.className = "userName"; - name_p.innerHTML = accVar.username; - name_p.href = accVar.url; - name_p.target = "_blank"; + del_btn_div.onclick = function () { + fetch(apiCall("/people/" + document.querySelector("#e-showid")!.innerHTML + "/accounts/" + accVar.service + "-" + accVar.username + "/delete"), { + method: "GET", + mode: "no-cors" + }); + base_div.remove(); - document.querySelector(".accounts")!.appendChild(base_div); - base_div.appendChild(pfp_img); - base_div.appendChild(info_div); - info_div.appendChild(service_p); - info_div.appendChild(name_p); + // TODO Add stuff here + } + } if (accVar.bio != null) { const bio_p = document.createElement("p"); bio_p.className = "userBio"; - bio_p.innerHTML = accVar.bio[1].bio; + bio_p.innerHTML = accVar.bio["1"].bio; info_div.appendChild(bio_p); } } } + return } +} - e_icon_div.onclick = function () { - mainContainer.style.display = "none"; - editContainer.style.display = "flex"; - - editShowID.innerHTML = obj.id; - - editNameTag.value = obj.name; - - if (obj.gender != "") { - const genderSelect = document.querySelector(".edit-container > .components > .scroll-box > div:nth-child(1) > .gender-select") as HTMLElement; - const selectItems = genderSelect.querySelector(".select-items") as HTMLElement; - const selectSelected = genderSelect.querySelector(".select-selected") as HTMLElement; - - const genderIndex: string | undefined = getDropdownElementIndex("gender", obj.gender); - if (genderIndex != undefined) { - const genderElement = selectItems.children[parseInt(genderIndex)]; +const searchBar = document.getElementById("searchbar"); - selectSelected.innerHTML = translateRawWord(obj.gender)!; - genderElement.className = "same-as-selected"; - } - } - if (obj.ethnicity != "") { - const ethnicitySelect = document.querySelector(".edit-container > .components > .scroll-box > div:nth-child(2) > .ethnicity-select") as HTMLElement; - const selectItems = ethnicitySelect.querySelector(".select-items") as HTMLElement; - const selectSelected = ethnicitySelect.querySelector(".select-selected") as HTMLElement; +// Listen for messages on the broadcast channel +const channel = new BroadcastChannel("seekr-channel"); - const ethnicityIndex: string | undefined = getDropdownElementIndex("ethnicity", obj.ethnicity); +channel.addEventListener("message", (event) => { + if (event.data.type === "theme") { + const theme = event.data.theme; - if (ethnicityIndex != undefined) { - const ethnicityElement = selectItems.children[parseInt(ethnicityIndex)]; + document.documentElement.setAttribute("data-theme", theme); + } else if (event.data.type === "language") { + translate() + } +}); - selectSelected.innerHTML = translateRawWord(obj.ethnicity)!; - ethnicityElement.className = "same-as-selected"; - } - } +if (!localStorage.getItem("language")) { + setLanguage("en"); // Default language +} - editAge.innerHTML = obj.age; - editBday.innerHTML = obj.bday; - editAddress.innerHTML = obj.address; +// Interface for IonIcons +interface IonIconElement extends HTMLElement { + name: string; +} - // Phone +// Variables for HTML elements - const phoneBase = document.querySelector(".phone-base") as HTMLDivElement; +// General - if (Object.keys(obj.phone).length >= 1) { - for (const [_, phone] of Object.entries(obj.phone)) { - const phoneVar = (phone as { number: string, valid: boolean, phoneinfoga: { Country: string } }) +const mainContainer = document.querySelector(".main") as HTMLDivElement; +const container = document.querySelector(".container") as HTMLDivElement; +const editContainer = document.querySelector(".edit-container") as HTMLDivElement; +const createContainer = document.querySelector(".create-container") as HTMLDivElement; - const container = document.createElement("div"); - container.className = "phone-container"; +// View - const subContainer = document.createElement("div"); - subContainer.className = "phone-subcontainer"; +const viewShowId = document.querySelector("#v-showid") as HTMLParagraphElement; +const viewNameTag = document.querySelector(".name-tag") as HTMLInputElement; - const phone_input = document.createElement("input"); - phone_input.className = "form-input phone"; - phone_input.id = "e-phone"; - phone_input.type = "tel"; - phone_input.placeholder = "Enter phone number"; - phone_input.spellcheck = false; - phone_input.setAttribute("lng-tag", "enter_phone_number") - phone_input.required = true; - phone_input.value = phoneVar.number; - - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; +const viewGender = document.querySelector(".gender") as HTMLParagraphElement; +const viewEthnicity = document.querySelector(".ethnicity") as HTMLParagraphElement; +const viewAge = document.querySelector(".age") as HTMLParagraphElement; +const viewBday = document.querySelector(".bday") as HTMLParagraphElement; +const viewAddress = document.querySelector(".address") as HTMLParagraphElement; +const viewCivilStatus = document.querySelector(".civilstatus") as HTMLParagraphElement; +const viewKids = document.querySelector(".kids") as HTMLParagraphElement; +const viewOccupation = document.querySelector(".occupation") as HTMLParagraphElement; +const viewPrevOccupation = document.querySelector(".prevoccupation") as HTMLParagraphElement; +const viewEducation = document.querySelector(".education") as HTMLParagraphElement; +const viewReligion = document.querySelector(".religion") as HTMLParagraphElement; +const viewPets = document.querySelector(".pets") as HTMLParagraphElement; +const viewLegal = document.querySelector(".legal") as HTMLParagraphElement; +const viewPolitical = document.querySelector(".political") as HTMLParagraphElement; +const viewNotes = document.getElementById("notes") as HTMLDivElement; - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; +// Edit - container.appendChild(subContainer); - subContainer.appendChild(phone_input); - phoneBase.appendChild(container); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); +const editShowID = document.querySelector("#e-showid") as HTMLParagraphElement; +const editNameTag = document.querySelector(".e-name-tag") as HTMLInputElement; +const editAge = document.querySelector(".e-age") as HTMLInputElement; +const editBday = document.querySelector(".e-bday") as HTMLInputElement; +const editAddress = document.querySelector(".e-address") as HTMLInputElement; +const editKids = document.querySelector(".e-kids") as HTMLInputElement; +const editOccupation = document.querySelector(".e-occupation") as HTMLInputElement; +const editPrevOccupation = document.querySelector(".e-prevoccupation") as HTMLInputElement; +const editEducation = document.querySelector(".e-education") as HTMLInputElement; +const editPets = document.querySelector(".e-pets") as HTMLInputElement; +const editLegal = document.querySelector(".e-legal") as HTMLInputElement; +const editPolitical = document.querySelector(".e-political") as HTMLInputElement; +const editNotes = document.getElementById("e-notes") as HTMLDivElement; - del_btn.onclick = function () { - container.remove(); - } +// Create - refreshTranslation(); - }; - } +const createNameTag = document.querySelector(".c-name-tag") as HTMLInputElement; - document.getElementById("phone-add-btn")!.onclick = function () { - const phone_container = document.createElement("div"); - phone_container.className = "phone-container"; +// Accs - const subContainer = document.createElement("div"); - subContainer.className = "phone-subcontainer"; +const accNameTag = document.getElementById("acc-name-tag") as HTMLInputElement; +const accContainer = document.querySelector(".acc-container") as HTMLDivElement; +const accSearchChip = document.getElementById("acc-search-chip") as HTMLDivElement; +const accNoResults = document.getElementById("acc-no-results") as HTMLDivElement; +const accScrollBox = document.getElementById("acc-scroll-box") as HTMLDivElement; +const accAccounts = document.getElementById("accounts") as HTMLDivElement; - const phone_input = document.createElement("input"); - phone_input.className = "form-input e-phone"; - phone_input.id = "phone"; - phone_input.type = "tel"; - phone_input.placeholder = "Enter phone number"; - phone_input.spellcheck = false; - phone_input.setAttribute("lng-tag", "enter_phone_number") - //phone_input.maxLength = "15"; // FIXME some formattings can have more then 15 chars. - phone_input.required = true; +const accLoadingSpinner = document.getElementById("loading-spinner") as HTMLDivElement; - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; +async function getData(): Promise { + const res = await fetch(apiCall("/")); - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + let data = await res.json(); - phoneBase.appendChild(phone_container); - phone_container.appendChild(subContainer); - subContainer.appendChild(phone_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + return data; +} - del_btn_div.onclick = function () { - phone_container.remove(); - } +searchBar!.addEventListener("keyup", searchEntries); - refreshTranslation(); - } +document.getElementById("savemdbtn")!.onclick = async function () { + const getId = document.getElementById("v-showid") as HTMLParagraphElement; + const getName = document.getElementById("name-tag") as HTMLInputElement; - if (obj.civilstatus != "") { - const civilstatusSelect = document.querySelector(".edit-container > .components > .scroll-box > div:nth-child(7) > .civilstatus-select") as HTMLElement; - const selectItems = civilstatusSelect.querySelector(".select-items"); - const selectSelected = civilstatusSelect.querySelector(".select-selected"); + const request = await fetch(apiCall("/people/" + getId!.innerHTML + "/markdown")); + const textToSave = await request.json(); - const civilstatusIndex = getDropdownElementIndex("civilstatus", obj.civilstatus); - if (civilstatusIndex != undefined) { - const civilstatusElement = selectItems!.children[parseInt(civilstatusIndex)]; + saveAsFile(textToSave.markdown, getName!.value.toLowerCase().replace(/ /g, "") + ".md"); +} - selectSelected!.innerHTML = translateRawWord(obj.civilstatus)!; - civilstatusElement.className = "same-as-selected"; - } - } +// NEW BUTTON +document.getElementById("newbtn")!.onclick = async function () { - editKids.innerHTML = obj.kids; + const data = await getData() as object[]; - // Hobbies + let totalIds = Object.keys(data).length; + let preId = String(totalIds + 1); - const hobbyBase = document.querySelector(".e-hobby-base") as HTMLDivElement; - if (Object.keys(obj.hobbies).length >= 1) { - for (const [_, hobby] of Object.entries(obj.hobbies)) { - const hobbyVar = (hobby as { hobby: string }) + function checkId(preId: string): string { + let idExists = false; - const container = document.createElement("div"); - container.className = "hobby-container"; + for (let i = 0; i < totalIds; i++) { + if (Object.keys(data)[i] == preId) { + idExists = true; + break; + } + } - const subContainer = document.createElement("div"); - subContainer.className = "hobby-subcontainer"; + if (idExists) { + preId = String(parseInt(preId) + 1); + return checkId(preId); + } + return preId; + } - const hobby_input = document.createElement("input") as HTMLInputElement; - hobby_input.className = "form-input hobby"; - hobby_input.id = "e-hobby"; - hobby_input.placeholder = "Enter hobby"; - hobby_input.spellcheck = false; - hobby_input.setAttribute("lng-tag", "enter_hobby") - hobby_input.value = hobbyVar.hobby; + let obj = new Person(); + obj.id = checkId(preId); + obj.name = ""; + obj.accounts = {}; + obj.phone = {}; + obj.email = {}; + obj.age = 0; + obj.address = ""; + obj.bday = ""; + obj.kids = ""; + obj.Edit(); + // mainContainer.style.display = "none"; + // createContainer.style.display = "flex"; +} - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; +document.getElementById("exportbtn")!.onclick = async function () { + const data = await getData() as object[]; - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + saveAsFile(JSON.stringify(data), "data.json"); +} - container.appendChild(subContainer); - subContainer.appendChild(hobby_input); - hobbyBase.appendChild(container); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); +function createCards(obj: Person) { + let x = document.querySelector('#list-holder')!; - del_btn.onclick = function () { - container.remove(); - } + // Basic - refreshTranslation(); - }; - } + const base_div = document.createElement("div"); + base_div.className = "chip"; - document.getElementById("hobby-add-btn")!.onclick = function () { - const hobby_container = document.createElement("div"); - hobby_container.className = "hobby-container"; + const hitbox_abbr = document.createElement("abbr"); + hitbox_abbr.title = "View" + hitbox_abbr.className = "hitbox-abbr"; - const subContainer = document.createElement("div"); - subContainer.className = "hobby-subcontainer"; + const hitbox_div = document.createElement("div"); + hitbox_div.className = "hitbox"; - const hobby_input = document.createElement("input"); - hobby_input.className = "form-input e-hobby"; - hobby_input.id = "hobby"; - hobby_input.type = "text"; - hobby_input.placeholder = "Enter hobby"; - hobby_input.setAttribute("lng-tag", "enter_hobby") - hobby_input.spellcheck = false; - hobby_input.required = true; + const p_icon_div = document.createElement("div"); + p_icon_div.className = "chip-icon"; - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + const p_icon = document.createElement("ion-icon"); + p_icon.className = "icon" + p_icon.setAttribute("name", "person"); - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + const txt_div = document.createElement("div"); + txt_div.className = "text-container"; - hobbyBase.appendChild(hobby_container); - hobby_container.appendChild(subContainer); - subContainer.appendChild(hobby_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + const name_p = document.createElement("p"); + name_p.className = "card-text"; - del_btn_div.onclick = function () { - hobby_container.remove(); - } + // Edit - refreshTranslation(); - } - - editOccupation.innerHTML = obj.occupation; - editPrevOccupation.innerHTML = obj.prevoccupation; - editEducation.innerHTML = obj.education; - - if (obj.religion != "") { - const religionSelect = document.querySelector(".edit-container > .components > .scroll-box > div:nth-child(15) > .religion-select") as HTMLElement; - const selectItems = religionSelect.querySelector(".select-items") as HTMLElement; - const selectSelected = religionSelect.querySelector(".select-selected") as HTMLElement; + const e_icon_div = document.createElement("div"); + e_icon_div.className = "chip-edit"; - const religionIndex = getDropdownElementIndex("religion", obj.religion); + const e_abbr = document.createElement("abbr"); + e_abbr.title = "Edit" - if (religionIndex != undefined) { - const religionElement = selectItems.children[parseInt(religionIndex)]; + const e_icon = document.createElement("ion-icon"); + e_icon.className = "icon" + e_icon.setAttribute("name", "create-outline"); - selectSelected.innerHTML = translateRawWord(obj.religion)!; - religionElement.className = "same-as-selected"; - } - } + // Accounts - editPets.innerHTML = obj.pets; + const acc_icon_div = document.createElement("div"); + acc_icon_div.className = "chip-acc"; - // Clubs + const acc_abbr = document.createElement("abbr"); + acc_abbr.title = "Add Accounts" - const clubBase = document.querySelector(".e-club-base") as HTMLDivElement; + const acc_icon = document.createElement("ion-icon"); + acc_icon.className = "icon" + acc_icon.setAttribute("name", "person-circle-outline"); - if (Object.keys(obj.clubs).length >= 1) { - for (const [_, club] of Object.entries(obj.clubs)) { - const clubVar = (club as { club: string }) + // Delete - const container = document.createElement("div"); - container.className = "club-container"; + const d_icon_div = document.createElement("div"); + d_icon_div.className = "chip-delete"; - const subContainer = document.createElement("div"); - subContainer.className = "club-subcontainer"; + const d_abbr = document.createElement("abbr"); + d_abbr.title = "Delete" - const club_input = document.createElement("input"); - club_input.className = "form-input club"; - club_input.id = "e-club"; - club_input.type = "text"; - club_input.placeholder = "Enter club"; - club_input.spellcheck = false; - club_input.setAttribute("lng-tag", "enter_club") - club_input.value = clubVar.club; - - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + const d_icon = document.createElement("ion-icon"); + d_icon.className = "icon" + d_icon.setAttribute("name", "trash-outline"); - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + d_icon_div.onclick = function () { + fetch(apiCall("/people/" + obj.id + "/delete"), { + method: "GET", + mode: "no-cors" + }).then(function () { + location.reload(); + }); + } - container.appendChild(subContainer); - subContainer.appendChild(club_input); - clubBase.appendChild(container); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + acc_icon_div.onclick = function () { + editShowID.innerHTML = obj.id; + mainContainer.style.display = "none"; + accContainer.style.display = "flex"; + } - del_btn.onclick = function () { - container.remove(); - } + accSearchChip.onclick = search; - refreshTranslation(); - }; + accNameTag.onkeypress = function (event) { + // Check if the pressed key is the Enter key + if (event.key === "Enter") { + event.preventDefault(); + // Execute the search function + search(); } - document.getElementById("club-add-btn")!.onclick = function () { - const club_container = document.createElement("div"); - club_container.className = "club-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "club-subcontainer"; + if (event.key == " ") { + event.preventDefault(); + } + }; - const club_input = document.createElement("input"); - club_input.className = "form-input e-club"; - club_input.id = "club"; - club_input.type = "text"; - club_input.placeholder = "Enter club"; - club_input.spellcheck = false; - club_input.setAttribute("lng-tag", "enter_club") - club_input.required = true; + let isButtonEnabled = true; - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + async function search() { + if (accNameTag.value == "") { + return; + } + // Check if the button is enabled + if (!isButtonEnabled) { + return; + } - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + // Disable the button + isButtonEnabled = false; - clubBase.appendChild(club_container); - club_container.appendChild(subContainer); - subContainer.appendChild(club_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + accLoadingSpinner.style.display = "inline-block"; - del_btn_div.onclick = function () { - club_container.remove(); - } + // Set the flag to indicate that a request is in progress + const response = await fetch(apiCall('/getAccounts/' + accNameTag.value)); + const data = await response.json(); - refreshTranslation(); - } + const term_container = document.createElement("div"); + term_container.className = "term-container"; - editLegal.innerHTML = obj.legal; - editPolitical.innerHTML = obj.political; + const term_header = document.createElement("p"); + term_header.className = "term-header"; + term_header.textContent = accNameTag.value; - // Sources + term_container.appendChild(term_header); - const sourceBase = document.querySelector(".e-source-base") as HTMLDivElement; + if (data != null && Object.entries(data).length >= 1) { + accNoResults.style.display = "none"; + accScrollBox.style.display = "block"; - if (Object.keys(obj.sources).length >= 1) { - for (const [_, url] of Object.entries(obj.sources)) { - const sourceVar = (url as { url: string }) + const row_div = document.createElement("div"); + row_div.className = "acc-row"; - const container = document.createElement("div"); - container.className = "source-container"; + accAccounts.appendChild(row_div); - const subContainer = document.createElement("div"); - subContainer.className = "source-subcontainer"; - const source_input = document.createElement("input"); - source_input.className = "form-input source"; - source_input.id = "e-source"; - source_input.type = "text"; - source_input.placeholder = "Enter source"; - source_input.spellcheck = false; - source_input.setAttribute("lng-tag", "enter_source") - source_input.value = sourceVar.url; + for (const [i, _] of Object.entries(data)) { + let accObj = data[i]; - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + const manage_acc_chip = document.createElement("div"); + manage_acc_chip.className = "manage-acc-chip" - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + const outer_div = document.createElement("div"); + outer_div.className = "acc-chip"; - container.appendChild(subContainer); - subContainer.appendChild(source_input); - sourceBase.appendChild(container); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + const user_pfp = document.createElement("img"); + user_pfp.className = "userPfp"; - del_btn.onclick = function () { - container.remove(); + if (accObj.profilePicture != null) { + user_pfp.src = "data:image/png;base64," + accObj.profilePicture["1"].img; + } else { + user_pfp.src = "https://as2.ftcdn.net/v2/jpg/03/32/59/65/1000_F_332596535_lAdLhf6KzbW6PWXBWeIFTovTii1drkbT.jpg"; } - refreshTranslation(); - }; - } + const info_container = document.createElement("div"); + info_container.className = "info-container"; - document.getElementById("source-add-btn")!.onclick = function () { - const source_container = document.createElement("div"); - source_container.className = "source-container"; + const service_name = document.createElement("p"); + service_name.className = "serviceName"; + service_name.innerHTML = accObj.service; - const subContainer = document.createElement("div"); - subContainer.className = "source-subcontainer"; + const user_name = document.createElement("a"); + user_name.className = "userName"; + user_name.innerHTML = accObj.username; + user_name.href = accObj.url; + user_name.target = "_blank"; - const source_input = document.createElement("input"); - source_input.className = "form-input e-source"; - source_input.id = "source"; - source_input.type = "text"; - source_input.placeholder = "Enter source"; - source_input.spellcheck = false; - source_input.setAttribute("lng-tag", "enter_source") - source_input.required = true; + row_div.appendChild(term_container); + term_container.appendChild(manage_acc_chip); + manage_acc_chip.appendChild(outer_div); + outer_div.appendChild(user_pfp); + outer_div.appendChild(info_container); + info_container.appendChild(service_name); + info_container.appendChild(user_name); - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + if (accObj.bio != null) { + const user_bio = document.createElement("p"); + user_bio.className = "userBio"; + user_bio.innerHTML = accObj.bio["1"].bio; - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + info_container.appendChild(user_bio); + } - sourceBase.appendChild(source_container); - source_container.appendChild(subContainer); - subContainer.appendChild(source_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + const btn_container = document.createElement("div"); + btn_container.className = "manage-btn-container"; - del_btn_div.onclick = function () { - source_container.remove(); - } + const reject_btn = document.createElement("div"); + reject_btn.id = "acc-rejectbtn"; + reject_btn.className = "btn btn-secondary"; - refreshTranslation(); - } + const reject_p = document.createElement("p"); + reject_p.innerHTML = "Reject"; - editNotes.innerHTML = obj.notes; + const accept_btn = document.createElement("div"); + accept_btn.id = "acc-acceptbtn"; + accept_btn.className = "btn btn-secondary"; - // IPs + const accept_p = document.createElement("p"); + accept_p.innerHTML = "Accept"; - const ipBase = document.querySelector(".e-ip-base") as HTMLDivElement; + manage_acc_chip.appendChild(btn_container); + btn_container.appendChild(reject_btn); + btn_container.appendChild(accept_btn); + reject_btn.appendChild(reject_p); + accept_btn.appendChild(accept_p); - if (Object.keys(obj.ips).length >= 1) { - for (const [_, ip] of Object.entries(obj.ips)) { - const ipVar = (ip as { ip: string }) - const container = document.createElement("div"); - container.className = "ip-container"; - const subContainer = document.createElement("div"); - subContainer.className = "ip-subcontainer"; - const ip_input = document.createElement("input"); - ip_input.className = "form-input ip"; - ip_input.id = "e-ip"; - ip_input.type = "text"; - ip_input.placeholder = "Enter IP"; - ip_input.spellcheck = false; - ip_input.setAttribute("lng-tag", "enter_ip") - ip_input.value = ipVar.ip; + accept_btn.onclick = async function () { + // Check if accObj.service and accObj.username are also in accounts object at obj.accounts + let getId = editShowID.innerHTML - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + const res = await fetch(apiCall("/people/" + getId)); - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + let data = await res.json() as Person; - container.appendChild(subContainer); - subContainer.appendChild(ip_input); - ipBase.appendChild(container); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + data.accounts[accObj.service + "-" + accObj.username] = accObj; + fetch(apiCall("/person"), { + method: 'POST', + body: JSON.stringify(data) + }); - del_btn.onclick = function () { - container.remove(); + accept_p.innerHTML = "Accepted!"; } - refreshTranslation(); - }; - } - - document.getElementById("ip-add-btn")!.onclick = function () { - const ip_container = document.createElement("div"); - ip_container.className = "ip-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "ip-subcontainer"; - - const ip_input = document.createElement("input"); - ip_input.className = "form-input e-ip"; - ip_input.id = "ip"; - ip_input.type = "text"; - ip_input.placeholder = "Enter IP"; - ip_input.spellcheck = false; - ip_input.setAttribute("lng-tag", "enter_ip") - ip_input.required = true; + reject_btn.onclick = async function () { + let elementCount = term_container.childElementCount; - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + if (elementCount > 2) { + manage_acc_chip.remove(); + } else { + row_div.remove(); + } + } + } + } else { + // No accounts found - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + if (accAccounts.childElementCount <= 0) { + accNoResults.style.display = "flex"; + accScrollBox.style.display = "none"; + } + } - ipBase.appendChild(ip_container); - ip_container.appendChild(subContainer); - subContainer.appendChild(ip_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + accLoadingSpinner.style.display = "none"; + isButtonEnabled = true; + } - del_btn_div.onclick = function () { - ip_container.remove(); - } + base_div.appendChild(hitbox_abbr); + hitbox_abbr.appendChild(hitbox_div); + hitbox_div.appendChild(p_icon_div); + hitbox_div.appendChild(txt_div); + txt_div.appendChild(name_p); + base_div.appendChild(e_abbr); + e_abbr.appendChild(e_icon_div); + base_div.appendChild(acc_abbr); + base_div.appendChild(d_abbr); + acc_abbr.appendChild(acc_icon_div); + d_abbr.appendChild(d_icon_div); + p_icon_div.appendChild(p_icon); + e_icon_div.appendChild(e_icon); + acc_icon_div.appendChild(acc_icon); + d_icon_div.appendChild(d_icon); - refreshTranslation(); - } + name_p.innerHTML = `${obj.name}` + x.appendChild(base_div); - // Email + hitbox_div.onclick = async function () { + mainContainer.style.display = "none"; + container.style.display = "flex"; - const emailBase = document.querySelector(".email-base") as HTMLDivElement; + viewShowId.innerHTML = obj.id; - if (Object.keys(obj.email).length >= 1) { - for (const [_, email] of Object.entries(obj.email)) { - const emailVar = (email as { mail: string, services: {} }); + viewNameTag.value = obj.name; - const container = document.createElement("div"); - container.className = "email-container"; + viewGender.innerHTML = translateRawWord("Gender:")! + " " + translateRawWord(obj.gender); + viewEthnicity.innerHTML = translateRawWord("Ethnicity:")! + " " + translateRawWord(obj.ethnicity); + viewAge.innerHTML = translateRawWord("Age:")! + " " + obj.age; + viewBday.innerHTML = translateRawWord("Birthday:")! + " " + obj.bday; + viewAddress.innerHTML = translateRawWord("Address:")! + " " + obj.address; + viewCivilStatus.innerHTML = translateRawWord("Civil status:")! + " " + translateRawWord(obj.civilstatus); + viewKids.innerHTML = translateRawWord("Kids:") + " " + (obj.kids || ""); + viewOccupation.innerHTML = translateRawWord("Occupation:")! + " " + obj.occupation; + viewPrevOccupation.innerHTML = translateRawWord("Previous Occupation:")! + obj.prevoccupation; + viewEducation.innerHTML = translateRawWord("Education:")! + " " + obj.education; + viewReligion.innerHTML = translateRawWord("Religion:")! + " " + translateRawWord(obj.religion); + viewPets.innerHTML = translateRawWord("Pets:")! + " " + obj.pets; + viewLegal.innerHTML = translateRawWord("Legal:")! + " " + obj.legal; + viewPolitical.innerHTML = translateRawWord("Political:")! + " " + obj.political; + viewNotes.innerHTML = (obj.notes || ""); - const subContainer = document.createElement("div"); - subContainer.className = "email-subcontainer"; - const email_input = document.createElement("input"); - email_input.className = "form-input e-mail"; - email_input.id = "e-mail"; - email_input.type = "email"; - email_input.placeholder = "Enter email address"; - email_input.spellcheck = false; - email_input.setAttribute("lng-tag", "enter_email_address") - email_input.required = true; - email_input.value = emailVar.mail; + const allObjectsAtStart = document.querySelectorAll(".viewtag"); - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + allObjectsAtStart.forEach((object) => { + object.style.display = "flex"; + }); - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; - container.appendChild(subContainer); - subContainer.appendChild(email_input); - emailBase.appendChild(container); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + // Get all the elements with the class "viewtag" and store them in a variable called "allObjects" + let allObjects = document.getElementsByClassName("viewtag"); - if (emailVar.services != undefined && emailVar.services != null && emailVar.services != "") { - const hidden_email_save = document.createElement("p"); - hidden_email_save.className = "hidden-email-save"; + // Loop through all the objects in the array + for (let i = 0; i < allObjects.length; i++) { - hidden_email_save.innerHTML = JSON.stringify(emailVar.services); - container.appendChild(hidden_email_save); - } + // Store the current object's HTML in a variable called "item" + let item = allObjects[i] as HTMLElement; + // Get the text from the object's HTML and store it in a variable called "tempText" + let tempText = item.innerHTML.substring(item.innerHTML.indexOf(':') + 1).trim(); - del_btn.onclick = function () { - container.remove(); - } + // Check if the text is empty, null, or undefined + if (tempText.length <= 0 || tempText.replace(" ", "") == "" || tempText == null || tempText == undefined || tempText == "0") { + // Remove the object from the page + // allObjects[i].remove(); - refreshTranslation(); - }; + item.style.display = "none"; + // i--; + } } + if (viewNotes.innerHTML.length <= 0) { + document.getElementById("space-maker")!.style.display = "none"; + } + // Hobbies - document.getElementById("email-add-btn")!.onclick = function () { - const email_base = document.querySelector(".email-base"); - - const email_container = document.createElement("div"); - email_container.className = "email-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "email-subcontainer"; + const viewHobbyBase = document.querySelector(".v-hobby-base") as HTMLDivElement; + const viewHobbySpacemaker = document.querySelector(".v-hobby-space-maker") as HTMLDivElement; - const email_input = document.createElement("input"); - email_input.className = "form-input e-mail"; - email_input.id = "e-mail"; - email_input.type = "email"; - email_input.placeholder = "Enter email address"; - email_input.spellcheck = false; - email_input.setAttribute("lng-tag", "enter_email_address") - email_input.required = true; + viewHobbyBase.style.display = "block"; - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + if (Object.keys(obj.hobbies).length >= 1) { + const hobbyContainer = document.querySelector(".v-hobby-base") as HTMLDivElement; - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + for (const [_, hobby] of Object.entries(obj.hobbies)) { + const hobbyVar = (hobby as { hobby: string }) - emailBase.appendChild(email_container); - email_container.appendChild(subContainer); - subContainer.appendChild(email_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + if (hobbyVar.hobby != "" && hobbyVar.hobby != null && hobbyVar.hobby != undefined) { + viewHobbySpacemaker.style.display = "block"; + const container = document.createElement("div"); + container.className = "v-hobby-container"; - const hidden_email_save = document.createElement("p"); - hidden_email_save.className = "hidden-email-save"; - email_container.appendChild(hidden_email_save); + const subContainer = document.createElement("div"); + subContainer.className = "hobby-subcontainer"; - del_btn_div.onclick = function () { - email_container.remove(); - } + const hobby_input = document.createElement("input") as HTMLInputElement; + hobby_input.className = "form-input v-hobby"; + hobby_input.id = "v-hobby"; + hobby_input.type = "hobby"; + hobby_input.required = true; + hobby_input.value = hobbyVar.hobby; + hobby_input.disabled = true; - refreshTranslation(); + hobbyContainer.appendChild(container); + container.appendChild(subContainer); + subContainer.appendChild(hobby_input); + }; + }; + } else { + viewHobbySpacemaker.style.display = "none"; } - // Accounts - - if (obj.accounts != "{}" && obj.accounts != null) { - for (const [_, accObj] of Object.entries(obj.accounts)) { - const accVar = (accObj as { service: string, id: string, username: string, url: string, profilePicture: { [key: number]: { img: string, img_hash: number } }, bio: { [key: number]: { bio: string } } }); - - //let accObj = obj.accounts[i]; + // IPs - // Creating elements + const viewIpBase = document.querySelector(".v-ip-base") as HTMLDivElement; + const viewIpSpacemaker = document.querySelector(".v-ip-space-maker") as HTMLDivElement; - const base_div = document.createElement("div"); // Outer div - base_div.className = "acc-chip"; + viewIpBase.style.display = "block"; - const pfp_img = document.createElement("img"); // Pfp img - pfp_img.className = "userPfp"; + if (Object.keys(obj.ips).length >= 1) { + const ipContainer = document.querySelector(".v-ip-base") as HTMLDivElement; - if (accVar.profilePicture != null) { - pfp_img.src = "data:image/png;base64," + accVar.profilePicture["1"].img; - } else { - pfp_img.src = "https://as2.ftcdn.net/v2/jpg/03/32/59/65/1000_F_332596535_lAdLhf6KzbW6PWXBWeIFTovTii1drkbT.jpg" - } + for (const [_, ip] of Object.entries(obj.ips)) { + const ipVar = (ip as { ip: string }) - const info_div = document.createElement("div"); // Info div - info_div.className = "info-container"; + if (ipVar.ip != "" && ipVar.ip != null && ipVar.ip != undefined) { + viewIpSpacemaker.style.display = "block"; + const container = document.createElement("div"); + container.className = "v-ip-container"; - const icon_space = document.createElement("div"); - icon_space.className = "icon-space"; + const subContainer = document.createElement("div"); + subContainer.className = "ip-subcontainer"; - const service_p = document.createElement("a"); - service_p.className = "serviceName"; - service_p.innerHTML = accVar.service; - service_p.href = accVar.url; - service_p.target = "_blank"; + const ip_input = document.createElement("input"); + ip_input.className = "form-input v-ip"; + ip_input.id = "v-ip"; + ip_input.type = "ip"; + ip_input.spellcheck = false; + ip_input.value = ipVar.ip; + ip_input.disabled = true; - const name_p = document.createElement("a"); - name_p.className = "userName"; - name_p.innerHTML = accVar.username; - name_p.href = accVar.url; - name_p.target = "_blank"; + ipContainer.appendChild(container); + container.appendChild(subContainer); + subContainer.appendChild(ip_input); + } + }; + } else { + viewIpSpacemaker.style.display = "none"; + } - document.querySelector(".e-accounts")!.appendChild(base_div); - base_div.appendChild(pfp_img); - base_div.appendChild(info_div); - base_div.appendChild(icon_space); - info_div.appendChild(service_p); - info_div.appendChild(name_p); + // Clubs - if (accVar.service.toLowerCase() == "github") { // If the service is github, add a deep investigation button - const deep_btn = document.createElement("div"); - deep_btn.className = "deepInvBtn btn btn-secondary"; - deep_btn.id = "deepInvBtn"; + const viewClubBase = document.querySelector(".v-club-base") as HTMLDivElement; + const viewClubSpacemaker = document.querySelector(".v-club-space-maker") as HTMLDivElement; - const deep_btn_txt = document.createElement("p"); - deep_btn_txt.className = "deepInvBtnTxt"; - deep_btn_txt.innerHTML = "Deep Investigation"; + viewClubBase.style.display = "block"; - base_div.appendChild(deep_btn); - deep_btn.appendChild(deep_btn_txt); + if (Object.keys(obj.clubs).length >= 1) { + const clubContainer = document.querySelector(".v-club-base") as HTMLDivElement; - const del_btn_div = document.createElement("div"); - del_btn_div.className = "delAccBtn-deep btn btn-secondary"; + for (const [_, club] of Object.entries(obj.clubs)) { + const clubVar = (club as { club: string }) - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + if (clubVar.club != "" && clubVar.club != null && clubVar.club != undefined) { + viewClubSpacemaker.style.display = "block"; + const container = document.createElement("div"); + container.className = "v-club-container"; - base_div.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + const subContainer = document.createElement("div"); + subContainer.className = "club-subcontainer"; + const club_input = document.createElement("input"); + club_input.className = "form-input v-club"; + club_input.id = "v-club"; + club_input.type = "club"; + club_input.spellcheck = false; + club_input.value = clubVar.club; + club_input.disabled = true; - // Deep investigation - deep_btn.onclick = async function () { - if (icon_space.firstChild) { - icon_space.firstChild.remove(); - } + clubContainer.appendChild(container); + container.appendChild(subContainer); + subContainer.appendChild(club_input); + } + }; + } else { + viewClubSpacemaker.style.display = "none"; + } - deep_btn_txt.innerHTML = "This may take up to an hour..."; + // Sources - const loadingSpinner = document.createElement("div"); - loadingSpinner.className = "neu"; - loadingSpinner.id = "deepInvLoadingSpinner"; - loadingSpinner.style.display = "flex"; + const viewSourceBase = document.querySelector(".v-source-base") as HTMLDivElement; + const viewSourceSpacemaker = document.querySelector(".v-source-space-maker") as HTMLDivElement; - const loadingSpinnerShape = document.createElement("div"); - loadingSpinnerShape.className = "neu_shape"; + viewSourceBase.style.display = "block"; - const loadingSpinnerInner = document.createElement("div"); - loadingSpinnerInner.className = "neu_inner"; + if (Object.keys(obj.sources).length >= 1) { + const sourceContainer = document.querySelector(".v-source-base") as HTMLDivElement; - const loadingSpinnerBall = document.createElement("div"); - loadingSpinnerBall.className = "neu_ball"; + for (const [_, url] of Object.entries(obj.sources)) { + const sourceVar = (url as { url: string }) + if (sourceVar.url != "" && sourceVar.url != null && sourceVar.url != undefined) { + viewSourceSpacemaker.style.display = "block"; + const container = document.createElement("div"); + container.className = "v-source-container"; - icon_space.appendChild(loadingSpinner) - loadingSpinner.appendChild(loadingSpinnerShape); - loadingSpinnerShape.appendChild(loadingSpinnerInner); - loadingSpinnerInner.appendChild(loadingSpinnerBall); - loadingSpinnerInner.appendChild(loadingSpinnerBall.cloneNode()); - loadingSpinnerInner.appendChild(loadingSpinnerBall.cloneNode()); - loadingSpinnerInner.appendChild(loadingSpinnerBall.cloneNode()); + const subContainer = document.createElement("div"); + subContainer.className = "source-subcontainer"; + const source_field = document.createElement("a"); + source_field.className = "source-link v-source"; + source_field.id = "v-source"; + source_field.type = "source"; + source_field.spellcheck = false; + source_field.innerHTML = sourceVar.url; + source_field.href = sourceVar.url; + source_field.target = "_blank"; - const res = await fetch(apiCall("/deep/github/" + accVar.username)) - let data = await res.json(); + sourceContainer.appendChild(container); + container.appendChild(subContainer); + subContainer.appendChild(source_field); + } + }; + } else { + viewSourceSpacemaker.style.display = "none"; + } - loadingSpinner.remove(); + // Phone - const deepInvResIcon = document.createElement("ion-icon") as IonIconElement; - deepInvResIcon.className = "deepInvResIcon"; + const viewPhoneBase = document.querySelector(".v-phone-base") as HTMLDivElement; + const viewPhoneSpacemaker = document.querySelector(".v-phone-space-maker") as HTMLDivElement; - icon_space.appendChild(deepInvResIcon); + viewPhoneBase.style.display = "block"; - if (data != null && data != "{}" && res.status == 200) { - deep_btn_txt.innerHTML = "Deep Investigation"; + if (Object.keys(obj.phone).length >= 1) { + const phoneContainer = document.querySelector(".v-phone-base") as HTMLDivElement; - deepInvResIcon.name = "checkmark-outline"; - deepInvResIcon.style.filter = "drop-shadow(0.3rem 0.3rem 0.2rem var(--greyLight-2)) drop-shadow(-0.2rem -0.2rem 0.5rem var(--white));" + for (const [_, phone] of Object.entries(obj.phone)) { + const phoneVar = (phone as { number: string, valid: boolean, phoneinfoga: { Country: string } }) - for (const [i, _] of Object.entries(data)) { - let obj = data[i]; + if (phoneVar.number != "" && phoneVar.number != null && phoneVar.number != undefined) { + viewPhoneSpacemaker.style.display = "block"; + const container = document.createElement("div"); + container.className = "v-phone-container"; - const email_container = document.createElement("div"); - email_container.className = "email-container"; + const subContainer = document.createElement("div"); + subContainer.className = "phone-subcontainer"; - const subContainer = document.createElement("div"); - subContainer.className = "email-subcontainer"; + const phone_input = document.createElement("input"); + phone_input.className = "form-input v-phone"; + phone_input.id = "v-phone"; + phone_input.type = "phone"; + phone_input.value = phoneVar.number; + phone_input.disabled = true; - const email_input = document.createElement("input"); - email_input.className = "form-input e-mail"; - email_input.id = "e-mail"; - email_input.type = "email"; - email_input.placeholder = "Enter email address"; - email_input.spellcheck = false; - email_input.setAttribute("lng-tag", "enter_email_address") - email_input.value = obj.mail; - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; + const infoBtn = document.createElement("div"); + infoBtn.className = "v-info-btn"; - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + const icon = document.createElement("ion-icon"); + icon.setAttribute("name", "information-outline"); - const hidden_email_save = document.createElement("p"); - hidden_email_save.className = "hidden-email-save"; + container.appendChild(subContainer); + infoBtn.appendChild(icon); + subContainer.appendChild(phone_input); + subContainer.appendChild(infoBtn); + phoneContainer.appendChild(container); - hidden_email_save.innerHTML = JSON.stringify(obj.services); + infoBtn.onclick = function () { + const infoDiv = container.querySelector(".v-info-div"); - emailBase.appendChild(email_container); - email_container.appendChild(subContainer); - subContainer.appendChild(email_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); - email_container.appendChild(hidden_email_save); + if (!infoDiv) { + const infoDiv = document.createElement("div"); + infoDiv.className = "v-info-div"; - del_btn_div.onclick = function () { - email_container.remove(); - } + container.appendChild(infoDiv); + // use a function and parse the arg valid/invalid and use the literal string everywhere + if (phoneVar.valid == true) { + const abbrContainerValidity = document.createElement("abbr") + abbrContainerValidity.className = "validity-abbr"; + abbrContainerValidity.title = "Valid Phone Number"; - refreshTranslation(); - } - } else if (res.status == 403 && data["fatal"] == "rate limited") { - deepInvResIcon.name = "timer-outline"; - deepInvResIcon.style.filter = "drop-shadow(0.3rem 0.3rem 0.15rem var(--greyLight-2)) drop-shadow(-0.2rem -0.2rem 0.5rem var(--white));" - } else { - deepInvResIcon.name = "close-outline"; - deepInvResIcon.style.filter = "drop-shadow(0.3rem 0.3rem 0.2rem var(--greyLight-2)) drop-shadow(-0.2rem -0.2rem 0.5rem var(--white));" - } - } + const iconDivValid = document.createElement("div"); + iconDivValid.className = "valid-icon-div"; + const iconValid = document.createElement("img"); + iconValid.className = "valid-icon phone-icon"; + iconValid.src = "./images/valid-phone.png"; - del_btn_div.onclick = function () { - fetch(apiCall("/people/" + document.querySelector("#e-showid")!.innerHTML + "/accounts/" + accVar.service + "-" + accVar.username + "/delete"), { - method: "GET", - mode: "no-cors" - }); + infoDiv.appendChild(abbrContainerValidity); + abbrContainerValidity.appendChild(iconDivValid); + iconDivValid.appendChild(iconValid); + } else if (phoneVar.valid == false) { + const abbrContainerValidity = document.createElement("abbr") + abbrContainerValidity.className = "validity-abbr"; + abbrContainerValidity.title = "Invalid Phone Number"; - base_div.remove(); - // TODO Add stuff here - } - } else { - const del_btn_div = document.createElement("div"); - del_btn_div.className = "delAccBtn btn btn-secondary"; + const iconDivValid = document.createElement("div"); + iconDivValid.className = "valid-icon-div"; - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; + const iconValid = document.createElement("img"); + iconValid.className = "valid-icon phone-icon"; + iconValid.src = "./images/invalid-phone.png"; - base_div.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); + infoDiv.appendChild(abbrContainerValidity); + abbrContainerValidity.appendChild(iconDivValid); + iconDivValid.appendChild(iconValid); + } - del_btn_div.onclick = function () { - fetch(apiCall("/people/" + document.querySelector("#e-showid")!.innerHTML + "/accounts/" + accVar.service + "-" + accVar.username + "/delete"), { - method: "GET", - mode: "no-cors" - }); + // This should almost never fail + if (phoneVar.phoneinfoga.Country != "" && phoneVar.phoneinfoga.Country != null && phoneVar.phoneinfoga.Country != undefined) { + const abbrContainer = document.createElement("abbr") + abbrContainer.className = "phone-info-abbr"; + abbrContainer.title = phoneVar.phoneinfoga.Country; - base_div.remove(); + const iconDiv = document.createElement("div"); + iconDiv.className = "service-icon-div"; - // TODO Add stuff here + const icon = document.createElement("img"); + icon.className = "country-icon"; + icon.src = "./images/flags/" + phoneVar.phoneinfoga.Country + ".png"; + + infoDiv.appendChild(abbrContainer); + abbrContainer.appendChild(iconDiv); + iconDiv.appendChild(icon); + } + } else { + container.removeChild(infoDiv); + } } } + }; + } else { + viewPhoneSpacemaker.style.display = "none"; + } - if (accVar.bio != null) { - const bio_p = document.createElement("p"); - bio_p.className = "userBio"; - bio_p.innerHTML = accVar.bio["1"].bio; - info_div.appendChild(bio_p); - } - } - } - } -} + // Email -// CREATE + const viewEmailBase = document.querySelector(".v-email-base") as HTMLDivElement; + const viewEmailSpacemaker = document.querySelector(".v-email-space-maker") as HTMLDivElement; -const createSaveBtn = document.getElementById("c-savebtn") as HTMLDivElement; + viewEmailBase.style.display = "block"; -createSaveBtn.onclick = async function () { // new document save button - const data = await getData() as object[]; + if (Object.keys(obj.email).length >= 1) { + for (const [_, email] of Object.entries(obj.email)) { + const emailVar = (email as person.Email) - let totalIds = Object.keys(data).length; - let preId = String(totalIds + 1); + if (emailVar.mail != "" && emailVar.mail != null && emailVar.mail != undefined) { + viewEmailSpacemaker.style.display = "block"; + const container = document.createElement("div"); + container.className = "v-email-container"; - //A function to check if the data list includes that id already, if it does, it should add one until it doesnt exist - function checkId(preId: string): string { - let idExists = false; + const subContainer = document.createElement("div"); + subContainer.className = "email-subcontainer"; - for (let i = 0; i < totalIds; i++) { - if (Object.keys(data)[i] == preId) { - idExists = true; - break; - } - } + const email_input = document.createElement("input"); + email_input.className = "form-input v-mail"; + email_input.id = "v-e-mail"; + email_input.type = "email"; + email_input.required = true; + email_input.value = emailVar.mail; + email_input.disabled = true; - if (idExists) { - preId = String(parseInt(preId) + 1); - return checkId(preId); - } - return preId; - } - let id = checkId(preId); + const infoBtn = document.createElement("div"); + infoBtn.className = "v-info-btn"; + + const icon = document.createElement("ion-icon"); + icon.setAttribute("name", "information-outline"); + + container.appendChild(subContainer); + infoBtn.appendChild(icon); + subContainer.appendChild(email_input); + subContainer.appendChild(infoBtn); + viewEmailBase.appendChild(container); - let name = createNameTag.value; + infoBtn.onclick = function () { + const infoDiv = container.querySelector(".v-info-div"); - let gender = checkDropdownValue("create", "gender"); + if (!infoDiv) { + const infoDiv = document.createElement("div"); + infoDiv.className = "v-info-div"; - let ethnicity = checkDropdownValue("create", "ethnicity"); + container.appendChild(infoDiv); - let age = parseInt(document.querySelector(".c-age")!.innerHTML); + if (emailVar.valid == true) { + const abbrContainerValidity = document.createElement("abbr") + abbrContainerValidity.className = "validity-abbr"; + abbrContainerValidity.title = "Valid Email"; - if (age <= 0) { - age *= -1 - } - if (age > 120) { - age = 120 - } + const iconDivValid = document.createElement("div"); + iconDivValid.className = "valid-icon-div"; - let bday = document.querySelector(".c-bday")!.innerHTML; - let address = document.querySelector(".c-address")!.innerHTML; + const iconValid = document.createElement("img"); + iconValid.className = "valid-icon"; + iconValid.src = "./images/valid.png"; - let createPhoneContainers = document.querySelectorAll(".c-phone-container") as NodeListOf; - let phoneNumbers: {[key: string]: {number: string}} = {}; + infoDiv.appendChild(abbrContainerValidity); + abbrContainerValidity.appendChild(iconDivValid); + iconDivValid.appendChild(iconValid); + } else if (emailVar.valid == false) { + const abbrContainerValidity = document.createElement("abbr") + abbrContainerValidity.className = "validity-abbr"; + abbrContainerValidity.title = "Invalid Email"; - createPhoneContainers.forEach((container: HTMLDivElement) => { - const phoneInput: HTMLInputElement | null = container.querySelector('input[type="tel"]')!; + const iconDivValid = document.createElement("div"); + iconDivValid.className = "valid-icon-div"; - const phoneNumber: string = phoneInput.value.toString(); + const iconValid = document.createElement("img"); + iconValid.className = "valid-icon"; + iconValid.src = "./images/invalid.png"; - phoneNumbers[phoneNumber] = { - "number": phoneNumber - }; - }); + infoDiv.appendChild(abbrContainerValidity); + abbrContainerValidity.appendChild(iconDivValid); + iconDivValid.appendChild(iconValid); + } + + if (emailVar.services != undefined && emailVar.services != null) { + for (const [_, service] of Object.entries(emailVar.services)) { + const abbrContainer = document.createElement("abbr") + abbrContainer.className = "service-abbr"; + abbrContainer.title = service.name; - let civilstatus = checkDropdownValue("create", "civilstatus"); + const iconDiv = document.createElement("div"); + iconDiv.className = "service-icon-div"; - let kids = document.querySelector(".c-kids")!.innerHTML; + const icon = document.createElement("img"); + icon.className = "service-icon"; + icon.src = service.icon; - let createHobbyContainers = document.querySelectorAll(".c-hobby-container") as NodeListOf; - let hobbies: {[key: string]: {hobby: string}} = {}; - createHobbyContainers.forEach(function (container) { - let hobbyInput = container.querySelector("input")!; - hobbies[hobbyInput.value] = { - "hobby": hobbyInput.value - }; - }); + infoDiv.appendChild(abbrContainer); + abbrContainer.appendChild(iconDiv); + iconDiv.appendChild(icon); - let occupation = document.querySelector(".c-occupation")!.innerHTML; - let prevoccupation = document.querySelector(".c-prevoccupation")!.innerHTML; - let education = document.querySelector(".c-education")!.innerHTML; + iconDiv.onclick = function () { + if (service.link != "") { + window.open(service.link, "_blank"); + } + } + }; - let religion = checkDropdownValue("create", "religion"); + container.appendChild(infoDiv); + } + } else { + container.removeChild(infoDiv); + } + } + } + }; + } else { + viewEmailSpacemaker.style.display = "none"; + } - let pets = document.querySelector(".c-pets")!.innerHTML; - let editClubContainers = document.querySelectorAll(".c-club-container") as NodeListOf; - let clubs: {[key: string]: {club: string}} = {}; + // Accounts - editClubContainers.forEach(function (container) { - let clubInput = container.querySelector("input")!; - clubs[clubInput.value] = { - "club": clubInput.value - }; - }); + if (Object.keys(obj.accounts).length != 0 && obj.accounts != null) { + for (const [_, accObj] of Object.entries(obj.accounts)) { + const accVar = (accObj as { service: string, id: string, username: string, url: string, profilePicture: { [key: number]: { img: string, img_hash: number } }, bio: { [key: number]: { bio: string } } }); - let legal = document.querySelector(".c-legal")!.innerHTML; - let political = document.querySelector(".c-political")!.innerHTML; + //let accObj = obj.accounts[i]; - let editSourceContainers = document.querySelectorAll(".c-source-container") as NodeListOf; - let sources: {[key: string]: {url: string}} = {}; + // Creating elements - editSourceContainers.forEach(function (container) { - let sourceInput = container.querySelector("input")!; - sources[sourceInput.value] = { - "url": sourceInput.value - }; - }); + const base_div = document.createElement("div"); // Outer div + base_div.className = "acc-chip"; - let notes = document.querySelector(".c-notes")!.innerHTML; + const pfp_img = document.createElement("img"); // Pfp img + pfp_img.className = "userPfp"; - let createEmailContainers = document.querySelectorAll(".c-email-container") as NodeListOf; - let emailAddresses: {[key: string]: {mail: string, src: string, services: string}} = {}; + if (accVar.profilePicture != null) { + pfp_img.src = "data:image/png;base64," + accVar.profilePicture[1]!.img; + } else { + pfp_img.src = "https://as2.ftcdn.net/v2/jpg/03/32/59/65/1000_F_332596535_lAdLhf6KzbW6PWXBWeIFTovTii1drkbT.jpg" + } - createEmailContainers.forEach(function (container) { - let hiddenElement = container.querySelector(".hidden-email-save")!; - - // FIXME this is beatiful - let hiddenElementVal = null; + const info_div = document.createElement("div"); // Info div + info_div.className = "info-container"; - if (hiddenElement.innerHTML != "" && hiddenElement.innerHTML != null && hiddenElement.innerHTML != undefined) { - hiddenElementVal = JSON.parse(hiddenElement.innerHTML); - } + const service_p = document.createElement("a"); + service_p.className = "serviceName"; + service_p.innerHTML = accVar.service; + service_p.href = accVar.url; + service_p.target = "_blank"; - let emailInput = container.querySelector("input")!; - emailAddresses[emailInput.value] = { - "mail": emailInput.value, - "src": "manual", - "services": hiddenElementVal - }; - }); + const name_p = document.createElement("a"); + name_p.className = "userName"; + name_p.innerHTML = accVar.username; + name_p.href = accVar.url; + name_p.target = "_blank"; - let createIPContainers = document.querySelectorAll(".c-ip-container"); - let ips: {[key: string]: {ip: string}} = {}; - createIPContainers.forEach(function (container) { - let ipInput = container.querySelector("input")!; - ips[ipInput.value] = { - "ip": ipInput.value - }; - }); + document.querySelector(".accounts")!.appendChild(base_div); + base_div.appendChild(pfp_img); + base_div.appendChild(info_div); + info_div.appendChild(service_p); + info_div.appendChild(name_p); - const loadingSpinner = document.querySelector("#c-loading-spinner") as HTMLDivElement; - loadingSpinner.style.display = "flex" + if (accVar.bio != null) { + const bio_p = document.createElement("p"); + bio_p.className = "userBio"; + bio_p.innerHTML = accVar.bio[1].bio; - fetch(apiCall("/person"), { - method: "POST", - body: JSON.stringify({ "id": id, "name": name, "gender": gender, "ethnicity": ethnicity, "age": age, "bday": bday, "address": address, "phone": phoneNumbers, "civilstatus": civilstatus, "kids": kids, "hobbies": hobbies, "email": emailAddresses, "ips": ips, "occupation": occupation, "prevoccupation": prevoccupation, "education": education, "religion": religion, "pets": pets, "clubs": clubs, "legal": legal, "political": political, "sources": sources, "notes": notes }) - }).then(function () { - loadingSpinner.style.display = "none" - location.reload(); - }); + info_div.appendChild(bio_p); + } + } + } + } + // edit button + e_icon_div.onclick = function () { + let obj2 = new Person(obj); + obj2.Edit() + } } + const editSaveBtn = document.querySelector("#e-savebtn")! as HTMLDivElement; editSaveBtn.onclick = async function () { @@ -1844,7 +1760,7 @@ editSaveBtn.onclick = async function () { let gender = checkDropdownValue("edit", "gender"); let ethnicity = checkDropdownValue("edit", "ethnicity"); - + let age = parseInt(editAge.innerHTML); if (age < 0) { @@ -1857,7 +1773,7 @@ editSaveBtn.onclick = async function () { let bday = editBday.innerHTML; let address = editAddress.innerHTML; - let phoneNumbers: {[key: string]: {number: string}} = {}; + let phoneNumbers: { [key: string]: { number: string } } = {}; editPhoneContainers.forEach((container: HTMLDivElement) => { const phoneInput: HTMLInputElement | null = container.querySelector('input[type="tel"]')!; @@ -1873,7 +1789,7 @@ editSaveBtn.onclick = async function () { let kids = editKids.innerHTML; - let hobbies: {[key: string]: {hobby: string}} = {}; + let hobbies: { [key: string]: { hobby: string } } = {}; editHobbyContainers.forEach(function (container) { let hobbyInput = container.querySelector("input")!; @@ -1890,7 +1806,7 @@ editSaveBtn.onclick = async function () { let pets = editPets.innerHTML; - let clubs: {[key: string]: {club: string}} = {}; + let clubs: { [key: string]: { club: string } } = {}; editClubContainers.forEach(function (container) { let clubInput = container.querySelector("input")!; @@ -1902,7 +1818,7 @@ editSaveBtn.onclick = async function () { let legal = editLegal.innerHTML; let political = editPolitical.innerHTML; - let sources: {[key: string]: {url: string}} = {}; + let sources: { [key: string]: { url: string } } = {}; editSourceContainers.forEach(function (container) { let sourceInput = container.querySelector("input")!; @@ -1913,12 +1829,12 @@ editSaveBtn.onclick = async function () { let notes = editNotes.innerHTML; - let emailAddresses: {[key: string]: {mail: string, src: string, services: string}} = {}; + let emailAddresses: { [key: string]: { mail: string, src: string, services: string } } = {}; editEmailContainers.forEach(function (container) { let hiddenElement = container.querySelector(".hidden-email-save")!; - - // FIXME this is beatiful + + // FIXME this is beautiful let hiddenElementVal = null; if (hiddenElement.innerHTML != "" && hiddenElement.innerHTML != null && hiddenElement.innerHTML != undefined) { @@ -1932,8 +1848,8 @@ editSaveBtn.onclick = async function () { "services": hiddenElementVal }; }); - - let ips: {[key: string]: {ip: string}} = {}; + + let ips: { [key: string]: { ip: string } } = {}; editIPContainers.forEach(function (container) { let ipInput = container.querySelector("input")!; @@ -1941,21 +1857,47 @@ editSaveBtn.onclick = async function () { "ip": ipInput.value }; }); - + const loadingSpinner = document.querySelector("#e-loading-spinner")! as HTMLDivElement; loadingSpinner.style.display = "flex" const res = await fetch(apiCall("/people/" + id)) - let data = await res.json(); + let data = await res.json() as Person; + let obj = new Person(); + + if (data == null) { + obj.accounts = {}; + } else { + obj.accounts = data.accounts; + } + + obj.id = id; + obj.name = name; + obj.gender = gender || ''; + obj.ethnicity = ethnicity || ''; + obj.age = age; + obj.bday = bday; + obj.address = address; + obj.phone = phoneNumbers as { [key: string]: person.PhoneNumber }; + obj.civilstatus = civilstatus || ''; + obj.kids = kids; + obj.hobbies = hobbies; + obj.email = emailAddresses as unknown as { [key: string]: person.Email }; + obj.ips = ips; + obj.occupation = occupation; + obj.prevoccupation = prevoccupation; + obj.education = education; + obj.religion = religion || ''; + obj.pets = pets; + obj.clubs = clubs; + obj.legal = legal; + obj.political = political; + obj.sources = sources; + obj.notes = notes; + + obj.Post(loadingSpinner); - fetch(apiCall("/person"), { - method: "POST", - body: JSON.stringify({ "id": id, "name": name, "gender": gender, "ethnicity": ethnicity, "age": age, "bday": bday, "address": address, "phone": phoneNumbers, "civilstatus": civilstatus, "kids": kids, "hobbies": hobbies, "email": emailAddresses, "ips": ips, "occupation": occupation, "prevoccupation": prevoccupation, "education": education, "religion": religion, "pets": pets, "clubs": clubs, "legal": legal, "political": political, "sources": sources, "notes": notes, "accounts": data.accounts }) - }).then(function () { - loadingSpinner.style.display = "none" - location.reload(); - }); } document.getElementById("backbtn")!.onclick = function () { @@ -2027,290 +1969,10 @@ document.getElementById("e-backbtn")!.onclick = function () { parentElement.innerHTML = ""; } -document.getElementById("c-backbtn")!.onclick = function () { - mainContainer.style.display = "flex"; - createContainer.style.display = "none"; -} - document.getElementById("acc-backbtn")!.onclick = function () { // account back button location.reload(); } -// Clubs - -document.getElementById("c-club-add-btn")!.onclick = function () { - const club_base = document.querySelector(".c-club-base") as HTMLDivElement; - - const club_container = document.createElement("div"); - club_container.className = "c-club-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "club-subcontainer"; - - const club_input = document.createElement("input"); - club_input.className = "form-input e-club"; - club_input.id = "club"; - club_input.type = "text"; - club_input.placeholder = "Enter club"; - club_input.spellcheck = false; - club_input.setAttribute("lng-tag", "enter_club") - - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; - - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; - - club_base.appendChild(club_container); - club_container.appendChild(subContainer); - subContainer.appendChild(club_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); - - del_btn_div.onclick = function () { - club_container.remove(); - } - - refreshTranslation(); -} - -// Sources - -document.getElementById("c-source-add-btn")!.onclick = function () { - const source_base = document.querySelector(".c-source-base") as HTMLDivElement; - - const source_container = document.createElement("div"); - source_container.className = "c-source-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "source-subcontainer"; - - const source_input = document.createElement("input"); - source_input.className = "form-input e-source"; - source_input.id = "source"; - source_input.type = "text"; - source_input.placeholder = "Enter source"; - source_input.spellcheck = false; - source_input.setAttribute("lng-tag", "enter_source") - - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; - - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; - - source_base.appendChild(source_container); - source_container.appendChild(subContainer); - subContainer.appendChild(source_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); - - del_btn_div.onclick = function () { - source_container.remove(); - } - - refreshTranslation(); -} - -// IPs - -document.getElementById("c-ip-add-btn")!.onclick = function () { - const ip_base = document.querySelector(".c-ip-base") as HTMLDivElement; - - const ip_container = document.createElement("div"); - ip_container.className = "c-ip-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "ip-subcontainer"; - - const ip_input = document.createElement("input"); - ip_input.className = "form-input e-ip"; - ip_input.id = "ip"; - ip_input.type = "text"; - ip_input.placeholder = "Enter IP"; - ip_input.spellcheck = false; - ip_input.setAttribute("lng-tag", "enter_ip") - - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; - - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; - - ip_base.appendChild(ip_container); - ip_container.appendChild(subContainer); - subContainer.appendChild(ip_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); - - del_btn_div.onclick = function () { - ip_container.remove(); - } - - refreshTranslation(); -} - -// Phone - -document.getElementById("c-phone-add-btn")!.onclick = function () { - const phone_base = document.querySelector(".c-phone-base") as HTMLDivElement; - - const phone_container = document.createElement("div"); - phone_container.className = "c-phone-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "phone-subcontainer"; - - const phone_input = document.createElement("input"); - phone_input.className = "form-input e-phone"; - phone_input.id = "phone"; - phone_input.type = "tel"; - phone_input.placeholder = "Enter phone number"; - phone_input.spellcheck = false; - phone_input.setAttribute("lng-tag", "enter_phone_number") - - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; - - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; - - phone_base.appendChild(phone_container); - phone_container.appendChild(subContainer); - subContainer.appendChild(phone_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); - - del_btn_div.onclick = function () { - phone_container.remove(); - } - - refreshTranslation(); -} - -// Hobbies - -document.getElementById("c-hobby-add-btn")!.onclick = function () { - const hobby_base = document.querySelector(".c-hobby-base") as HTMLDivElement; - - const hobby_container = document.createElement("div"); - hobby_container.className = "c-hobby-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "hobby-subcontainer"; - - const hobby_input = document.createElement("input"); - hobby_input.className = "form-input e-hobby"; - hobby_input.id = "hobby"; - hobby_input.type = "tel"; - hobby_input.placeholder = "Enter hobby"; - hobby_input.spellcheck = false; - hobby_input.setAttribute("lng-tag", "enter_hobby") - - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; - - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; - - hobby_base.appendChild(hobby_container); - hobby_container.appendChild(subContainer); - subContainer.appendChild(hobby_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); - - del_btn_div.onclick = function () { - hobby_container.remove(); - } - - refreshTranslation(); -} - -// IPs - -document.getElementById("c-ip-add-btn")!.onclick = function () { - const ip_base = document.querySelector(".c-ip-base") as HTMLDivElement; - - const ip_container = document.createElement("div"); - ip_container.className = "c-ip-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "ip-subcontainer"; - - const ip_input = document.createElement("input"); - ip_input.className = "form-input e-ip"; - ip_input.id = "ip"; - ip_input.type = "tel"; - ip_input.placeholder = "Enter IP"; - ip_input.spellcheck = false; - ip_input.setAttribute("lng-tag", "enter_ip") - - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; - - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; - - ip_base.appendChild(ip_container); - ip_container.appendChild(subContainer); - subContainer.appendChild(ip_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); - - del_btn_div.onclick = function () { - ip_container.remove(); - } - - refreshTranslation(); -} - -// Email - -document.getElementById("c-add-btn")!.onclick = function () { - const email_base = document.querySelector(".c-email-base") as HTMLDivElement; - - const email_container = document.createElement("div"); - email_container.className = "c-email-container"; - - const subContainer = document.createElement("div"); - subContainer.className = "c-email-subcontainer"; - - const email_input = document.createElement("input"); - email_input.className = "form-input e-mail"; - email_input.id = "c-e-mail"; - email_input.type = "email"; - email_input.placeholder = "Enter email address"; - email_input.spellcheck = false; - email_input.setAttribute("lng-tag", "enter_email_address") - - const del_btn_div = document.createElement("div"); - del_btn_div.className = "del-btn"; - - const del_btn = document.createElement("ion-icon") as IonIconElement; - del_btn.name = "remove-outline"; - - email_base.appendChild(email_container); - email_container.appendChild(email_input); - email_container.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); - - const hidden_email_save = document.createElement("p"); - hidden_email_save.className = "hidden-email-save"; - email_container.appendChild(hidden_email_save); - - del_btn_div.onclick = function () { - email_container.remove(); - } - - email_container.appendChild(subContainer); - subContainer.appendChild(email_input); - subContainer.appendChild(del_btn_div); - del_btn_div.appendChild(del_btn); - - refreshTranslation(); -} - - runOnStart(); @@ -2327,9 +1989,9 @@ async function runOnStart() { exportBtn.style.display = "none"; } else { for (const [i, _] of Object.entries(data)) { - let obj = data[Number(i)] as any; - //let obj = data[Number(i)] as person.Person; - + //let obj = data[Number(i)] as any; + let obj = data[Number(i)] as Person; + createCards(obj); } } @@ -2381,5 +2043,4 @@ async function searchEntries() { } } - export { }; diff --git a/web/ts/theme_loader.ts b/web/ts/theme_loader.ts index 6465aea9..f93b2e88 100644 --- a/web/ts/theme_loader.ts +++ b/web/ts/theme_loader.ts @@ -12,8 +12,6 @@ function setDefaultIfNotStored(): void { localStorage.setItem("theme", defaultTheme); changeTheme(defaultTheme); - - console.log(localStorage.getItem("theme")); } }