An IndieWeb engine for a self-hostable website. https://koype.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.ts 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @license
  3. * Koype: a IndieWeb-focused, single-tenant website engine for people.
  4. *
  5. * Copyright © 2019 Jacky Alciné <jacky.is@black.af>
  6. *
  7. * This file belongs to the Koype project.
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. import renderQRCode from './lib/qrcode'
  23. window.addEventListener('load', function startSettingsPage () {
  24. const componentElem: HTMLInputElement = document.querySelector('input[name=component]')
  25. switch (componentElem.getAttribute('value')) {
  26. case 'endpoints':
  27. setupEndpointPage()
  28. break
  29. case 'totp':
  30. renderQrCode()
  31. break
  32. default: break
  33. }
  34. function renderQrCode () {
  35. renderQRCode(document.querySelector('#qrCode'), document.querySelector('#totpSecret').getAttribute('value'))
  36. }
  37. function setupEndpointPage () {
  38. function setUpToggle (checkBoxSelector, inputSelector) {
  39. const checkbox: HTMLInputElement = document.querySelector(checkBoxSelector)
  40. checkbox.addEventListener('change', () => {
  41. const inputElem = document.querySelector(inputSelector)
  42. inputElem.toggleAttribute('readonly', checkbox.checked)
  43. inputElem.toggleAttribute('disabled', checkbox.checked)
  44. })
  45. }
  46. const toggleFields = [
  47. {
  48. checkbox: "input[name='inbuilt[indieauth.auth]']",
  49. elem: 'input#endpoint-indieauth-auth'
  50. }
  51. ]
  52. toggleFields.forEach((field) => {
  53. setUpToggle(field.checkbox, field.elem)
  54. })
  55. }
  56. })