// ==UserScript==
// @name Copy Amboss Questions to GPT #CaribbeanConnection
// @namespace http://tampermonkey.net/
// @version 1.0.0.1
// @description Add copy buttons to amboss.com to copy to ChatGPT
// @author PinballDestiny
// @match https://*.amboss.com/*
// @grant none
// @require http://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==
const loadCSS = (href) => {
let link = document.createElement("link");
link.href = href;
link.rel = "stylesheet";
document.head.appendChild(link);
};
loadCSS("https://fonts.googleapis.com/icon?family=Material+Icons");
loadCSS("https://fonts.googleapis.com/icon?family=Material+Icons+Outlined");
(function() {
'use strict';
// Common helper functions
const getPlainText = (element, removeLinks = false) => {
let clone = element.cloneNode(true);
let anchors = clone.querySelectorAll('a');
anchors.forEach(a => {
const textNode = document.createTextNode(a.textContent);
a.parentNode.replaceChild(textNode, a);
});
if (removeLinks) {
let styles = clone.querySelectorAll('style');
styles.forEach(style => style.remove());
}
return clone.innerText;
};
const isVisible = (element) => {
return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
};
const showNotification = (message) => {
const notification = document.createElement('div');
notification.textContent = message;
notification.style.position = 'fixed';
notification.style.bottom = '10px';
notification.style.right = '10px';
notification.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
notification.style.color = 'white';
notification.style.padding = '10px';
notification.style.borderRadius = '5px';
document.body.appendChild(notification);
setTimeout(() => notification.remove(), 1500);
};
function addTooltip(element, tooltipText) {
// Create tooltip div
const tooltip = document.createElement('div');
tooltip.innerText = tooltipText;
// Style the tooltip div
tooltip.style.cssText = "position: absolute; bottom: 50%; right: 100%; transform: translateX(-10px) translateY(50%); margin-right: 10px; background-color: #7A80A0; color: #F1F1F4; border-radius: 5px; padding: 5px; font-size: 12px; text-align: center; white-space: nowrap; visibility: hidden; opacity: 0; transition: opacity 0.3s";
// Append the tooltip to the button
element.appendChild(tooltip);
// Show and hide tooltip on hover
element.addEventListener('mouseenter', () => {
tooltip.style.visibility = 'visible';
tooltip.style.opacity = '1';
});
element.addEventListener('mouseleave', () => {
tooltip.style.visibility = 'hidden';
tooltip.style.opacity = '0';
});
}
// Function for Script 1
const addButtonToElements = () => {
const elements = document.querySelectorAll('[class^="explanationContent--"]');
elements.forEach(element => {
if (!element.querySelector('.copy-button')) {
const button = document.createElement('div');
button.style.width = '16px';
button.style.height = '16px';
button.style.borderRadius = '50%';
button.style.position = 'absolute';
button.style.top = '8px';
button.style.right = '0';
button.innerHTML = 'copy_all';
button.className = 'material-icons-outlined';
button.style.fontSize = '16px';
button.style.cursor = 'pointer';
button.style.opacity = '0.5';
button.style.transition = 'opacity 0.3s';
button.onmouseover = () => { button.style.opacity = '1'; };
button.onmouseout = () => { button.style.opacity = '0.1'; };
button.classList.add('copy-button');
button.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(getPlainText(element));
showNotification('Text copied!');
} catch (err) {
console.error('Failed to copy text: ', err);
}
});
element.style.position = 'relative';
element.appendChild(button);
}
});
};
// Functions for Script 2
const extractContent = () => {
const questionContent = document.querySelector('[class^="questionContent--"]');
const hintText = document.querySelector('[class^="hintText--"]');
const answerContents = document.querySelectorAll('[class^="answerContent--"]');
const explanationContents = document.querySelectorAll('[class^="explanationContent--"]');
let combinedText = '';
if (questionContent) {
combinedText += getPlainText(questionContent, true) + '\n\n';
}
if (hintText) {
combinedText += getPlainText(hintText, true) + '\n\n';
}
let answerLetter = 'A';
answerContents.forEach((answerContent) => {
combinedText += answerLetter + '. ' + getPlainText(answerContent, true) + '\n';
// Get next answer letter
answerLetter = String.fromCharCode(answerLetter.charCodeAt() + 1);
});
explanationContents.forEach((explanationContent) => {
if (isVisible(explanationContent)) {
combinedText += getPlainText(explanationContent, true) + '\n\n';
}
});
return combinedText;
};
const addButton = () => {
const questionContent = document.querySelector('[class^="questionContent--"]');
if (questionContent && !questionContent.querySelector('.copy-button')) {
const button = document.createElement('div');
button.style.width = '16px';
button.style.height = '16px';
button.style.borderRadius = '50%';
button.style.backgroundColor = 'rgba(0, 0, 0, 0)';
button.style.position = 'absolute';
button.style.bottom = '0';
button.style.right = '0';
button.style.cursor = 'pointer';
button.classList.add('copy-button');
button.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(extractContent());
showNotification('Single Explanation copied!');
} catch (err) {
console.error('Failed to copy text: ', err);
}
});
questionContent.style.position = 'relative';
questionContent.appendChild(button);
}
};
// Keyboard event for Alt + C
document.addEventListener('keydown', async function(event) {
if (event.altKey && event.key === 'a') {
try {
await navigator.clipboard.writeText(extractContent());
showNotification('Question + Expanded Explanations copied!');
} catch (err) {
console.error('Failed to copy text: ', err);
}
}
});
// Keyboard event for Alt + G
document.addEventListener('keydown', async function(event) {
if (event.altKey && event.key === 'g') {
const preText = `Respond to this prompt afresh, ignoring previous prompts and responses. Use the example provided between the "###" as a guide to format your response. Ensure the hierarchical outline has indents and line breaks and reduces the word count by about 75% while omitting as few details as possible. Follow the example closely to explain how to understand the vignette given after this example to reach the correct answer. Be sure there are no repetitive parts of your answer, and if so, simply omit that repeated part of the response leaving that section brief. Follow the example closely to explain how to understand “Your Vignette” in the text after the "&&&" so a medical student can understand how to reach the correct answer.\n###\nOriginal Question: 'A 2-month-old boy is brought to the clinic for irritability, poor feeding, and frequent vomiting. Weight is at the 15th percentile, and head circumference is at the 96th percentile. Lung sounds are clear throughout, and heart auscultation reveals no murmurs. The abdomen is soft and nondistended. There is hepatosplenomegaly. Diffusely reduced muscle tone is present in all extremities. Funduscopy reveals white-yellow chorioretinal lesions in both eyes. MRI of the brain shows enlarged ventricles and scattered intracranial calcifications. Which of the following is the most likely cause of this patient's condition?\nA. Chromosomal abnormality\nB. Intrapartum infection\nC. In utero infection\nD. Postpartum infection\nE. Single gene defect'\n\nCorrect Answer: 'C. In utero infection'\n\nIdeal Response (text enclosed in parenthesis is instruction for you and should not be included in response):\n\nI. Restated Question (all key clues from the vignette should be included in the restated question, and the question should ask the same question that makes sense with the original answer choice):\nWhat is the underlying condition in a 2-month-old boy presenting with irritability, poor feeding, vomiting, hepatosplenomegaly, reduced muscle tone, chorioretinal lesions, enlarged ventricles, and intracranial calcifications?\n\nII. Correct Answer (The following answer is provided exactly as it appears in the original text): C. In utero infection\n\nIII. To reach answer, you must understand (give details of key concept in 40 words or less, avoid repetition from prior sections): \n'• Recognize increased head circumference and enlarged ventricles indicate increased intracranial pressure. \n• Chorioretinal lesions, intracranial calcifications, and hepatosplenomegaly are signs of systemic infection. \n• The presentation in a 2-month-old suggests an in utero, rather than postpartum, infection. '\n\nIV. Vignette Key Clues (40 words or less providing unique details providing symptoms or findings using more general, descriptive language often favored by NBME and USMLE in vignettes, avoid repetition from prior sections): ' \nChorioretinitis: "Examination of the back of the eye reveals white-yellow lesions in both eyes."\nHydrocephalus: "Imaging of the brain shows enlarged ventricles."\nIntracranial calcifications: "Brain imaging reveals scattered dense, white spots within the brain tissue."\n\nV. Explanation of Why Clues Point to Answer (avoid repetition from prior sections): \n* Congenital toxoplasmosis presents with a classic triad of hydrocephalus, intracranial calcifications, and chorioretinitis.\n* In utero transmission of TORCH infections--Toxoplasmosis, Other infections, Rubella, Cytomegalovirus, and Herpes simplex--leads to chronic CNS inflammation and the development of intracranial calcifications.\n* Obstructive hydrocephalus causes ventriculomegaly, while chronic chorioretinal inflammation produces white-yellow retinal scars.\n* The presence of growth restriction, hepatosplenomegaly, and rash further support the suspicion of in utero infection.\n###\n&&&\nYour Vignette:\n`;
try {
await navigator.clipboard.writeText(preText + extractContent());
showNotification('GPT Prompt and content copied to clipboard!');
} catch (err) {
console.error('Failed to copy text: ', err);
}
}
});
// Add Alt+G button
const altGButton = document.createElement('img');
altGButton.src = "https://user-images.githubusercontent.com/57292172/223011977-371c1677-a8f3-4c06-87fb-b774243b0545.svg";
altGButton.style.position = 'fixed';
altGButton.style.bottom = '64px';
altGButton.style.right = '24px';
altGButton.style.width = '16px';
altGButton.style.height = '16px';
altGButton.style.opacity = '0.6';
altGButton.style.transition = 'opacity 0.3s';
altGButton.onmouseover = () => { altGButton.style.opacity = '1'; };
altGButton.onmouseout = () => { altGButton.style.opacity = '0.1'; };
altGButton.onclick = async () => {
const preText = `Respond to this prompt afresh, ignoring previous prompts and responses. Use the example provided between the "###" as a guide to format your response. Ensure the hierarchical outline has indents and line breaks and reduces the word count by about 75% while omitting as few details as possible. Follow the example closely to explain how to understand the vignette given after this example to reach the correct answer. Be sure there are no repetitive parts of your answer, and if so, simply omit that repeated part of the response leaving that section brief. Follow the example closely to explain how to understand “Your Vignette” in the text after the "&&&" so a medical student can understand how to reach the correct answer.\n###\nOriginal Question: 'A 2-month-old boy is brought to the clinic for irritability, poor feeding, and frequent vomiting. Weight is at the 15th percentile, and head circumference is at the 96th percentile. Lung sounds are clear throughout, and heart auscultation reveals no murmurs. The abdomen is soft and nondistended. There is hepatosplenomegaly. Diffusely reduced muscle tone is present in all extremities. Funduscopy reveals white-yellow chorioretinal lesions in both eyes. MRI of the brain shows enlarged ventricles and scattered intracranial calcifications. Which of the following is the most likely cause of this patient's condition?\nA. Chromosomal abnormality\nB. Intrapartum infection\nC. In utero infection\nD. Postpartum infection\nE. Single gene defect'\n\nCorrect Answer: 'C. In utero infection'\n\nIdeal Response (text enclosed in parenthesis is instruction for you and should not be included in response):\n\nI. Restated Question (all key clues from the vignette should be included in the restated question, and the question should ask the same question that makes sense with the original answer choice):\nWhat is the underlying condition in a 2-month-old boy presenting with irritability, poor feeding, vomiting, hepatosplenomegaly, reduced muscle tone, chorioretinal lesions, enlarged ventricles, and intracranial calcifications?\n\nII. Correct Answer (The following answer is provided exactly as it appears in the original text): C. In utero infection\n\nIII. To reach answer, you must understand (give details of key concept in 40 words or less, avoid repetition from prior sections): \n'• Recognize increased head circumference and enlarged ventricles indicate increased intracranial pressure. \n• Chorioretinal lesions, intracranial calcifications, and hepatosplenomegaly are signs of systemic infection. \n• The presentation in a 2-month-old suggests an in utero, rather than postpartum, infection. '\n\nIV. Vignette Key Clues (40 words or less providing unique details providing symptoms or findings using more general, descriptive language often favored by NBME and USMLE in vignettes, avoid repetition from prior sections): ' \nChorioretinitis: "Examination of the back of the eye reveals white-yellow lesions in both eyes."\nHydrocephalus: "Imaging of the brain shows enlarged ventricles."\nIntracranial calcifications: "Brain imaging reveals scattered dense, white spots within the brain tissue."\n\nV. Explanation of Why Clues Point to Answer (avoid repetition from prior sections): \n* Congenital toxoplasmosis presents with a classic triad of hydrocephalus, intracranial calcifications, and chorioretinitis.\n* In utero transmission of TORCH infections--Toxoplasmosis, Other infections, Rubella, Cytomegalovirus, and Herpes simplex--leads to chronic CNS inflammation and the development of intracranial calcifications.\n* Obstructive hydrocephalus causes ventriculomegaly, while chronic chorioretinal inflammation produces white-yellow retinal scars.\n* The presence of growth restriction, hepatosplenomegaly, and rash further support the suspicion of in utero infection.\n###\n&&&\nYour Vignette:\n`;
try {
await navigator.clipboard.writeText(preText + extractContent());
showNotification('GPT Prompt and content copied to clipboard!');
} catch (err) {
console.error('Failed to copy text: ', err);
}
};
document.body.appendChild(altGButton);
// Fade after 3500ms
setTimeout(() => {
altGButton.style.transition = 'opacity 1s';
altGButton.style.opacity = '0.05';
}, 3500);
// Add Alt+C button
const altCButton = document.createElement('span');
altCButton.innerHTML = 'copy_all';
altCButton.className = 'material-icons-outlined';
altCButton.style.position = 'fixed';
altCButton.style.bottom = '96px';
altCButton.style.right = '24px';
altCButton.style.fontSize = '16px';
altCButton.style.cursor = 'pointer';
altCButton.style.opacity = '0.6';
altCButton.style.transition = 'opacity 0.3s';
altCButton.onmouseover = () => { altCButton.style.opacity = '1'; };
altCButton.onmouseout = () => { altCButton.style.opacity = '0.1'; };
altCButton.onclick = async () => {
try {
await navigator.clipboard.writeText(extractContent());
showNotification('Text copied!');
} catch (err) {
console.error('Failed to copy text: ', err);
}
};
document.body.appendChild(altCButton);
// Fade after 3500ms
setTimeout(() => {
altCButton.style.transition = 'opacity 1s';
altCButton.style.opacity = '0.05';
}, 3500);
// Call the functions
addButtonToElements();
addButton();
// Observe the document body for changes
new MutationObserver(() => {
addButtonToElements();
addButton();
}).observe(document.body, {childList: true, subtree: true});
})();