philomena/assets/js/pmwarning.ts

27 lines
591 B
TypeScript
Raw Normal View History

2022-03-24 17:31:57 +01:00
/**
* PmWarning
*
* Warn users that their PM will be reviewed.
*/
import { $, hideEl, showEl } from './utils/dom';
2022-03-24 17:31:57 +01:00
export function warnAboutPMs() {
const textarea = $<HTMLTextAreaElement>('.js-toolbar-input');
const warning = $<HTMLDivElement>('.js-hidden-warning');
2022-03-24 17:31:57 +01:00
const imageEmbedRegex = /!+\[/g;
if (!warning || !textarea) return;
textarea.addEventListener('input', () => {
const value = textarea.value;
2022-03-24 19:07:51 +01:00
if (value.match(imageEmbedRegex)) {
showEl(warning);
2022-03-24 19:07:51 +01:00
}
else if (!warning.classList.contains('hidden')) {
hideEl(warning);
2022-03-24 19:07:51 +01:00
}
2022-03-24 17:31:57 +01:00
});
}