2
0

skin_set_do.js 2.1 KB

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