downdoubanpage

豆瓣日記頁添加下載按鈕

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         downdoubanpage
// @namespace    http://tampermonkey.net/
// @version      1.01
// @description  豆瓣日記頁添加下載按鈕
// @author       You
// @match        https://www.douban.com/note/*
// @match        https://www.douban.com/group/topic/*
// @require      https://cdn.jsdelivr.net/npm/[email protected]/FileSaver.min.js
// ==/UserScript==

(function () {
  "use strict";

  //自动下载
  const autodown = true;

  function down() {
    const r = document.querySelector("#link-report");
    if (r) {
      let header = document.querySelector(".note-header");
      if (!header)
        header = document.querySelector(".article > h1:nth-child(1)");
      if (!header) alert("下载失败 header is null");

      var blob = new Blob([header.innerText, "\r\n", r.innerText], {
        type: "text/plain;charset=utf-8",
      });
      saveAs(blob, `${header.innerText}.txt`);
    }
  }

  const t = document.querySelector(".article");
  if (t) {
    let e = document.createElement("button");
    e.id = "TDownBtn";
    e.textContent = "下载";
    e.className = "btn btn-md btn-default";
    e.onclick = down;
    t.parentNode.insertBefore(e, t);
  }

  if (autodown) {
    setTimeout(down, 200);
  }

  // Your code here...
})();