fava

cate or overide

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         fava
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  cate or overide
// @author       You
// @match        http://localhost:5000/**
// @icon         https://www.google.com/s2/favicons?domain=undefined.localhost
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    setTimeout(main, 500);
})();

(function () {
    handleRegx("n(s)a")
})();

function main() {
    let es = document.querySelectorAll("body > article > div > fava-journal > ol > .transaction > p");

    for (let ele of es) {
        // console.log(ele);
        ele.querySelector(".flag").append(createBtn(ele));
    }
}

function createBtn(ele) {
    let btn = document.createElement("div");
    btn.innerText = "[copy]";
    btn.style = `font-size:.30rem;color: blue;`;
    btn.onclick = function () {
        let txt = generateOverideRule(ele);
        navigator.clipboard.writeText(txt).then(r => toast("拷贝成功:\n" + txt, 1000));
    };
    return btn;
}

function generateOverideRule(ele) {
    console.log(ele);
    let time = ele.querySelector(".datecell").innerText;
    let payee = ele.querySelector(".description > .payee").innerText;
    let desc = ele.querySelector(".description ").innerText.replace(payee, "");
    let change = ele.querySelector(".change").innerText.replace(",", "").replace("CNY", "");

    if (payee.indexOf("拼多多") !== -1) {
        let txt = time + ",商品标题," + change;
        return txt;
    } else {
        let txt = time + " .*" + handleRegx(desc) + ".*";
        if (payee) {
            txt = txt + handleRegx(payee) + ".*";
        }
        txt = txt + ": None toWhich";

        // console.log(time);
        // console.log(desc);
        return txt;
    }
}

function handleRegx(text) {
    let rst = text.replace("(", "\\(").replace(")", "\\)").replace(/[\r\n]/g, "");
    // console.log(rst);
    return rst;
}

function toast(msg, duration) {
    duration = isNaN(duration) ? 3000 : duration;
    let m = document.createElement('div');
    m.innerHTML = msg;
    m.style.cssText = `font-size: .32rem;
    color: rgb(255, 255, 255);
    background-color: rgba(0, 0, 0, 0.6);
    padding: 10px 15px;
    margin: 0 0 0 -60px;
    border-radius: 4px;
    position: fixed;
    top: 50%;
    left: 50%;
    width: 300px;
    text-align: center;`;
    document.body.appendChild(m);
    setTimeout(function () {
        let d = 0.5;
        m.style.opacity = '0';
        setTimeout(function () {
            document.body.removeChild(m)
        }, d * 1000);
    }, duration);
}