// ==UserScript== // @name 百度文库文字下载 // @namespace BlueFire // @version 0.2 // @description 添加一个按钮,复制百度文库中的文字 // @author BlueFire // @match *://wenku.baidu.com/view/* // @require http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; let toastDiv = '
'; function Copy(str){ var save = function(e){ e.clipboardData.setData('text/plain', str); e.preventDefault(); } document.addEventListener('copy', save); document.execCommand('copy'); document.removeEventListener('copy',save); } function ShowToast(str){ $('#page-toast-div').remove(); $('body').append(toastDiv); $('#page-toast-span').text(str); var t=setTimeout("$('#page-toast-div').remove();",1500); } $(document).ready(function(){ let downloadBtn = '
复制此页
'; $('.mod.reader-page.complex').each(function(){ $(this).prepend(downloadBtn); let parent = $(this); $(this).find('#reader-copy-text').click(function(){ let str = ""; parent.find('.reader-word-layer').each(function(){ str += this.innerText.replace(/\u2002/g,' '); }); if(str.length > 0){ Copy(str); ShowToast("复制成功"); }else{ ShowToast("复制失败,请等待网页加载"); } }); }); }); })();