neatreader_web_directory_export_mdfile

使用[NeatReader]网页版读书时,点击键盘字母D下载名为[书名.md]的文件,该文件内容为带有缩进层级和选项框的目录,便于标记书籍已读。

目前為 2023-06-12 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         neatreader_web_directory_export_mdfile
// @license MIT
// @namespace    [email protected]
// @version      1.4
// @description  使用[NeatReader]网页版读书时,点击键盘字母D下载名为[书名.md]的文件,该文件内容为带有缩进层级和选项框的目录,便于标记书籍已读。
// @author       jiazhen
// @require      https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js
// @match        https://www.neat-reader.cn/webapp*
// @icon         https://www.google.com/s2/favicons?domain=tampermonkey.net
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var jq = jQuery.noConflict();
    function prepare(){
        var importJs=document.createElement('script'); //在页面新建一个script标签
        importJs.setAttribute("type","text/javascript"); //给script标签增加type属性
        importJs.setAttribute("src", 'https://cdn.jsdelivr.net/npm/[email protected]');
        var title_list = [];
        //书名
        var book = jq("title").html();
        //目录
        jq("div.book-catalog div").each(function(){
            var title = {};
            title.retract = parseInt(jq(this).attr("class").split(" ")[0].substr("nav-level-".length));
            title.name = jq(this).attr("data-label");
            title_list.push(title);
        });
        //生成json
        //console.log(JSON.stringify(title_list));
        //生成markdown格式文本
        var md_text = "";
        title_list.forEach((item,index,array)=>{
            var i = 0;
            for(var d in item) {
                //debugger;
                if(i==0){
                    md_text+="  ".repeat(item[d]-1)+"- [ ] ";
                }else{
                    md_text+=item[d];
                }
                i++;
            }
            if(index < array.length-1){
                md_text+="\r\n";
            }
        });
        //写入文件
        download(book+".md",md_text);
    }
    function download(filename, text) {
        var element = document.createElement('a');
        element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', filename);
        element.style.display = 'none';
        document.body.appendChild(element);
        element.click();
        document.body.removeChild(element);
    }
    //绑定键盘字母D点击事件
    jq(document).keyup(function(e){
        switch(e.keyCode) {
            case 68:
                prepare();
            return;
        }
    });
})();