philomena/assets/js/pmwarning.ts

29 lines
629 B
TypeScript
Raw Normal View History

2022-03-24 17:31:57 +01:00
/**
* PmWarning
*
* Warn users that their PM will be reviewed.
*/
import { $ } from './utils/dom';
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)) {
2022-03-24 17:31:57 +01:00
warning.classList.remove('hidden');
2022-03-24 19:07:51 +01:00
}
else if (!warning.classList.contains('hidden')) {
2022-03-24 17:31:57 +01:00
warning.classList.add('hidden');
2022-03-24 19:07:51 +01:00
}
2022-03-24 17:31:57 +01:00
});
}
export { warnAboutPMs };