downdoubanpage

豆瓣日記頁添加下載按鈕

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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