表格下载工具

功能介绍:1、下载网页中出现的表格到本地

在您安装前,Greasy Fork 希望您知道此脚本声明其包含了一些负面功能。这些功能也许会使脚本作者获利,而不能给您带来任何直接的金钱收益。

作者可从这份脚本获得佣金,例如通过修改链接地址或提供优惠券代码以包含推荐或附属代码。 脚本作者的说明: 此提示为GreasyFork代码规范要求含有查券功能的脚本必须添加,实际使用无任何强制跳转,代码可查,请知悉。

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         表格下载工具
// @version      0.0.3
// @description  功能介绍:1、下载网页中出现的表格到本地
// @author       SvenJiA
// @match      *://zh.wikipedia.org/*
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/xlsx.min.js
// @license      MIT
// @antifeature  referral-link 此提示为GreasyFork代码规范要求含有查券功能的脚本必须添加,实际使用无任何强制跳转,代码可查,请知悉。
// @namespace https://greasyfork.org/users/812577
// ==/UserScript==

window.onload = function(){
  var btn  = document.createElement('button');
  btn.id = 'download_excel';
  btn.innerHTML = '下载表格'
  appendStyle();
  document.body.appendChild(btn);
    var dowloadBtn = document.getElementById('download_excel')
    dowloadBtn.onclick = function(){
      var tables = document.getElementsByTagName("table");
      var wb = XLSX.utils.book_new();
      for(var i = 0; i < tables.length; ++i) {
        var ws = XLSX.utils.table_to_sheet(tables[i]);
        XLSX.utils.book_append_sheet(wb, ws, "Table" + i);
      }
      XLSX.writeFile(wb, "excel.xlsx");
    }
}

function appendStyle(){
  var style = document.createElement("style");
  style.type = "text/css";
  style.appendChild(document.createTextNode(`#download_excel {
  position:fixed;
  right:50px;
  bottom:50px;
  background-color: #f22;
  outline: none;
  border: none;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  color: #fff;
  z-index:999999999;
}
#download_excel:hover{
  cursor: pointer;
  color: #ff2;
  background-color: #F00;
}`));



var head = document.getElementsByTagName("head")[0];

head.appendChild(style);
}