Skip to content

Instantly share code, notes, and snippets.

@xilin
Last active December 7, 2019 08:05
Show Gist options
  • Save xilin/fc2ea8bc151f6a9c248733290b629299 to your computer and use it in GitHub Desktop.
Save xilin/fc2ea8bc151f6a9c248733290b629299 to your computer and use it in GitHub Desktop.
copy desc in leetcode for notion
var l = getEventListeners(document).copy[0];
document.removeEventListener('copy', l.listener, l.useCapture);
// change format so that codes inside `PRE` tag can show correctly in notion
for (let strong of [...document.getElementsByTagName('code')].filter(i => i.parentNode.tagName === 'PRE')) {
const textNode = document.createElement('span');
textNode.innerHTML = strong.innerHTML;
strong.parentNode.replaceChild(textNode, strong);
}
for (let strong of [...document.getElementsByTagName('strong')].filter(i => i.parentNode.tagName === 'PRE')) {
const textNode = document.createElement('span');
textNode.innerHTML = strong.innerHTML;
strong.parentNode.replaceChild(textNode, strong);
}
for (let strong of [...document.getElementsByTagName('em')].filter(i => i.parentNode.tagName === 'PRE')) {
const textNode = document.createElement('span');
textNode.innerHTML = strong.innerHTML;
strong.parentNode.replaceChild(textNode, strong);
}
// select&copy
var elem = document.getElementsByClassName('content__1Y2H')[0];
var range = document.createRange();
range.selectNode(elem);
getSelection().removeAllRanges();
getSelection().addRange(range);
document.execCommand('copy');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment