🎺🎺🎺📄百度文库|文库|下载|复制|wenku|VIP|WORD|GPT|文库GPT|文章生成|文档搜索|欢迎反馈|度文库|不定时福利

优化逻辑,重新上线!百度文库,文库,wenku,获取 WORD 格式全文,文字复制,支持下载,导出为 WORD,GPT,文库GPT,文章生成,对话,支持一键复制文字,原创,持续更新百度文库,不定时限时免费;

// ==UserScript==
// @name         🎺🎺🎺📄百度文库|文库|下载|复制|wenku|VIP|WORD|GPT|文库GPT|文章生成|文档搜索|欢迎反馈|度文库|不定时福利
// @version      0.6.5
// @description  优化逻辑,重新上线!百度文库,文库,wenku,获取 WORD 格式全文,文字复制,支持下载,导出为 WORD,GPT,文库GPT,文章生成,对话,支持一键复制文字,原创,持续更新百度文库,不定时限时免费;
// @author       You
// @match        *://wenku.baidu.com/view/*
// @match        *://wenku.baidu.com/tfview/*
// @match        *://百度文库.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require      https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js
// @require      https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jspdf/2.5.1/jspdf.umd.min.js
// @require      https://unpkg.com/docx@7.1.0/build/index.js
// @grant        GM_info
// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_xmlhttpRequest
// @connect      156.238.240.83
// @connect      wkretype.bdimg.com
// @connect      wkrtcs.bdimg.com
// @connect      gpt.soutigf.top
// @connect      wk.baidu.com
// @antifeature  ads      脚本包含搜索文本时,附带的广告
// @antifeature  payment  脚本文字搜索、转化等功能,需对接第三方接口付费
// @namespace    https://greasyfork.org/users/1052410
// ==/UserScript==
$(document).ready(function() {


  let baseUrl = 'http://156.238.240.83/wk';

  // baseUrl = 'http://127.0.0.1:4001';

  let httpClient = GM.xmlHttpRequest ? GM.xmlHttpRequest : (GM_xmlhttpRequest || null);

  // TODO
  // setTimeout(() => {
  //   $('.wk-chat-modal').hide();
  // }, 2000)

  let fkingSetValue = (key, val) => {
    if (GM_setValue) {
      return new Promise(resolve => {
        resolve(GM_setValue(key, JSON.stringify(val)));
      });
    } else if (GM.getValue) {
      return GM.setValue(key, JSON.stringify(val));
    }
  }

  let fkingGetValue = (key) => {
    if (GM_getValue) {
      return new Promise(resolve => {
        resolve(GM_getValue(key, "{}"))
      })
    } else if (GM.getValue) {
      return GM.getValue(key);
    }
  }

  fkingGetValue('FKKEYCODE').then(keyCode => {
    if (keyCode) {
      $('#wkKeyInput').val(JSON.parse(keyCode).key);
    }
  })

  if (!httpClient) {
    alert('警告:文库脚本服务不可用,请勿继续使用,推荐使用谷歌浏览器,并安装油猴');
  }

  var md4sum = pageData.readerInfo.md5sum || '';
  var md4Last = '';
  if (md4sum.indexOf('&rtcs_flag') > -1) {
    let idx = md4sum.indexOf('&rtcs_flag');
    md4Last = md4sum.substring(idx);
  }

  let fkingHttp = (method, url, config) => {
    let options = {
      timeout: 60000,
    }
    if (config) {
      Object.assign(options, config);
    }
    return new Promise((resolve, reject) => {
      httpClient(Object.assign({
        method: method,
        url: url.indexOf('http') > -1 ? url : baseUrl + url,
        onload: function(response) {
          resolve(response);
        },
        onerror: function (err) {
          reject(err);
        },
        ontimeout: function () {
          reject();
        }
      }, options));
    })
  }

  let FKingDocConfigList = {};

  addFKingDom();

  addFKingListener();

  getFKingOtherInfo();

  function addFKingListener() {

    $('#triggerBtn').on('click', () => {
      toggleFKingOuterWrap();
    });


    $('#wkIconClose').on('click', () => {
      toggleFKingOuterWrap();
    });

    // 获取 key
    $('#wkGetCodeBtn').on('click', () => {
      getFKingKeyCode();
    });

    // 全部文字
    $('#wkFullTextBtn').on('click', () => {
      getFKingFullText();
    });

    // Export
    $('#wkExportBtn').on('click', () => {
      getFKingWord();
    });


    // 复制
    $('#wkCopyBtn').on('click', () => {
      if (!navigator.clipboard) {
        alert('此浏览器不支持一键复制')
      } else {
        if (document.getElementById('FKingInnerContent')) {
          navigator.clipboard.writeText(document.getElementById('FKingInnerContent').innerText);
        } else {
          navigator.clipboard.writeText('');
        }
      }
    });
  }

  // 全部内容
  function getFKingFullText() {
    let docInfo = getFKingDocInfo();
    if (!docInfo) {
      hideFKingLoading();
      return;
    };

    showFKingLoading();

    let key = document.getElementById('wkKeyInput').value;
    key = String(key).trim();
    if (!key) {
      alert('请输入测试码');
      document.getElementById('wkKeyInput').focus();
      hideFKingLoading();
      return;
    }

    if (!/^\d+$/.test(key)) {
      alert('请输入正确的测试码');
      document.getElementById('wkKeyInput').focus();
      hideFKingLoading();
      return;
    }

    fkingSetValue('FKKEYCODE', {
      key: key
    });
    if (pageData.readerInfo.md5sum) {
      md4sum = pageData.readerInfo.md5sum;
      if (md4sum.indexOf('&rtcs_flag') > -1) {
        let idx = md4sum.indexOf('&rtcs_flag');
        md4Last = md4sum.substring(idx);
      }
    }

    fkingHttp('GET', `http://wk.baidu.com/view/${docInfo.id}?page=home&fr=wap_home_rec_wap_index_relatedoc&_wkts_=${Date.now()}`, {
      headers: getFKParamsHeaders()
    }).then(res => {
      if (res.status == 200) {
        let docBaic = genFKDocInfo(docInfo.id, res.responseText, md4sum, key);

        fkingHttp('POST', `/start`,{
          headers: {
            "Content-Type": "application/json"
          },
          responseType: 'json',
          data: JSON.stringify(docBaic)
        }).then(res => {
          let docInfoData = JSON.parse(res.responseText);
          if (docInfoData.code != 1) {
            hideFKingLoading();
            alert(docInfoData.msg);
          } else {
            
            FKingDocConfigList = docInfoData.data.docInfo || [];
            $('#FKingInnerContent').scrollTop(0);
            $('#FKingInnerContent').html('');
            let allHtml = genFKIngDocHtml(FKingDocConfigList);
            showFKingNotice(`<div style="font-size: 16px;font-weght: bold;">剩余次数 <em style="color: #dc3545">${docInfoData.data.remainText}</em></div>`);
            showFKingInnerHtml(allHtml)
    
            hideFKingLoading();
          }
        }).catch(err => {
          hideFKingLoading();
          alert('出错了,请稍后再试,错误码:400');
        });
      } else {
        hideFKingLoading();
        alert('出错了,请稍后再试,错误码:300');
      }
    }).catch(_ => {
      hideFKingLoading();
      alert('出错了,请稍后再试,错误码:300');
    })
  }

  // 配置
  function getFKingDocInfo() {
    try {
      var id = pageData.viewBiz.docInfo.showDocId;
      var docType = pageData.viewBiz.docInfo.fileType;
      var docName = pageData.viewBiz.docInfo.title;

      if (!id) {
        showFKingNotice('未获取到文档ID');
        return;
      }

      if (!docType || docType != 'word') {
        // 强化提醒
        showFKingNotice('当前仅支持WORD格式');
        return;
      }

      if (!docName) {
        showFKingNotice('未获取到文档名称');
        return;
      }

      return {
        id: String(id).trim(),
        docType: String(docType).trim(),
        docName: String(docName).trim(),
      }
    } catch {
      showFKingNotice('文档识别出错,请反馈')
      hideFKingLoading();
    }
  }

  // 生成 HTML
  function genFKIngDocHtml(pageConfigList) {
    let allHtml = `<div>`
    pageConfigList.forEach(page => {
      let pageDiv = '<div class="page-wrap">'
      page.children.forEach((para) => {
        let lineHtml = '';
        if (para.tag == 'p') {
          lineHtml += genPHtml(para);
        } else if (para.tag == 'table') {
          lineHtml += genTableHtml(para);
        }
        pageDiv += lineHtml;
      });
      pageDiv += '</div>';
      allHtml += pageDiv;
    });

    return allHtml;
  }

  function genPHtml(para) {
    let pHtml = `<p style="${genStyle(para.style)}">`;
    para.children.forEach((block) => {
      if (block.tag == 'span') {
        if (Array.isArray(block.content)) {
          let spanHtml = '';
          block.content.forEach(ele => {
            let { c = '', t } = ele;
            if (t == 'span') {
              spanHtml += `<span>${c}</span>`
            }
          })
          pHtml += `<span style="${genStyle(block.style)}">${spanHtml}</span>`
        } else {
          pHtml += `<span style="${genStyle(block.style)}">${block.content}</span>`
        }
      } else if (block.tag == 'img') {
        pHtml += `<img style="${genStyle(block.style)}height: auto;" src="${(block.url + md4Last)}" />`
      } else if (block.tag == 'table') {
        
      }
    });
    pHtml+= '</p>'
    return pHtml;
  }

  function genTableHtml(table) {
    let tableHtml = '<table border="1" style="border-collapse: collapse;">';
    table.rows.forEach((row) => {
      let rowHtml = '<tr>';
      row.cells.forEach((cellBox) => {
        let cellHtml = `<td`;
        const { colspan = 0, rowspan = 0 } = cellBox;
        if (colspan) {
          cellHtml += ` colspan="${colspan}"`;
        }
        if (rowspan) {
          cellHtml += ` rowspan="${rowspan}"`;
        }
        cellHtml += '>';
        (cellBox.childList || []).forEach((realCell) => {
          if (realCell.tag && realCell.tag == 'table') {
            cellHtml += genTableHtml(realCell)
          } else if (realCell.tag && realCell.tag == 'p')  {
            cellHtml += genPHtml(realCell)
          }
        });

        cellHtml += "</td>"
        rowHtml += cellHtml;
      });
      rowHtml += `</tr>`
      tableHtml += rowHtml;
    });
    tableHtml += '</table>'
    return tableHtml;
  }

  function genStyle(obj) {
    let styleStr = '';
    Object.keys(obj).forEach(key => {
      if (key == 'height' || key == 'width') {
        styleStr += `${key}: ${obj[key]}px;`;
      } else {
        styleStr += `${key}: ${obj[key]};`;
      }
    })
    return styleStr
  }

  // 生成 word
  async function getFKingWord() {

    if (!FKingDocConfigList.length) {
      alert('请先获取全文');
      return;
    }


    let b = confirm('导出 WORD 为最新的测试功能,不够完善,感谢理解。有图片的文档,速度慢。WORD 将会导出到浏览器默认下载地址,清注意查看。确认开始导出么?');
    if (!b) {
      return;
    }

    showFKingLoading('有图片的导出会比较慢,请耐心等待。。。');

    let paragraphList = [];
    let pageLen = FKingDocConfigList.length;
    for (let i = 0; i < pageLen; i++) {
      let page = FKingDocConfigList[i];
      let lineLen = page.children.length;
      for (let j = 0; j < lineLen;j++) {
        let line = page.children[j]
        const { tag } = line;
        if (tag == 'p') {
          paragraphList.push(await genParagraph(line));
        } else if (tag == 'table') {
          paragraphList.push(await genTable(line));
        }
      }
    }

    setTimeout(() => {
      const doc = new docx.Document({
        sections: [{
            children: paragraphList,
          },
        ]
      });
      docx.Packer.toBlob(doc).then(blob => {
        let docInfo = getFKingDocInfo();
        if (typeof saveAs !== 'undefined' ) {
          saveAs(blob, `${docInfo.docName || 'test'}.docx`);
        } else {
          var a = document.createElement("a");
          a.href = URL.createObjectURL(blob);
          a.download = docInfo.docName || 'test.docx';
          a.click();
        }

        hideFKingLoading();
      }).catch(err => {
        alert('导出 WORD 出错了,请重试')
        hideFKingLoading();
      })
    }, 1000)  
  }

  async function genParagraph(pData) {
    const { children = [], style = {} } = pData;

    let config = genParaStyleConfig(style);
    let ch = [];
    let len = children.length;
    for (let i = 0; i< len;i++) {
      let block = children[i]
      let { tag } = block;
      if (tag == "span") {
        ch.push(genTextRun(block));
      } else if (tag == 'img') {
        try {
          ch.push(await genImageRun(block));
        } catch {}
      }
    }
    config.children = ch;
    return new docx.Paragraph(config);
  }

  const genTextRun = (spanData) => {
    let { style, content } = spanData;
    let config = genSpanStyleConfig(style);
    let txt = '';
    if (Array.isArray(content)) {
      content.forEach(el => {
        txt += (el.c || '')
      });
    } else {
      txt = content
    }
    config.text = txt;
    return new docx.TextRun(config)
  }

  const genImageRun = (imgData) => {
    return new Promise((resolve, reject) => {
      const { url, style = {} } = imgData;
      const { width, height} = style;
      fkingHttp('GET', url + md4Last, {
        responseType: 'blob'
      }).then(res => {
        const image = new docx.ImageRun({
          data: res.response,
          transformation: {
            width: Number(width),
            height: Number(height),
          }
        });
        resolve(image)
      }).catch(err => {
        reject()
        console.log(err);
      })
    })
  }

  const genParaStyleConfig = (style) => {

    let config = {
      children: [],
      spacing: {
        before: 5,
        after: 5
      }
    }
  
    if (style['text-align']) {
      config.alignment = makeAlignment(style['text-align'])
    }
  
    if (style['padding-top']) {
      config.spacing.before = Number((style['padding-top']).replace('px', '').replace('em', '')) * 1.6
    }  
    return config;
  }

  const genSpanStyleConfig = (style) => {
    let config = {
      text: ''
    };

  
    if (style['font-size']) {
      // config.size = convertMillimetersToTwip(Number((allStyle['font-size']).replace('px', '')) * 0.2644)
      config.size = Number((style['font-size']).replace('px', '')) * 1.6
    }
    if (style['font-family']) {
      config.font = style['font-family']
    }
  
    // if (allStyle['font-weight'] && Number(allStyle['font-weight']) > 600) {
    //   config.bold = true
    // }
  
    return config;
  }

  const makeAlignment = (align) => {
    if (align == 'center') {
      return docx.AlignmentType.CENTER
    } else if (align == 'justify') {
      return docx.AlignmentType.JUSTIFIED
    }
  }

  async function genTable (tableData) {
    let tbRows = [];
    let rowsLen = tableData.rows.length;
    for (let i = 0; i < rowsLen; i++) {
      let trData = tableData.rows[i];
      let tdLen = trData.cells.length;
      let rowChildren = [];
      for (let j = 0; j < tdLen; j++) {
        let tdData = trData.cells[j];
        const { colspan = 0, rowspan = 0, childList = []} = tdData;
        let tdParaList = [];
        for (let m = 0; m < childList.length; m++) {
          let p = childList[m];
          tdParaList.push(await genParagraph(p));
        }
        let cellConfig = {
          children: tdParaList
        } 
        if (colspan) {
          //@ts-ignore
          cellConfig.columnSpan = colspan;
        }
        if (rowspan) {
          //@ts-ignore
          cellConfig.rowSpan = rowspan;
        }
        rowChildren.push(new docx.TableCell(cellConfig))
      }
      tbRows.push(
        new docx.TableRow({
          children: rowChildren
        })
      )
    }
    return new docx.Table({
      rows: tbRows
    });
  }

  // 获取 key
  function getFKingKeyCode() {
    if (!httpClient) {
      alert('警告:文库脚本服务不可用,请勿继续使用,推荐使用谷歌浏览器,并安装油猴');
      return;
    }
    fkingHttp('GET', `/key/create`).then(res => {
      let data = JSON.parse(res.responseText);
      if (data.url) {
        window.open(data.url, '_blank');
      }

      if (data.keyStr) {
        showFKingNotice(data.keyStr);
      }

      if (data.otherInfo) {
        showFKingInnerHtml(data.otherInfo);
      }
    }).catch(err => {});
  }

  // 其他信息
  function getFKingOtherInfo() {
    fkingHttp('GET', `/other`).then(res => {
      let data = JSON.parse(res.responseText);
      if (data.code == 1) {
        if (data.fuli) {
          $('#lineWrap').append($(data.fuli));
        }
        if (data.prompt) {
          $('#lineWrap').append($(data.prompt));
        }
        if (data.qUrl) {
          let $img = $(document.createElement('img'));
          $img.attr('src', data.qUrl);
          $img.css('height', data.qUrlHeight);
          $img.css('width', data.qUrlWidth);
          $('#FKQrBox').append($img);
        }
      }
    }).catch(err => {
      console.log(err)
    })
  }

  function showFKingLoading(msg) {
    $('#ovMsg').text(msg || '正在搜索,预计需要15秒钟...');
    $('#wkOverlay').show(1);
  }

  function hideFKingLoading() {
    $('#wkOverlay').hide();
  }

  function showFKingNotice(content) {
    $('#FKINGOUTERWRAP #FKINGWKMsg').html(content || '').show();
    $('#FKINGOUTERWRAP #FKINGWKMsg').css('font-weight', 'bold');
    $('#FKINGOUTERWRAP #FKINGWKMsg').css('border', 'dashed #dc3545 1px');
  }

  function showFKingInnerHtml(content) {
    $('#FKINGOUTERWRAP #FKingInnerContent').html(content || '').show();
  }

  function toggleFKingOuterWrap() {
    if ($('#FKINGOUTERWRAP').css('right') == '-1000px') {
      $('#FKINGOUTERWRAP').animate({right: '0px'}, 'fast');
    } else {
      $('#FKINGOUTERWRAP').animate({right: '-1000px'}, 'fast');
    }
  }

  function addFKingDom() {
    $(`<style type='text/css'>
      .FKINGOUTERWRAP {
        position: fixed;z-index: 9000;right: -1000px;top: 66px;width: 1000px;box-sizing: border-box;border: 1px solid #0075ff;border-right: none;
      }
      .FKINGOUTERWRAP .wk-icon-close {
        position: absolute;right: -14px;top: -12px;height: 36px;width: 36px;cursor: pointer;
      }
      .FKINGOUTERWRAP .wk-overlay {
        position: absolute;left: 0;top: 0;right: 0;bottom: 0;background-color: rgba(255,255,255,0.6);z-index: 9990;text-align: center;padding-top: 220px;color: #dc3545;display: none;
      }

      @keyframes spinner-border {
        100% { transform: rotate(360deg) };
      }

      .FKINGOUTERWRAP .wk-overlay .icon-loading {
        margin: 0 auto 12px auto; width: 32px; height: 32px; border: solid #dc3545 3px; border-radius: 50%;border-right-color: transparent; animation: spinner-border 0.75s linear infinite;
      }
      .FKINGOUTERWRAP .wk-overlay .txt {
        font-size: 18px; font-weight: bold;
      }
      .FKINGOUTERWRAP .trigger-btn {
        position: absolute;top: 50%;left: -50px;height: 200px;width: 50px;transform: translateY(-100px);background-color: #dc3545;border-top-left-radius: 10px;border-bottom-left-radius: 10px;color: #fff;font-size: 20px;cursor: pointer;text-align: center;padding: 24px 10px;box-sizing: border-box;
      }
      .FKINGOUTERWRAP .trigger-btn svg {
        margin-bottom: 5px;
      }
      .FKINGOUTERWRAP .top-content {
        height: 80px;display: flex;background-color: #fff;background-image: url(https://edu-wenku.bdimg.com/v1/pc/aigc/ai-chat-bg-1683892068238.png);background-repeat: no-repeat;background-size: 100% 100%;
      }
      .FKINGOUTERWRAP .top-content .line-wrap {
        flex: 1; display:flex; flex-direction: column; justify-content: space-between; position: relative; font-size: 12px;
      }
      .FKINGOUTERWRAP .top-content .line {
        position: relative; display: flex; align-items: center; flex: 1; border-bottom: 1px dashed #dee2e6; padding:0 12px 0 6px;
      }
      .FKINGOUTERWRAP .top-content .line .fkwk-tab-wrap {
        display: flex;
      }
      .FKINGOUTERWRAP .top-content .line .fkwk-tab-wrap .fkwk-tab {
        position: relative; top: 2px; width: 80px; height: 36px; line-height: 36px; font-size: 14px; text-align: center; cursor: pointer;
      }
      .FKINGOUTERWRAP .top-content .line .fkwk-tab-wrap .fkwk-tab.fkactive {
        border: solid #0075ff 1px; border-bottom: none; background-color: #fff; border-top-left-radius: 8px;border-top-right-radius: 8px; color: #4e6ef2;
      }
      .FKINGOUTERWRAP .top-content .line:last-child {
        border: none;
      }
      .FKINGOUTERWRAP .top-content .key-input {
        width: 212px; height: 24px; line-height: 24px;border: solid 1px #dee2e6; padding: 0 10px; transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
      }
      .FKINGOUTERWRAP .btn {
        height: 26px; line-height: 24px; box-sizing: border-box;padding: 0 6px;font-size: 12px;text-align: center;;color: #fff; cursor: pointer; width: auto; min-width: 100px; letter-spacing: 1px;
      }
      .FKINGOUTERWRAP .btn .btn-icon {
        width: 12px; height: 12px; vertical-align: middle;
      }
      .FKINGOUTERWRAP .top-content .btn.full-text {
        margin-right: 12px; background-color: #0d6efd;border: 1px solid #0d6efd;border-top-right-radius: 4px;border-bottom-right-radius: 4px;
      }
      .FKINGOUTERWRAP .top-content .btn.key-btn {
        background-color: #dc3545; border: 1px solid #dc3545; color: #fff; border-top-left-radius: 4px;border-bottom-left-radius: 4px; font-weight: 600;
      }
      .FKINGOUTERWRAP .top-content .btn.wk-export-btn {
        line-height: 26px; background-color: #ffc107; border: none;border-top-left-radius: 4px;border-bottom-left-radius: 4px; color: #000;
      }
      .FKINGOUTERWRAP .top-content .btn.wk-copy-btn {
        line-height: 26px; background-color: #198754; border: none; color: #fff;border-top-right-radius: 4px;border-bottom-right-radius: 4px;
      }
      .FKINGOUTERWRAP .top-content .qr-box {
        padding: 8px 8px;border-left: dashed 1px #dee2e6;
      }
      .FKINGOUTERWRAP .top-content .qr-name {
        font-size: 18px; margin-bottom: 4px;text-align: center;
      }
      .FKINGOUTERWRAP .top-content .qr-box img {
        width: 64px; height: 64px;
      }
      .FKINGOUTERWRAP .wk-content-wrap {
        position:relative;height: 359px;color:#222;border-bottom-left-radius: 10px;border-top: dashed 1px #dee2e6;
      }
      .FKINGOUTERWRAP .wk-content-wrap .wk-inner-content {
        box-sizing:border-box; height: 100%; overflow: scroll; background-color: #fff; padding: 12px;
      }
    </style>`).appendTo("head");
    var wrap = $(`
      <div id="FKINGOUTERWRAP" class="FKINGOUTERWRAP">
        <div id="wkOverlay" class="wk-overlay">
          <div class="icon-loading"></div>
          <div id="ovMsg" class="txt">正在搜索,预计需要15秒钟...</div>
        </div>
        <svg xmlns="http://www.w3.org/2000/svg" id="wkIconClose" class="wk-icon-close" viewBox="0 0 1024 1024" height="1em" width="1em">
          <path d="M685.4 354.8c0-4.4-3.6-8-8-8l-66 .3L512 465.6l-99.3-118.4-66.1-.3c-4.4 0-8 3.5-8 8 0 1.9.7 3.7 1.9 5.2l130.1 155L340.5 670a8.32 8.32 0 0 0-1.9 5.2c0 4.4 3.6 8 8 8l66.1-.3L512 564.4l99.3 118.4 66 .3c4.4 0 8-3.5 8-8 0-1.9-.7-3.7-1.9-5.2L553.5 515l130.1-155c1.2-1.4 1.8-3.3 1.8-5.2z"/>
          <path d="M512 65C264.6 65 64 265.6 64 513s200.6 448 448 448 448-200.6 448-448S759.4 65 512 65zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"/>
        </svg>

        <div id="triggerBtn" class="trigger-btn">
          <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 1024 1024" height="1em" width="1em">
            <path d="M904 160H120c-4.4 0-8 3.6-8 8v64c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-64c0-4.4-3.6-8-8-8zm0 624H120c-4.4 0-8 3.6-8 8v64c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-64c0-4.4-3.6-8-8-8zm0-312H120c-4.4 0-8 3.6-8 8v64c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-64c0-4.4-3.6-8-8-8z" fill="#fff"/>
          </svg>文库助手
        </div>
        <div id="topContent" class="top-content">
          <div id="lineWrap" class="line-wrap">
            <div class="line">
              <input class="key-input" id="wkKeyInput" placeholder="请输入测试码" maxlength="24" type="text" />
              <button id="wkGetCodeBtn" class="btn key-btn">
              <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512" class="btn-icon">
              <title></title>
              <g id="icomoon-ignore">
              </g>
              <path d="M352 0c-88.368 0-160 71.632-160 160 0 10.016 0.935 19.808 2.688 29.312l-194.688 194.688v96c0 17.68 14.32 32 32 32h32v-32h64v-64h64v-64h64l41.528-41.528c17 6.159 35.344 9.527 54.472 9.527 88.368 0 160-71.632 160-160s-71.632-160-160-160zM399.937 160.056c-26.505 0-48-21.495-48-48s21.495-48 48-48 48 21.495 48 48-21.488 48-48 48z"></path>
              </svg>
              获取测试码</button>
            </div>
            <div class="line" style="border-bottom: solid #0075ff 1px;">
              <div class="fkwk-tab-wrap">
                <div id="fkpanelOne" class="fkwk-tab fkactive">文章获取</div>
              </div>
            </div>
          </div>
          <div id="FKQrBox" class="qr-box">
          </div>
        </div>
        <div id="fkPanelOneContent">
          <div class="top-content" style="height: auto;">
            <div class="line-wrap" style="flex-direction: row; height: 40px;">
              <div id="otherBtns" class="line">
              <button id="wkFullTextBtn" class="btn full-text">获取全文文字</button>
              <button id="wkExportBtn" class="btn wk-export-btn">
                <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512" class="btn-icon">
                  <title></title>
                  <g id="icomoon-ignore">
                  </g>
                  <path d="M256 288l128-128h-96v-128h-64v128h-96zM372.363 235.636l-35.87 35.871 130.040 48.493-210.533 78.509-210.533-78.509 130.040-48.493-35.871-35.871-139.636 52.364v128l256 96 256-96v-128z"></path>
                </svg>
                导出为WORD
              </button>
              <button id="wkCopyBtn" class="btn wk-copy-btn">一键复制</button>
              (获取全文后才有效)
              </div>
              <div id="FKINGWKMsg" class="line"></div>
            </div>
          </div>
          <div class="wk-content-wrap">
            <div id="FKingInnerContent" class="wk-inner-content"></div>
          </div>
        </div>
      </div>
    `);
    $('html').append(wrap);
  }

  function getFKParamsHeaders() {
    return {
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
      "Accept-Encoding": "gzip, deflate, br",
      "Accept-Language": "zh-CN,zh;q=0.9",
      "Cache-Control": "max-age=0",
      "Connection": "keep-alive",
      "Host": "wk.baidu.com",
      "Sec-Fetch-Dest": "document",
      "Sec-Fetch-Mode": "navigate",
      "Sec-Fetch-Site": "none",
      "Sec-Fetch-User": "?1",
      "Upgrade-Insecure-Requests": 1,
      "User-Agent" : getFKUA()
    }
  }

  function getFKUA() {
    let mobileUAList = [
      {
        ua: "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.3",
        pct: 21.67,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Mobile Safari/537.3",
        pct: 21.2,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Mobile/15E148 Safari/604.",
        pct: 15.08,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.",
        pct: 4.24,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Mobile/15E148 Safari/604.",
        pct: 3.3,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.2 Mobile/15E148 Safari/604.",
        pct: 2.83,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 11; moto e20 Build/RONS31.267-94-3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.227 Mobile Safari/537.3",
        pct: 2.36,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/115.0.5790.130 Mobile/15E148 Safari/604.",
        pct: 1.88,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.",
        pct: 1.88,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.3",
        pct: 1.41,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 15_7_8 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.6 Mobile/15E148 Safari/604.",
        pct: 1.41,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/114.0.5735.124 Mobile/15E148 Safari/604.",
        pct: 1.41,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.1 Mobile/15E148 Safari/604.",
        pct: 0.94,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-G780G) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.94,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 9; Redmi Note 8T Build/PKQ1.190616.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.119 Mobile Safari/537.3",
        pct: 0.94,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-M135F) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.94,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-G990B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.94,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 15_7_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.4 Mobile/15E148 Safari/604.",
        pct: 0.94,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/113.0.5672.69 Mobile/15E148 Safari/604.",
        pct: 0.94,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 15_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Mobile/15E148 Safari/604.",
        pct: 0.94,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/274.0.549390226 Mobile/15E148 Safari/604.",
        pct: 0.94,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Mobile Safari/537.36",
        pct: 0.82,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36",
        pct: 0.71,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 8.1.0; MI 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36 (compatible; Google-Read-Aloud; +https://support.google.com/webmasters/answer/1061943",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-A546B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/274.0.549390226 Mobile/15E148 Safari/604.",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Android 12; Mobile; rv:109.0) Gecko/115.0 Firefox/115.",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Mobile/15E148 Safari/604.",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/115.0 Firefox/115.",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/115.1  Mobile/15E148 Safari/605.1.1",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Mobile/15E148 Safari/604.",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 11; SM-A326B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.85 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 11; moto g(8) power) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-A536B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-A528B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-S911B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-S906B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/21.0 Chrome/110.0.5481.154 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-G781B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-G980F) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SAMSUNG SM-S901B) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/22.0 Chrome/111.0.5563.116 Mobile Safari/537.3",
        pct: 0.47,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Mobile/15E148 Safari/604.1",
        pct: 0.35,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.1 Mobile/15E148 Safari/604.1",
        pct: 0.35,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1",
        pct: 0.35,
      },
      {
        ua: "Mozilla/5.0 (Linux; arm_64; Android 13; SM-A336E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 YaSearchBrowser/23.71.1 BroPP/1.0 YaSearchApp/23.71.1 webOmni SA/3 Mobile Safari/537.36",
        pct: 0.24,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Mobile Safari/537.36",
        pct: 0.12,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Mobile/15E148 Safari/604.1",
        pct: 0.12,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Mobile/15E148 Safari/604.1",
        pct: 0.12,
      },
      {
        ua: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/115.0.5790.130 Mobile/15E148 Safari/604.1",
        pct: 0.12,
      },
      {
        ua: "Mozilla/5.0 (Linux; Android 13; SM-S9080) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36",
        pct: 0.12,
      },
    ];
    let random = Math.floor(Math.random() * 52);
    return mobileUAList[random].ua;
  }

  function genFKDocInfo(id, htmlStr, md4sum, key) {
    const noBlankStr = htmlStr.replace(/\s/g, '');

    const start = noBlankStr.indexOf('{"docInfoFromApi":') + 18;
    const end = noBlankStr.indexOf(',"antiClass":');

    const allInfo = JSON.parse(noBlankStr.substring(start, end));

    const {
      docInfo: {
        docTitle,
        docType
      },
      readerParam: {
        pageNumTotal,
        md5sum,
        rsign,
        bucketNum,
      }
    } = allInfo;

    return {id, docTitle, docType, pageNumTotal, md5sum, md4sum, rsign, bucketNum, key}
  }

})