skin_set_do.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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') === '0') {
  22. } else {
  23. document.getElementById('ringo_add_style').innerHTML += `
  24. section {
  25. width: auto !important;
  26. display: block !important;
  27. margin: auto !important;
  28. }
  29. .do_fixed {
  30. display: none !important;
  31. }
  32. `;
  33. }
  34. if(window.localStorage.getItem('main_css_fixed_width') && window.localStorage.getItem('main_css_fixed_width') !== '') {
  35. let fixed_width_data = window.localStorage.getItem('main_css_fixed_width');
  36. document.getElementById('ringo_add_style').innerHTML += `
  37. article.main {
  38. max-width: ` + fixed_width_data + `px !important;
  39. }
  40. `;
  41. }
  42. if(window.localStorage.getItem('main_css_sidebar_right') && window.localStorage.getItem('main_css_sidebar_right') === '1') {
  43. document.getElementById('ringo_add_style').innerHTML += `
  44. .do_fixed {
  45. float: right !important;
  46. }
  47. `;
  48. }
  49. }
  50. ringo_do_skin_set();