common.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. bodyElem = document.getElementsByTagName('body')[0]
  2. if (!localStorage.getItem('theme')) {
  3. bodyElem.classList.forEach(function (klass) {
  4. if (klass.startsWith('mdui-theme-layout-'))
  5. localStorage.setItem('theme', klass.slice(18))
  6. })
  7. }
  8. if (!localStorage.getItem('color')) {
  9. bodyElem.classList.forEach(function (klass) {
  10. if (klass.startsWith('mdui-theme-primary-'))
  11. localStorage.setItem('color', klass.slice(19))
  12. })
  13. }
  14. if (!localStorage.getItem('quality'))
  15. localStorage.setItem('quality', '32')
  16. document.querySelectorAll('.js-only').forEach(x => x.classList.toggle('mdui-hidden'))
  17. document.querySelectorAll('.nojs-only').forEach(x => x.classList.add('mdui-hidden'))
  18. window.qnc = function (quality) {
  19. document.querySelector(`[href="javascript:qnc(${localStorage.getItem('quality')});"]`)
  20. .classList.remove('mdui-color-theme')
  21. localStorage.setItem('quality', quality)
  22. document.querySelector(`[href="javascript:qnc(${quality});"]`)
  23. .classList.add('mdui-color-theme')
  24. }
  25. bodyElem.className = `mdui-theme-layout-${localStorage.getItem('theme')}`
  26. + ` mdui-theme-primary-${localStorage.getItem('color')}`
  27. + ` mdui-theme-accent-${localStorage.getItem('color')}`
  28. window.addEventListener('load', function() {
  29. document.querySelector(`[value="${localStorage.getItem('color')}"]`)
  30. .setAttribute('checked', '')
  31. document.querySelector(`[value="${localStorage.getItem('theme')}"]`)
  32. .setAttribute('checked', '')
  33. tf = document.getElementById('theme-sel')
  34. for (let inpa of tf['elements']['theme-layout']) {
  35. inpa.onclick = function () {
  36. newTheme = tf['elements']['theme-layout'].value
  37. bodyElem.classList.remove(`mdui-theme-layout-${localStorage.getItem('theme')}`)
  38. bodyElem.classList.add(`mdui-theme-layout-${newTheme}`)
  39. localStorage.setItem('theme', newTheme)
  40. }
  41. }
  42. cf = document.getElementById('color-sel')
  43. for (let inpa of cf['elements']['theme-primary']) {
  44. inpa.onclick = function () {
  45. newColor = cf['elements']['theme-primary'].value
  46. bodyElem.classList.remove(`mdui-theme-accent-${localStorage.getItem('color')}`)
  47. bodyElem.classList.remove(`mdui-theme-primary-${localStorage.getItem('color')}`)
  48. bodyElem.classList.add(`mdui-theme-accent-${newColor}`)
  49. bodyElem.classList.add(`mdui-theme-primary-${newColor}`)
  50. localStorage.setItem('color', newColor)
  51. }
  52. }
  53. document.querySelector(`[href="javascript:qnc(${localStorage.getItem('quality')});"]`)
  54. .classList.add('mdui-color-theme')
  55. }, false)