1(function () { 2 3 function escHtml(s) { 4 const d = document.createElement('div'); 5 d.textContent = s; 6 return d.innerHTML; 7 } 8 9 function getTitle() { 10 const el = document.getElementById('liveblog-entry-title-input'); 11 return el ? (el.value || '').trim() : ''; 12 } 13 14 function titlePrefixHtml(title) { 15 if (!title) return ''; 16 return '<h3 class="liveblog-entry-title">' + escHtml(title) + '</h3>'; 17 } 18 19 /* ---------------------------------------- 20 Inject Title field into Liveblog editor 21 ---------------------------------------- */ 22 23 function injectTitleField() { 24 25 const container = document.querySelector('.liveblog-editor-container'); 26 if (!container) return false; 27 28 if (document.getElementById('liveblog-entry-title-input')) return true; 29 30 const heading = container.querySelector('.liveblog-editor-title') || container.firstChild; 31 32 const wrap = document.createElement('div'); 33 wrap.style.margin = '10px 0 10px'; 34 35 wrap.innerHTML = 36 '<label for="liveblog-entry-title-input" style="display:block;margin-bottom:6px;font-weight:600;">Entry title</label>' + 37 '<input type="text" id="liveblog-entry-title-input" placeholder="Title (optional)" ' + 38 'style="width:100%;max-width:640px;padding:8px 10px;border:1px solid #c3c4c7;border-radius:4px;" />'; 39 40 if (heading && heading.parentNode) { 41 heading.parentNode.insertBefore(wrap, heading.nextSibling); 42 } else { 43 container.insertBefore(wrap, container.firstChild); 44 } 45 46 return true; 47 } 48 49 let tries = 0; 50 const timer = setInterval(function () { 51 tries++; 52 if (injectTitleField() || tries > 80) clearInterval(timer); 53 }, 250); 54 55 56 /* ---------------------------------------- 57 Capture title when publish is clicked 58 ---------------------------------------- */ 59 60 window.__lb_title_snapshot = ''; 61 62 document.addEventListener('click', function (e) { 63 const btn = e.target.closest('.liveblog-publish-btn'); 64 if (!btn) return; 65 66 window.__lb_title_snapshot = getTitle(); 67 }, true); 68 69 70 /* ---------------------------------------- 71 Patch Liveblog REST request 72 ---------------------------------------- */ 73 74 const origOpen = XMLHttpRequest.prototype.open; 75 76 XMLHttpRequest.prototype.open = function (method, url) { 77 this.__lb_url = url; 78 return origOpen.apply(this, arguments); 79 }; 80 81 const origSend = XMLHttpRequest.prototype.send; 82 83 XMLHttpRequest.prototype.send = function (body) { 84 85 try { 86 87 const url = this.__lb_url || ''; 88 const isLiveblogCrud = 89 url.indexOf('/wp-json/liveblog/v1/') !== -1 && 90 url.indexOf('/crud/') !== -1; 91 92 if (isLiveblogCrud && typeof body === 'string' && body.length) { 93 94 const title = (window.__lb_title_snapshot || '').trim(); 95 96 if (title) { 97 98 const obj = JSON.parse(body); 99 100 const keys = ['content', 'html', 'message', 'entry', 'text', 'body']; 101 102 for (let i = 0; i < keys.length; i++) { 103 const k = keys[i]; 104 105 if (typeof obj[k] === 'string') { 106 107 obj[k] = titlePrefixHtml(title) + obj[k]; 108 109 body = JSON.stringify(obj); 110 111 setTimeout(function () { 112 const el = document.getElementById('liveblog-entry-title-input'); 113 if (el) el.value = ''; 114 window.__lb_title_snapshot = ''; 115 }, 0); 116 117 break; 118 } 119 } 120 } 121 } 122 123 } catch (e) { } 124 125 return origSend.call(this, body); 126 }; 127 128 /* Copy Link */ 129 document.addEventListener('click', async (e) => { 130 const link = e.target.closest('.lb-copy'); 131 if (!link) return; 132 133 e.preventDefault(); 134 135 const url = link.href; // absolute 136 if (!url) return; 137 138 try { 139 await navigator.clipboard.writeText(url); 140 const old = link.textContent; 141 link.textContent = 'Copied!'; 142 setTimeout(() => (link.textContent = old), 1200); 143 } catch { 144 alert('Copy this link: ' + url); 145 } 146 }); 147 148})();
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.