1/* global gettext */ 2 3const getLevel = (notice, levels) => { 4 let label = '' 5 for (const name of Object.keys(levels)) { 6 for (const className of [...notice.classList]) { 7 if (levels[name].selector.indexOf(className) !== -1) { 8 label = levels[name].label 9 break 10 } 11 } 12 if (label !== '') break 13 } 14 return label 15} 16 17export const addNoticeTitle = (notices, levels) => { 18 for (const notice of notices) { 19 if (notice.querySelector('.pk-notice--title')) continue 20 21 const noticeTitle = document.createElement(['LI', 'P'].includes(notice.tagName) ? 'span' : 'p') 22 noticeTitle.classList.add('pk-notice--title') 23 noticeTitle.textContent = getLevel(notice, levels) 24 25 notice.prepend(noticeTitle) 26 } 27} 28 29window.addEventListener('DOMContentLoaded', () => { 30 const levels = { 31 error: { 32 label: gettext('Error'), 33 selector: '.errornotice, #messages li.error, .pk-error', 34 }, 35 success: { 36 label: gettext('Success'), 37 selector: '.successnotice, #messages li.success, .pk-success', 38 }, 39 info: { 40 label: gettext('Information'), 41 selector: '.infonotice, #messages li.info, .pk-information', 42 }, 43 warning: { 44 label: gettext('Warning'), 45 selector: '.warningnotice, #messages li.warning, .pk-attention', 46 }, 47 remark: { 48 label: gettext('Remark'), 49 selector: '.remarknotice, .aretha-remark', 50 }, 51 note: { 52 label: gettext('Note'), 53 selector: '.notenotice, .aretha-note, .note', 54 }, 55 } 56 57 const noticesSelectors = Object.values(levels).map(i => i.selector).join(',') 58 const notices = document.querySelectorAll(noticesSelectors) 59 if (notices.length > 0) { 60 addNoticeTitle(notices, levels) 61 } 62})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.