blob: 7ab748669055a466ea0f72bae6ebeb6c51780eb0 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<style>
p {
font-size: 20px;
width: 100px;
text-align: center;
display: inline-block;
}
</style>
</head>
<body>
<p contenteditable>foobar</p>
<div>Has "Translate" item? <span id="has-translate"></span></div>
<div>Has "Look Up" item? <span id="has-look-up"></span></div>
<div>Has "Search the Web" item? <span id="has-search"></span></div>
<script>
function hasMenuItemContainingTitle(items, titleToQuery)
{
for (let item of items) {
let title = item.title || item;
if (title.includes?.(titleToQuery))
return true;
}
return false;
}
let paragraph = document.querySelector("p");
let boundingRect = paragraph.getBoundingClientRect();
eventSender.mouseMoveTo(boundingRect.left + boundingRect.width / 2, boundingRect.top + boundingRect.height / 2);
items = eventSender.contextClick();
document.getElementById("has-look-up").textContent = hasMenuItemContainingTitle(items, "Look Up");
document.getElementById("has-translate").textContent = hasMenuItemContainingTitle(items, "Translate");
document.getElementById("has-search").textContent = hasMenuItemContainingTitle(items, "Search the Web");
paragraph.remove();
</script>
</body>
</html>