skin_set_do.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. function ringo_do_regex_data(data) {
  2. return new RegExp('(?:^|; )' + data + '=([^;]*)');
  3. }
  4. function ringo_do_skin_set() {
  5. let cookies = document.cookie;
  6. if(!window.localStorage.getItem('main_css_use_sys_darkmode') || window.localStorage.getItem('main_css_use_sys_darkmode') === '1') {
  7. if(cookies.match(ringo_do_regex_data('main_css_darkmode')) && cookies.match(ringo_do_regex_data('main_css_darkmode'))[1] === '1') {
  8. if(!window.matchMedia('(prefers-color-scheme: dark)').matches) {
  9. document.cookie = 'main_css_darkmode=0; path=/';
  10. history.go(0);
  11. }
  12. }
  13. if(!cookies.match(ringo_do_regex_data('main_css_darkmode')) || cookies.match(ringo_do_regex_data('main_css_darkmode'))[1] === '0') {
  14. if(window.matchMedia('(prefers-color-scheme: dark)').matches) {
  15. document.cookie = 'main_css_darkmode=1; path=/';
  16. history.go(0);
  17. }
  18. }
  19. }
  20. if(window.localStorage.getItem('main_css_off_sidebar') && window.localStorage.getItem('main_css_off_sidebar') === '1') {
  21. document.getElementById('ringo_add_style').innerHTML += `
  22. section {
  23. width: auto;
  24. display: block;
  25. margin: auto;
  26. }
  27. .do_fixed {
  28. display: none;
  29. }
  30. `;
  31. }
  32. if(window.localStorage.getItem('main_css_fixed_width') && window.localStorage.getItem('main_css_fixed_width') !== '') {
  33. let fixed_width_data = window.localStorage.getItem('main_css_fixed_width');
  34. document.getElementById('ringo_add_style').innerHTML += `
  35. article.main {
  36. max-width: ` + fixed_width_data + `px;
  37. }
  38. `;
  39. }
  40. if(window.localStorage.getItem('main_css_sidebar_right') && window.localStorage.getItem('main_css_sidebar_right') === '1') {
  41. document.getElementById('ringo_add_style').innerHTML += `
  42. .do_fixed {
  43. float: right;
  44. }
  45. `;
  46. }
  47. }
  48. ringo_do_skin_set();