截取页面长图,网页长图

只为了截页面保存图片,超级简单,截取页面长图,网页长图,截图不会包含本按钮。

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        截取页面长图,网页长图
// @namespace   www.miw.cn
// @description 只为了截页面保存图片,超级简单,截取页面长图,网页长图,截图不会包含本按钮。
// @match       *://*/*
// @grant       none
// @version     1.2
// @author      [email protected]
// @license MIT
//
// @require https://update.greasyfork.org/scripts/457525/1134363/html2canvas%20141.js
// ==/UserScript==
;
const cat_body=()=>{
  html2canvas(document.querySelector('body')).then(canvas=>{
  var picName = document.title || '页面截图';
	var link = document.createElement('a');
    link.download = `${picName}.png`;
    link.href = canvas.toDataURL("image/png");
    link.click();
  });
}
const show_tool=()=>{
  const elements = document.getElementsByTagName('*');
  let zIndex=0;
  for(e of elements){
    let s=window.getComputedStyle(e);
    if(s.zIndex && s.zIndex!='auto') {
      try{
        let t = parseInt(s.zIndex);
        zIndex = t>zIndex?t:zIndex;
      }catch(e){}
    }
  }
  var body = document.body;
  var btn = document.createElement("button");
        btn.textContent = '截长图';
        btn.classList.add('__doit');
        btn.addEventListener('click', function() {
          cat_body();
        });
  btn.style.cssText = `position:fixed;right:0;top:0;z-index:${zIndex+1};`;
  console.log(btn.style.cssText);
  body.parentNode.insertBefore(btn, body);
}

(function () {
  show_tool();

})()
;