Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save cuylerstuwe/46720e01067a79c288f76db4cffa4c7b to your computer and use it in GitHub Desktop.

Select an option

Save cuylerstuwe/46720e01067a79c288f76db4cffa4c7b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Arthi Murugesan - Classification (Menu Item Classification HIT)
// @namespace salembeats
// @version 1
// @description .
// @author Cuyler Stuwe (salembeats)
// @include *
// @grant unsafeWindow
// ==/UserScript==
if(window === window.top) {return;}
if(!document.referrer.includes("3X7VAYHW1S66PEA8INW34RI3ZA9VPR")) {return;}
let hitTextElement = document.querySelector("#workContent>div");
let hitText = hitTextElement.innerText;
let menuItemName = hitText.match(/Name:\s+(.*)$/gm)[1].match(/Name:\s+(.*)$/m)[1];
let description = hitText.match(/Description:\s+(.*)$/m)[1];
let category = hitText.match(/Menu Category of the menu item:\s+(.*)$/m)[1];
let optionsLineText = (hitText.match(/Choice Options:\s+(.*)$/m) || ["",""])[1];
let options = optionsLineText.split("|");
function optionsToHTML() {
let html = "";
for(let option of options) {
html += `<li><span class="details">${option}</span></li>`;
}
return html;
}
let dishQueryElement = document.querySelectorAll("h5")[1];
let dishQuery = dishQueryElement.innerText.trim();
let dishes = dishQuery.split(/\(\d+\)./)
.filter(string => string !== "")
.map(
dish => dish.replace('"', "")
.replace('"', "")
.replace(", ", "")
);
function dishesToHTML() {
let html = "";
for(let dish of dishes) {
html += `<span class="dish">${dish}</span>, `;
}
return html.substr(0, html.length-2);
}
hitTextElement.insertAdjacentHTML("beforebegin", `
<style>
#simplified>div>span:first-of-type {
font-weight: bold;
}
#simplified {
border: 5px dotted red;
background: #FFE0E0;
padding: 10px;
}
#dishQuery {
font-size: 1.5em;
}
#item {
background: #ffffe0;
}
.dish {
background: #ffffe0;
}
.details {
background: #e6fffd;
}
</style>
<div id="simplified">
<div><span>Tell Whether The Below Is:</span> <span id="dishQuery">${dishesToHTML()}</span></div>
<br/>
<div><span>Item:</span> <span id="item">${menuItemName}</span></div>
<div><span>Description:</span> <span class="details">${description}</span></div>
<div><span>Category:</span> <span class="details">${category}</span></div>
<br/>
<div><span>Options:</span></div>
<ul id="options">
${optionsToHTML()}
</ul>
</div>
`);
hitTextElement.innerText = hitTextElement.innerText;
hitTextElement.innerHTML = `<em><div style="margin-top: 50px;">Original HIT Text:</div><div>${hitTextElement.innerHTML}</div></em>`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment