Skip to content

Instantly share code, notes, and snippets.

@beshanoe
Created August 28, 2015 15:53
Show Gist options
  • Save beshanoe/9dd4530e725afddfe37c to your computer and use it in GitHub Desktop.
Save beshanoe/9dd4530e725afddfe37c to your computer and use it in GitHub Desktop.
chrome.extension.sendMessage({}, function (response) {
var readyStateCheckInterval = setInterval(function () {
if (document.readyState === "complete") {
clearInterval(readyStateCheckInterval);
console.log("TP Copy extension now works!");
setInterval(function () {
if (!document.getElementById('copybaba')) {
if (document.querySelector('.ui-title')) {
var title = document.querySelector('.ui-title');
var btn = document.createElement('button');
btn.id = 'copybaba';
btn.textContent = 'Copy!';
btn.addEventListener('click', function (el) {
var textArea = document.createElement('textarea');
textArea.style.position = 'absolute';
textArea.style.top = '0';
textArea.style.left = '-10000px';
textArea.value = Array.prototype.slice.call(document.querySelectorAll('.ui-title td')).map(function (el) {
return el.textContent
}).join(' ').replace(/#/, ' #');
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
textArea.parentNode.removeChild(textArea);
});
document.querySelector('.ui-title').insertBefore(btn, title.firstChild);
}
}
}, 500);
}
}, 10);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment