Skip to content

Commit 53d27a7

Browse files
committed
Refactor dark mode attribute handling
1 parent 2db8fb4 commit 53d27a7

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

js/script.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ customElements.define('upvote-rss', class extends HTMLElement {
88
'average-posts-per-day', 'comments', 'threshold-percentage', 'post-cutoff-days', 'score', 'score-default-hacker-news', 'score-default-lemmy', 'score-default-lobsters', 'score-default-mbin', 'score-default-piefed', 'score-default-reddit'
99
]);
1010

11+
// Constructor
12+
constructor () {
13+
super();
14+
15+
// Set initial attributes
16+
this.setAttribute('dark-mode', localStorage.getItem('dark-mode') || this.attr('dark-mode') || 'auto');
17+
this.setAttribute('show-rss-url', navigator.clipboard ? false : true);
18+
}
19+
1120

1221
/**
1322
* Called when the element is added to the DOM
@@ -36,16 +45,9 @@ customElements.define('upvote-rss', class extends HTMLElement {
3645
this.allowSkeletons = false;
3746
this.skeletonDelay = 150;
3847

39-
// Get dark mode preference
40-
this.getDarkMode();
41-
4248
// Initial data fetching
4349
this.debouncedSearch();
4450

45-
// Set initial attributes
46-
this.setAttribute('dark-mode', localStorage.getItem('dark-mode') || 'auto');
47-
this.setAttribute('show-rss-url', navigator.clipboard ? false : true);
48-
4951
// Set up event listeners
5052
this.setupEventListeners();
5153
}
@@ -698,19 +700,6 @@ customElements.define('upvote-rss', class extends HTMLElement {
698700
}
699701

700702

701-
/**
702-
* Get the dark mode setting from local storage and apply it
703-
* @returns {void}
704-
* */
705-
getDarkMode () {
706-
const darkMode = localStorage.getItem('dark-mode');
707-
if (darkMode) {
708-
this.setAttribute('dark-mode', darkMode);
709-
}
710-
document.documentElement.dataset.colorScheme = this.attr('dark-mode');
711-
}
712-
713-
714703
/**
715704
* Perform a debounced search to get posts
716705
* @param {number} delay - The delay in milliseconds

views/html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
post-cutoff-days='<?php echo POST_CUTOFF_DAYS; ?>'
108108
cache-size='<?php $cache_size = cache()->getTotalCacheSize(); echo $cache_size; ?>'
109109
show-rss-url='true'
110-
dark-mode='true'
110+
dark-mode=''
111111
>
112112

113113
<div class="columns">

0 commit comments

Comments
 (0)