# هل هناك طريقة للكشف عن استخدام الوضع المظلم؟

**URL:** https://meta.discourse.org/t/is-there-a-way-to-detect-dark-mode-usage/261821
**Category:** Development
**Created:** [16 أبريل 2023، 2:45ص UTC](https://meta.discourse.org/t/is-there-a-way-to-detect-dark-mode-usage/261821 "2023-04-16T02:45:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ti0](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ti0/32/184402_2.png) [@ti0](https://meta.discourse.org/u/ti0)
#### Post date: [16 أبريل 2023، 2:45ص UTC](https://meta.discourse.org/t/is-there-a-way-to-detect-dark-mode-usage/261821/1 "2023-04-16T02:45:02Z")

</div>

هل هناك طريقة في مكون إضافي / مكون سمة للكشف عما إذا كانت السمة الحالية تستخدم الوضع المظلم؟  
بدلاً من ذلك ، هل هناك طريقة للحصول على معرف السمة النشط؟  
أم يجب علينا إنشاء مكونات سمة مختلفة للسمات الفاتحة والسمات الداكنة؟

---

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [16 أبريل 2023، 10:39ص UTC](https://meta.discourse.org/t/is-there-a-way-to-detect-dark-mode-usage/261821/2 "2023-04-16T10:39:50Z")

</div>

> [@ti0](#):
>
> اكتشاف ما إذا كان المظهر الحالي يستخدم الوضع المظلم

مرحباً،

أعتقد أن هناك عدة طرق لتحقيق ذلك.

يمكنك استخدام هذا

> [@No specific class for dark mode](https://meta.discourse.org/t/no-specific-class-for-dark-mode/254984/2?u=dodesz):
>
> Would this accomplish what you need? this would need to be added to color\_definitions.scss @if #{schemeType()} == dark { body { background: red; } } @else { body { background: blue; } } A class does seem like it would be useful though, we can probably add one.

أو هذا

> [@Why might dark-light-choose() not work?](https://meta.discourse.org/t/why-might-dark-light-choose-not-work/172232/2?u=dodesz):
>
> I believe, due to the way the SCSS is compiled, custom dark/light definitions need to be added to color\_definitions.scss within a theme and won’t work in other scss files. color\_definitions.scss is high up in the cascade (before a lot of the default styles), so you don’t want to add the .modal.history-modal ins part there. Instead you can just add the color definition itself… $dark-theme-ins: #acf2bd; $light-theme-ins: #4da06d; $ins: dark-light-choose(…

* * *

أحب قسم **المواضيع ذات الصلة** في Discourse Ai 😃 يسهل تنظيمه والعثور على المواضيع.

 ![Screenshot_20230416_122730](https://global.discourse-cdn.com/meta/original/4X/7/e/a/7ea6da30d8a6bd1d5d5428808b5063ceab021e37.jpeg)

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [16 أبريل 2023، 12:02م UTC](https://meta.discourse.org/t/is-there-a-way-to-detect-dark-mode-usage/261821/3 "2023-04-16T12:02:49Z")

</div>

شخصيًا، أفضل وجود سمات داكنة وفاتحة منفصلة، بدلاً من أوضاع داكنة وفاتحة للسمة. أعتقد أن بعض المستخدمين يجدون تلك القائمة المنسدلة الإضافية مربكة. أنا فقط أقوم بإنشاء إصدارات فاتحة وداكنة للسمات وأضعها في قائمة الهامبرغر، ولكن لدي فقط 4 سمات نشطة (لقد قمت بعمل سمات محدودة الوقت للمناسبات الخاصة، على سبيل المثال، كانت لدينا سمات فاتحة وداكنة لبطولة Masters Golf). فقط يجب تتبع لوحات الألوان.

---

<div class="post-metadata">

### Author: ![ti0](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ti0/32/184402_2.png) [@ti0](https://meta.discourse.org/u/ti0)
#### Post date: [16 أبريل 2023، 12:24م UTC](https://meta.discourse.org/t/is-there-a-way-to-detect-dark-mode-usage/261821/4 "2023-04-16T12:24:29Z")

</div>

لقد قمت بحل هذا عن طريق إضافة سطر واحد من التعليمات البرمجية إلى قسم الرأس (Head) لكل سمة اعتمادًا على الألوان:

> document.body.classList.add(“dark-theme”);

> document.body.classList.add(“light-theme”);

شكراً لمدخلاتكم @Don @Lilly

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [16 مايو 2023، 12:24م UTC](https://meta.discourse.org/t/is-there-a-way-to-detect-dark-mode-usage/261821/5 "2023-05-16T12:24:34Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
