Skip to content

Instantly share code, notes, and snippets.

@oneross
Last active November 21, 2023 23:44
Show Gist options
  • Save oneross/b4679f3993cc9c05f9b6b1db5fd67ed6 to your computer and use it in GitHub Desktop.
Save oneross/b4679f3993cc9c05f9b6b1db5fd67ed6 to your computer and use it in GitHub Desktop.
Bookmarklet - Copy full contents of dom to clipboard
javascript:(function() {
var container = document.createElement('div');
container.innerHTML = '<div style="position:fixed;top:20%;left:50%;transform:translate(-50%, -50%);background-color:white;padding:20px;border-radius:8px;box-shadow:0 4px 8px rgba(0,0,0,0.2);z-index:1000;"><h3>Select Action:</h3><button id="createBtn">Create</button><button id="addBtn">Add</button></div>';
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'); });
})();
javascript:(function() {
var element = document.createElement('textarea');
element.textContent = document.documentElement.outerHTML;
document.body.appendChild(element);
element.select();
document.execCommand('copy');
document.body.removeChild(element);
alert('DOM copied to clipboard!');
})();
javascript:(function() {
var htmlContent = document.documentElement.outerHTML;
var emailRegex = /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi;
var emails = htmlContent.match(emailRegex);
var uniqueEmails = emails ? Array.from(new Set(emails)) : [];
if (uniqueEmails.length > 0) {
var element = document.createElement('textarea');
element.textContent = uniqueEmails.join('\n');
document.body.appendChild(element);
element.select();
document.execCommand('copy');
document.body.removeChild(element);
alert('Emails copied to clipboard!');
} else {
alert('No emails found!');
}
})();
javascript:(function() {
var action = prompt("Choose action: 'Create' or 'Add'");
if (!action || (action !== 'Create' && action !== 'Add')) {
alert('Invalid action. Please enter either "Create" or "Add".');
return;
}
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!');
}
})();
import networkx as nx
import matplotlib.pyplot as plt
# Assuming org_structure is a list of tuples in the form (manager, managee, 'reports-to')
org_structure = [('person1', 'person2', 'reports-to'), ('person2', 'person3', 'reports-to')]
G = nx.DiGraph()
G.add_edges_from([(x[0], x[1]) for x in org_structure])
pos = nx.spring_layout(G)
nx.draw_networkx_nodes(G, pos)
nx.draw_networkx_edges(G, pos)
nx.draw_networkx_labels(G, pos)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment