2022-05-15 08:30:40 -07:00
|
|
|
import { expandSpoilers } from 'flavours/glitch/util/initial_state';
|
|
|
|
|
2022-07-24 11:01:30 -07:00
|
|
|
function _autoUnfoldCW(spoiler_text, skip_unfold_regex) {
|
|
|
|
if (!expandSpoilers)
|
2018-08-28 08:16:30 -07:00
|
|
|
return false;
|
2018-10-12 14:12:39 -07:00
|
|
|
|
2022-07-24 11:01:30 -07:00
|
|
|
if (!skip_unfold_regex)
|
2018-10-12 14:12:39 -07:00
|
|
|
return true;
|
|
|
|
|
2022-07-24 11:01:30 -07:00
|
|
|
let regex = null;
|
2018-08-28 08:16:30 -07:00
|
|
|
|
|
|
|
try {
|
2022-07-24 11:01:30 -07:00
|
|
|
regex = new RegExp(skip_unfold_regex.trim(), 'i');
|
2018-08-28 08:16:30 -07:00
|
|
|
} catch (e) {
|
2022-07-24 11:01:30 -07:00
|
|
|
// Bad regex, skip filters
|
|
|
|
return true;
|
2018-08-28 08:16:30 -07:00
|
|
|
}
|
|
|
|
|
2022-07-24 11:01:30 -07: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 08:16:30 -07:00
|
|
|
}
|