Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

extra.js 6.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  1. // Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
  2. // Apply theme colors based on dark/light mode
  3. const applyTheme = (isDark) => {
  4. document.body.setAttribute(
  5. "data-md-color-scheme",
  6. isDark ? "slate" : "default",
  7. );
  8. document.body.setAttribute(
  9. "data-md-color-primary",
  10. isDark ? "black" : "indigo",
  11. );
  12. };
  13. // Check and apply appropriate theme based on system/user preference
  14. const checkTheme = () => {
  15. const palette = JSON.parse(localStorage.getItem(".__palette") || "{}");
  16. if (palette.index === 0) {
  17. // Auto mode is selected
  18. applyTheme(window.matchMedia("(prefers-color-scheme: dark)").matches);
  19. }
  20. };
  21. // Watch for system theme changes
  22. window
  23. .matchMedia("(prefers-color-scheme: dark)")
  24. .addEventListener("change", checkTheme);
  25. // Initialize theme handling on page load
  26. document.addEventListener("DOMContentLoaded", () => {
  27. // Watch for theme toggle changes
  28. document
  29. .getElementById("__palette_1")
  30. ?.addEventListener(
  31. "change",
  32. (e) => e.target.checked && setTimeout(checkTheme),
  33. );
  34. // Initial theme check
  35. checkTheme();
  36. });
  37. // Inkeep --------------------------------------------------------------------------------------------------------------
  38. document.addEventListener("DOMContentLoaded", () => {
  39. const enableSearchBar = true;
  40. const inkeepScript = document.createElement("script");
  41. inkeepScript.src =
  42. "https://cdn.jsdelivr.net/npm/@inkeep/cxkit-js@0.5/dist/embed.js";
  43. inkeepScript.type = "module";
  44. inkeepScript.defer = true;
  45. document.head.appendChild(inkeepScript);
  46. if (enableSearchBar) {
  47. const containerDiv = document.createElement("div");
  48. containerDiv.style.transform = "scale(0.7)";
  49. containerDiv.style.transformOrigin = "left center";
  50. const inkeepDiv = document.createElement("div");
  51. inkeepDiv.id = "inkeepSearchBar";
  52. containerDiv.appendChild(inkeepDiv);
  53. const headerElement = document.querySelector(".md-header__inner");
  54. const searchContainer = headerElement.querySelector(".md-header__source");
  55. if (headerElement && searchContainer) {
  56. headerElement.insertBefore(containerDiv, searchContainer);
  57. }
  58. }
  59. // Configuration object for Inkeep
  60. const config = {
  61. baseSettings: {
  62. apiKey: "13dfec2e75982bc9bae3199a08e13b86b5fbacd64e9b2f89",
  63. primaryBrandColor: "#E1FF25",
  64. organizationDisplayName: "Ultralytics",
  65. colorMode: {
  66. enableSystem: true,
  67. },
  68. theme: {
  69. styles: [
  70. {
  71. key: "main",
  72. type: "link",
  73. value: "/stylesheets/style.css",
  74. },
  75. {
  76. key: "chat-button",
  77. type: "style",
  78. value: `
  79. /* Light mode styling */
  80. .ikp-chat-button__button {
  81. background-color: #E1FF25;
  82. color: #111F68;
  83. }
  84. /* Dark mode styling */
  85. [data-theme="dark"] .ikp-chat-button__button {
  86. background-color: #40434f;
  87. color: #ffffff;
  88. }
  89. .ikp-chat-button__container {
  90. position: fixed;
  91. right: 1rem;
  92. bottom: 3rem;
  93. }
  94. `,
  95. },
  96. ],
  97. },
  98. },
  99. searchSettings: {
  100. placeholder: "Search",
  101. },
  102. aiChatSettings: {
  103. chatSubjectName: "Ultralytics",
  104. aiAssistantAvatar:
  105. "https://storage.googleapis.com/organization-image-assets/ultralytics-botAvatarSrcUrl-1729379860806.svg",
  106. exampleQuestions: [
  107. "What's new in Ultralytics YOLO11?",
  108. "How can I get started with Ultralytics HUB?",
  109. "How does Ultralytics Enterprise Licensing work?",
  110. ],
  111. getHelpOptions: [
  112. {
  113. name: "Ask on Ultralytics GitHub",
  114. icon: {
  115. builtIn: "FaGithub",
  116. },
  117. action: {
  118. type: "open_link",
  119. url: "https://github.com/ultralytics/ultralytics",
  120. },
  121. },
  122. {
  123. name: "Ask on Ultralytics Discourse",
  124. icon: {
  125. builtIn: "FaDiscourse",
  126. },
  127. action: {
  128. type: "open_link",
  129. url: "https://community.ultralytics.com/",
  130. },
  131. },
  132. {
  133. name: "Ask on Ultralytics Discord",
  134. icon: {
  135. builtIn: "FaDiscord",
  136. },
  137. action: {
  138. type: "open_link",
  139. url: "https://discord.com/invite/ultralytics",
  140. },
  141. },
  142. ],
  143. },
  144. };
  145. // Initialize Inkeep widgets when script loads
  146. inkeepScript.addEventListener("load", () => {
  147. const widgetContainer = document.getElementById("inkeepSearchBar");
  148. Inkeep.ChatButton(config);
  149. widgetContainer && Inkeep.SearchBar("#inkeepSearchBar", config);
  150. });
  151. });
  152. // Fix language switcher links
  153. (function () {
  154. function fixLanguageLinks() {
  155. const path = location.pathname;
  156. const links = document.querySelectorAll(".md-select__link");
  157. if (!links.length) return;
  158. const langs = [];
  159. let defaultLink = null;
  160. // Extract language codes
  161. links.forEach((link) => {
  162. const href = link.getAttribute("href");
  163. if (!href) return;
  164. const url = new URL(href, location.origin);
  165. const match = url.pathname.match(/^\/([a-z]{2})\/?$/);
  166. if (match) langs.push({ code: match[1], link });
  167. else if (url.pathname === "/" || url.pathname === "") defaultLink = link;
  168. });
  169. // Find current language and base path
  170. let basePath = path;
  171. for (const lang of langs) {
  172. if (path.startsWith("/" + lang.code + "/")) {
  173. basePath = path.substring(lang.code.length + 1);
  174. break;
  175. }
  176. }
  177. // Update links
  178. langs.forEach(
  179. (lang) => (lang.link.href = location.origin + "/" + lang.code + basePath),
  180. );
  181. if (defaultLink) defaultLink.href = location.origin + basePath;
  182. }
  183. // Run immediately
  184. fixLanguageLinks();
  185. // Handle SPA navigation
  186. if (typeof document$ !== "undefined") {
  187. document$.subscribe(() => setTimeout(fixLanguageLinks, 50));
  188. } else {
  189. let lastPath = location.pathname;
  190. setInterval(() => {
  191. if (location.pathname !== lastPath) {
  192. lastPath = location.pathname;
  193. setTimeout(fixLanguageLinks, 50);
  194. }
  195. }, 200);
  196. }
  197. })();
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...