百度文库文字下载

添加一个按钮,复制百度文库中的文字

目前为 2018-06-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         百度文库文字下载
// @namespace    BlueFire
// @version      0.1
// @description  添加一个按钮,复制百度文库中的文字
// @author       BlueFire
// @match        *://wenku.baidu.com/view/*
// @require      http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    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);
    }

    $(document).ready(function(){
        let toastDiv = '<div id="page-toast-div" style="margin: 0px auto;background: black;opacity: 0.8;padding: 15px 30px;position: fixed;z-index: 1000;display: none;top: 85%;left: 48%;"><span id="page-toast-span" style="color:white;"></span></div>';
        $('body').append(toastDiv);
        let downloadBtn = '<div style="float:left;padding:10px 20px;background:green;z-index:999;position:relative;top:60px;left:0px;"><a id="reader-copy-text" href="###" style="color:white;font-size:15px;"><b class="ui-btn-btc">复制此页</b></a></div>';
        $('.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);
                    $('#page-toast-span').text("复制成功");
                }else{
                    $('#page-toast-span').text("复制失败,请等待网页加载");
                }
                $('#page-toast-div').css('display','block');
                var t=setTimeout("$('#page-toast-div').css('display','none');",1500);
            });
        });
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址