为了对付单位愚蠢的每日工作总结的要求, 写了一个小脚本来导出任务管理器里的内容到剪贴板, 于是接触了一下纯 javascript 实现复制到剪贴板功能
代码先行贴出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| (function() { 'use strict'; if ('your_url'){ var issueList = document.querySelectorAll('.issue-list li'); var taskList = []; for(var i = 0, len = issueList.length; i < len; i++){ var key = issueList[i].getAttribute('data-key'); var title = issueList[i].getAttribute('title'); var task = '已完成: '+key+'-'+title; taskList.push(task); } var text = taskList.join('\n'); var clipboard = document.createElement('textarea'); clipboard.style.width = '100%'; clipboard.style.height = '300px'; clipboard.value = text; var listPanel = document.getElementsByClassName('list-panel')[0]; listPanel.appendChild(clipboard); var today = document.createElement('button'); today.style.width = '100%'; today.innerText = 'Today'; listPanel.appendChild(today); today.addEventListener('click', function () { window.location.href = 'url_to_today'; }); var button = document.createElement('button'); button.style.width = '100%'; button.innerText = 'copy to clipboard'; listPanel.appendChild(button); button.addEventListener('click', function() { clipboard.select(); document.execCommand('copy'); clipboard.blur(); }); } })()
|