Last active
July 31, 2020 16:50
-
-
Save jcsrb/5052ddaebd3b7378a61c0b190f661901 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let alreadyRun = document.querySelector('body').classList.contains("vl-bookmarklet"); | |
let domainCheck = window.location.origin == "http://legaldiary.courts.ie" | |
function wrap(el, wrapper) { | |
el.parentNode.insertBefore(wrapper, el); | |
wrapper.appendChild(el); | |
} | |
function addStyle(styleString) { | |
const style = document.createElement('style'); | |
style.textContent = styleString; | |
document.head.append(style); | |
} | |
let styleBody = ` | |
.analyzed::before, .analyzed .nested::before { | |
content: "🦄"; | |
font-family: "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", EmojiSymbols; | |
} | |
.analyzed::after, .analyzed .nested::after { | |
font-family: "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", EmojiSymbols; | |
} | |
.analyzed.court::before { | |
content: "🏛"; | |
} | |
.analyzed.judge::before { | |
content: "👩⚖️"; | |
} | |
.analyzed.judge.man::before { | |
content: "👨⚖️"; | |
} | |
.analyzed.case::before { | |
content: "📘"; | |
} | |
.analyzed.country::before{ | |
content: ""; | |
} | |
.analyzed.country::after { | |
content: "🏳️"; | |
float: left; | |
} | |
.analyzed.CZECH::after { | |
content: "🇨🇿"; | |
} | |
.analyzed.ROMANIAN::after { | |
content: "🇷🇴"; | |
} | |
.analyzed.POLISH::after { | |
content: "🇵🇱"; | |
} | |
.analyzed.ENGLISH::after { | |
content: "ENG"; | |
background: darkblue; | |
color: white; | |
font-weight: bold; | |
padding: 0 0.25em; | |
font-size: 0.5em; | |
border-radius: 4px; | |
height: 2em; | |
line-height: 2em; | |
margin-top: 0.5em; | |
} | |
.analyzed.LITHUANIAN::after { | |
content: "🇱🇹"; | |
} | |
.analyzed.CROATIAN::after { | |
content: "🇭🇷"; | |
} | |
.analyzed.LATVIAN::after { | |
content: "🇱🇻"; | |
} | |
.analyzed.HUNGARIAN::after { | |
content: "🇭🇺"; | |
} | |
.analyzed.case .case-id { | |
background-color: #003657; | |
color: #fff; | |
padding: 5px 7px; | |
border-radius: 4px; | |
} | |
.analyzed.judge .judge-profile { | |
background-color: #003657; | |
color: #fff; | |
padding: 5px 7px; | |
border-radius: 4px; | |
} | |
.analyzed.time::before { | |
content: "⏳"!important; | |
} | |
.analyzed .nested.time::before { | |
content: "⏳" | |
} | |
.analyzed.time.case::before{ | |
content: "📘"!important; | |
} | |
.analyzed.list::before { | |
content: "🧾"; | |
} | |
.analyzed.remote::before { | |
content: "⚡️"; | |
} | |
a[href^="https://app.vizlegal"]::before{ | |
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='26.07' width='28.93' viewBox='0 0 28.930001 26.07'%3E%3Cg fill='%231a1e39' class='iso'%3E%3Cpath d='M2.79 15.12a8.16 8.16 0 008.17 8.15h1.4v2.8h-1.4a10.96 10.96 0 110-21.92h1.4v2.8h-1.4a8.16 8.16 0 00-8.16 8.16M26.13 15.12a8.16 8.16 0 01-8.16 8.15h-1.4v2.8h1.4a10.96 10.96 0 100-21.92h-1.4v2.8h1.4a8.16 8.16 0 018.16 8.16'/%3E%3Cpath d='M17.97 17.92h-7.02a2.8 2.8 0 110-5.6h7.02a2.8 2.8 0 010 5.6' fill='%23e62849' class='dot'/%3E%3Cpath d='M27.53 2.8h1.4V0h-1.4a10.95 10.95 0 00-9.48 5.47l2.76.88a8.14 8.14 0 016.72-3.55'/%3E%3C/g%3E%3C/svg%3E%0A"); | |
background-size: 0.8em; | |
background-color: white; | |
display: inline-block; | |
background-repeat: no-repeat; | |
background-position: center center; | |
width: 1.1em; | |
height: 1.1em; | |
content: ""; | |
border-radius: 7px; | |
top: 0.2em; | |
position: relative; | |
margin-right: 0.5em; | |
} | |
.vl-explainer { | |
border: 1px solid #E62648; | |
border-radius: 4px; | |
margin: 1em 1em; | |
padding: 0.7em 1em; | |
display: flex; | |
} | |
.vl-explainer .vl-app-icon{ | |
border-radius: 20%; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
box-shadow: 0px 1px 2px 0px rgba(0,0,0,0.42); | |
opacity: 0.8; | |
height: 3em; | |
width: 3em; | |
flex: 0 0 3em; | |
} | |
.vl-explainer > div { | |
padding: 0 1em; | |
} | |
.vl-explainer > div > a{ | |
color: #E62648; | |
font-weight: bold; | |
} | |
`; | |
let listTriggers = [ | |
/\bBAIL\b/, | |
/\bEXTRADITION\b/, | |
/\bLIST\b/, | |
/\bWARDSHIP\b/, | |
/\bHEARING\b/, | |
/\bPERSONAL INJURIES\b/, | |
/\bNON.JURY\/JUDICIAL REVIEW\b/, | |
/\bCOMMERCIAL\b/, | |
/\bCHANCERY\b/, | |
/\bMENTION\b/, | |
/\bASYLUM\b/, | |
/\bFAMILY LAW\b/, | |
] | |
let remoteTriggers = [ | |
/\bELECTRONICALLY\b/, | |
/\bREMOTE\b/, | |
/\bELECTRONIC\b/ | |
] | |
let countryTriggers = [ | |
/\bPOLISH\b/, | |
/\bCZECH\b/, | |
/\bROMANIAN\b/, | |
/\bENGLISH\b/, | |
/\bLITHUANIAN\b/, | |
/\bCROATIAN\b/, | |
/\bLATVIAN\b/, | |
/\bHUNGARIAN\b/, | |
/\bKURDISH\b/ | |
] | |
let matcher = (text) => (regex) => regex.test(text) | |
let isCourt = (text) => /\bcourts?|courtrooms?\b/i.test(text) && text.length < 100 | |
let isCase = (text) => /(\d{4}[\s,-]\d+[\s,-]?[A-Z]+)[\s,-]?/i.test(text) | |
let isAlternatFormatCase = (text) => /-201\d\/\d{1,3}\/.{1,3}[\s-]/i.test(text) | |
let isTime = (text) => /\d{1,2}[\.:]\d{2}/.test(text) | |
let isRemote = (text) => remoteTriggers.some(matcher(text)) | |
let isList = (text) => listTriggers.some(matcher(text)) | |
let isJudge = (text) => (/\bmr?s?\.?\s\bjustice\b|\bbefore\b|\bpresident\b/i.test(text) || /\bDUTY JUDGE\b/.test(text)) && text.length < 100 | |
let isMR = (text) => /\bMR\.?\b/i.test(text) | |
let isMRS = (text) => /\bMR?S\.?\b/i.test(text) | |
let isCountry = (text) => countryTriggers.some(matcher(text)) | |
function analyze(el) { | |
let labels = [] | |
let text = el.textContent | |
if (isCourt(text)) labels.push("court") | |
if (isJudge(text)) { | |
labels.push("judge") | |
if (isMR(text)) labels.push("man") | |
if (isMRS(text)) labels.push("women") | |
} | |
if (isCase(text)) { | |
labels.push("case"); | |
labels.push("default"); | |
} | |
if (isAlternatFormatCase(text)) { | |
labels.push("case"); | |
labels.push("alt1"); | |
} | |
if (isTime(text)) labels.push("time") | |
if (isRemote(text)) labels.push("remote") | |
if (isList(text)) labels.push("list") | |
if (isCountry(text)) { | |
labels.push("country") | |
labels.push(text.trim().split(/\s+/)[0].trim()) | |
} | |
if (labels.length) labels.push("analyzed") | |
return labels | |
} | |
function createWrapper(type, labels) { | |
let el = document.createElement(type) | |
labels.forEach(l => { | |
el.classList.add(l); | |
}) | |
return el | |
} | |
function cleanup(box){ | |
box.childNodes.forEach(el => { | |
if (el.previousSibling && el.previousSibling.nodeName == "BR" && el.nodeName == "BR") { | |
el.previousSibling.remove() | |
el.replaceWith(document.createElement("HR")) | |
} | |
}) | |
box.childNodes.forEach(el => { | |
if (el.nodeName == "BR") { | |
el.remove() | |
} | |
if (el.nodeName == "DIV" && el.classList.contains("case") && el.previousSibling.nodeName == "HR") { | |
el.previousSibling.remove() | |
} | |
}) | |
box.childNodes.forEach(el => { | |
if (el.previousSibling && el.previousSibling.nodeName == "HR" && el.nodeName == "HR") { | |
el.previousSibling.remove() | |
} | |
}) | |
} | |
function linkCases(){ | |
document.querySelectorAll('.ld-content .analyzed.case.default').forEach(el => { | |
let text = el.textContent; | |
text = text.replace(/^\d{1,2}\.[\s-]+/, "") | |
let s = text.match(/(\d{4}[\s,-]\d+[\s,-]?[A-Z]+)/i) | |
let case_id = s && s[0] | |
let caseIDParts = case_id.split(/[\s-]+/) | |
let linktext = text.replace(case_id, `<a target="_blank" title="Open ${case_id} on Vizlegal" href="https://app.vizlegal.com/docs/IEF-${caseIDParts[0]}-${caseIDParts[2]}-${caseIDParts[1]}?utm_source=legal_diary_bookmarklet" class="case-id">${case_id}</a> `) | |
el.innerHTML = linktext | |
}) | |
} | |
function linkJudges(){ | |
document.querySelectorAll('.ld-content .analyzed.judge').forEach(el => { | |
let text = el.textContent.toUpperCase(); | |
let searchKeyword = text.split(" ").filter(x => !["MR.","MS.", "MRS.", "MR","MS","MRS","JUSTICE","THE"].includes(x)).join(" "); | |
let linktext = `<a target="_blank" title="Judge Profile on Vizlegal" href="https://app.vizlegal.com/judges?utm_source=legal_diary_bookmarklet&filter=${searchKeyword}" class="judge-profile">${text}</a> ` | |
el.innerHTML = linktext; | |
}) | |
} | |
function boldTime(){ | |
document.querySelectorAll('.ld-content .analyzed.time').forEach(el => { | |
if(el.classList.contains("case")) return; | |
let text = el.textContent; | |
text = text.replace(/(\d{1,2}.\d{1,2})/, "<b>$1</b>") | |
el.innerHTML = text | |
}) | |
} | |
function altCaseTime(){ | |
document.querySelectorAll('.ld-content .case.alt1.analyzed').forEach(el => { | |
let text = el.textContent; | |
text = text.replace(/((201\d)\/(\d{1,4})\/([A-Z]{1,3}))/, '<a target="_blank" title="Open $1 on Vizlegal" href="https://app.vizlegal.com/docs/IEF-$2-$4-$3?utm_source=legal_diary_bookmarklet" class="case-id">$1</a>') | |
text = text.replace(/(\d{1,2}\.?\d{0,2}[amp]{2}|12 noon)/, '<b class="nested time">$1</b>') | |
el.innerHTML = text | |
}) | |
} | |
function addExplainer(){ | |
document.querySelectorAll('.alfresco-properties').forEach(el => { | |
let html = ` | |
<div class="vl-explainer"> | |
<a class="vl-app-icon" href="https://vizlegal.com?utm_source=legal_diary_bookmarklet" target="_blank"> <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='26.07' width='28.93' viewBox='0 0 28.930001 26.07'%3E%3Cg fill='%231a1e39' class='iso'%3E%3Cpath d='M2.79 15.12a8.16 8.16 0 008.17 8.15h1.4v2.8h-1.4a10.96 10.96 0 110-21.92h1.4v2.8h-1.4a8.16 8.16 0 00-8.16 8.16M26.13 15.12a8.16 8.16 0 01-8.16 8.15h-1.4v2.8h1.4a10.96 10.96 0 100-21.92h-1.4v2.8h1.4a8.16 8.16 0 018.16 8.16'/%3E%3Cpath d='M17.97 17.92h-7.02a2.8 2.8 0 110-5.6h7.02a2.8 2.8 0 010 5.6' fill='%23e62849' class='dot'/%3E%3Cpath d='M27.53 2.8h1.4V0h-1.4a10.95 10.95 0 00-9.48 5.47l2.76.88a8.14 8.14 0 016.72-3.55'/%3E%3C/g%3E%3C/svg%3E%0A" alt="vizlegal"></a> | |
<div>We at Vizlegal hope you enjoy this better formatting!<br>Get <b>notified of new filings</b>, <b>listings</b> and <b>search for judgments</b> and more! Get a <b>free trial account</b> at <a href="https://vizlegal.com?utm_source=legal_diary_bookmarklet" target="_blank">vizlegal.com</a></div> | |
</div> | |
`; | |
el.insertAdjacentHTML("afterend", html); | |
}) | |
} | |
function runContent(box){ | |
box.childNodes.forEach(el => { | |
if (el.nodeName == "#text") { | |
let labels = analyze(el) | |
el.textContent = el.textContent.trim() | |
if (el.textContent) { | |
wrap(el, createWrapper("div", labels)); | |
} else { | |
el.remove() | |
} | |
} | |
}) | |
} | |
if(!alreadyRun && domainCheck){ | |
document.querySelector('body').classList.add("vl-bookmarklet"); | |
let listType = document.querySelector('.alfresco-properties .cell:nth-child(2)') | |
let listCheck = listType && listType.textContent == "TypeToday's Cases / All Lists" | |
let runIt = listCheck || confirm("This tool is intended for High Court Today's Cases list, try it anyway?"); | |
if(runIt){ | |
let box = document.querySelector('.ld-content'); | |
addStyle(styleBody); | |
runContent(box); | |
cleanup(box); | |
linkCases(); | |
altCaseTime(); | |
linkJudges(); | |
boldTime(); | |
addExplainer(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment