downdoubanpage

豆瓣日記頁添加下載按鈕

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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...
})();