~cytrogen/masto-fe

ref: 95b389e89d984644f986bf984f9bc38080f6fb32 masto-fe/app/javascript/flavours/glitch/utils/content_warning.js -rw-r--r-- 711 bytes
95b389e8 — Cytrogen Convert mastodon flavour SCSS to CSS custom properties (Phase 7) 14 days ago
                                                                                
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
function _autoUnfoldCW(spoiler_text, settings) {
  if (!settings.getIn(["content_warnings", "auto_unfold"])) {
    return false;
  }

  const skip_unfold_regex = settings.getIn(["content_warnings", "filter"]);

  if (!skip_unfold_regex) {
    return true;
  }

  let regex = null;

  try {
    regex = new RegExp(skip_unfold_regex.trim(), "i");
  } catch (e) {
    // Bad regex, skip filters
    return true;
  }

  return !regex.test(spoiler_text);
}

export function autoHideCW(settings, spoiler_text) {
  return !_autoUnfoldCW(spoiler_text, settings);
}

export function autoUnfoldCW(settings, status) {
  if (!status) {
    return false;
  }

  return _autoUnfoldCW(status.get("spoiler_text"), settings);
}