2022-05-15 15:30:40 +00:00
|
|
|
import { expandSpoilers } from 'flavours/glitch/util/initial_state';
|
|
|
|
|
2022-07-24 18:01:30 +00:00
|
|
|
function _autoUnfoldCW(spoiler_text, skip_unfold_regex) {
|
|
|
|
if (!expandSpoilers)
|
2018-08-28 15:16:30 +00:00
|
|
|
return false;
|
2018-10-12 21:12:39 +00:00
|
|
|
|
2022-07-24 18:01:30 +00:00
|
|
|
if (!skip_unfold_regex)
|
2018-10-12 21:12:39 +00:00
|
|
|
return true;
|
|
|
|
|
2022-07-24 18:01:30 +00:00
|
|
|
let regex = null;
|
2018-08-28 15:16:30 +00:00
|
|
|
|
|
|
|
try {
|
2022-07-24 18:01:30 +00:00
|
|
|
regex = new RegExp(skip_unfold_regex.trim(), 'i');
|
2018-08-28 15:16:30 +00:00
|
|
|
} catch (e) {
|
2022-07-24 18:01:30 +00:00
|
|
|
// Bad regex, skip filters
|
|
|
|
return true;
|
2018-08-28 15:16:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-24 18:01:30 +00:00
|
|
|
return !regex.test(spoiler_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function autoHideCW(settings, spoiler_text) {
|
|
|
|
return !_autoUnfoldCW(spoiler_text, settings.getIn(['content_warnings', 'filter']));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function autoUnfoldCW(settings, status) {
|
|
|
|
if (!status)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return _autoUnfoldCW(status.get('spoiler_text'), settings.getIn(['content_warnings', 'filter']));
|
2018-08-28 15:16:30 +00:00
|
|
|
}
|