MCPcopy Index your code
hub / github.com/darkreader/darkreader / getRulesAsync

Function getRulesAsync

src/inject/dynamic-theme/style-manager.ts:258–324  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

256 const loadingLinkId = ++loadingLinkCounter;
257
258 async function getRulesAsync(): Promise<CSSRuleList | null> {
259 let cssText: string;
260 let cssBasePath: string;
261
262 if (element instanceof HTMLLinkElement) {
263 let [cssRules, accessError] = getRulesOrError();
264 if (accessError) {
265 logWarn(accessError);
266 }
267
268 if (
269 (isSafari && !element.sheet) ||
270 (!isSafari && !cssRules && !accessError) ||
271 isStillLoadingError(accessError!)
272 ) {
273 try {
274 logInfo(`Linkelement ${loadingLinkId} is not loaded yet and thus will be await for`, element);
275 await linkLoading(element, loadingLinkId);
276 } catch (err) {
277 // NOTE: Some @import resources can fail,
278 // but the style sheet can still be valid.
279 // There's no way to get the actual error.
280 logWarn(err);
281 wasLoadingError = true;
282 }
283 if (cancelAsyncOperations) {
284 return null;
285 }
286
287 [cssRules, accessError] = getRulesOrError();
288 if (accessError) {
289 // CORS error, cssRules are not accessible
290 // for cross-origin resources
291 logWarn(accessError);
292 }
293 }
294
295 if (cssRules) {
296 if (!hasImports(cssRules, false)) {
297 return cssRules;
298 }
299 }
300
301 try {
302 cssText = await loadText(element.href);
303 } catch (err) {
304 logWarn(err);
305 cssText = '';
306 }
307 cssBasePath = getCSSBaseBath(element.href);
308 if (cancelAsyncOperations) {
309 return null;
310 }
311 } else if (containsCSSImport()) {
312 cssText = element.textContent!.trim();
313 cssBasePath = getCSSBaseBath(location.href);
314 } else {
315 return null;

Callers 1

detailsFunction · 0.85

Calls 12

logWarnFunction · 0.90
logInfoFunction · 0.90
getCSSBaseBathFunction · 0.90
getRulesOrErrorFunction · 0.85
isStillLoadingErrorFunction · 0.85
linkLoadingFunction · 0.85
hasImportsFunction · 0.85
loadTextFunction · 0.85
containsCSSImportFunction · 0.85
createOrUpdateCORSCopyFunction · 0.85
hasMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected