javascript:(function() {
var container = document.createElement('div');
container.innerHTML = '
Select Action:
';
document.body.appendChild(container);
function handleAction(action) {
var userNameElement = document.querySelector('h3.userName');
var userName = userNameElement ? `'${userNameElement.textContent.trim()}'` : null;
var images = Array.from(document.querySelectorAll('img[fullname]'));
var userNameIndex = images.findIndex(img => img.getAttribute('fullname') === userName.replace(/'/g, ""));
var relations = [];
if (userName && userNameIndex !== -1) {
images.forEach((img, index) => {
var fullname = `'${img.getAttribute('fullname')}'`;
if (index < userNameIndex) {
var reportTo = index === 0 ? "''" : `'${images[index - 1].getAttribute('fullname')}'`;
relations.push(`(${fullname}, ${reportTo}, 'reports-to')`);
} else if (index > userNameIndex) {
relations.push(`(${fullname}, ${userName}, 'reports-to')`);
}
});
if (relations.length > 0) {
var element = document.createElement('textarea');
element.textContent = relations.join('\n');
document.body.appendChild(element);
element.select();
if (action === 'Add') {
var existingContent = '';
try {
existingContent = window.clipboardData.getData('Text') || '';
} catch (e) {
// Accessing clipboard can be restricted in some browsers
}
element.textContent = existingContent + element.textContent;
element.select();
}
document.execCommand('copy');
document.body.removeChild(element);
alert('Relations copied to clipboard!');
} else {
alert('No relations found!');
}
} else {
alert('User name not found or no images with fullname attribute!');
}
document.body.removeChild(container);
}
document.getElementById('createBtn').addEventListener('click', function() { handleAction('Create'); });
document.getElementById('addBtn').addEventListener('click', function() { handleAction('Add'); });
})();