Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- let t=document.title;
- let l=location.href;
- const dialog = document.createElement('div');
- dialog.style.position = 'fixed';
- dialog.style.top = '0';
- dialog.style.padding = '20px';
- dialog.style.backgroundColor = '#fff';
- dialog.style.boxShadow = '0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23)';
- dialog.style.borderRadius = '0 0 4px 0';
- dialog.style.zIndex = '2147483647';
- dialog.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Helvetica Neue", "Yu Gothic", YuGothic, Verdana, Meiryo, "M+ 1p", sans-serif';
- const textArea = document.createElement('textarea');
- textArea.setAttribute('readonly', '');
- const markdown = document.createElement('span');
- markdown.innerText = 'Markdown';
- markdown.style.padding = '8px';
- markdown.style.fontSize = '16px';
- markdown.style.marginRight = '8px';
- markdown.style.border = '1px solid #ddd';
- markdown.style.borderRadius = '4px';
- const text = document.createElement('span');
- text.innerText = 'Text';
- text.style.padding = '8px';
- text.style.fontSize = '16px';
- text.style.marginRight = '8px';
- text.style.border = '1px solid #ddd';
- text.style.borderRadius = '4px';
- const x = document.createElement('span');
- x.innerText = 'x';
- x.style.padding = '8px';
- x.style.fontSize = '16px';
- x.style.border = '1px solid #ddd';
- x.style.borderRadius = '4px';
- dialog.appendChild(markdown);
- dialog.appendChild(text);
- dialog.appendChild(x);
- document.body.appendChild(dialog);
- const close = (copied) => {
- let timeout;
- if (copied) {
- dialog.innerHTML = 'Copied!'
- dialog.style.transition = 'opacity .4s .4s';
- timeout = 800;
- } else {
- dialog.style.transition = 'opacity .4s';
- timeout = 400;
- }
- dialog.style.opacity = '0';
- if (selected) {
- document.getSelection().removeAllRanges();
- document.getSelection().addRange(selected);
- }
- setTimeout(() => {
- document.body.removeChild(dialog)
- document.body.removeEventListener('click', close);
- }, timeout);
- };
- const click = (title, url, type) => {
- switch(type) {
- case 'markdown': textArea.value = `[${title}](${url})`; break;
- case 'text': textArea.value = `${title}\n${url}`; break;
- }
- dialog.appendChild(textArea);
- textArea.select();
- document.execCommand('copy');
- close(true);
- };
- markdown.addEventListener('click', () => click(t, l, 'markdown'));
- text.addEventListener('click', () => click(t, l, 'text'));
- x.addEventListener('click', () => close(false));
- document.body.addEventListener('click', () => close(false));
- const selected = document.getSelection().rangeCount > 0
- ? document.getSelection().getRangeAt(0)
- : false;
- }
Add Comment
Please, Sign In to add comment