Greasy Fork is available in English.

fava

cate or overide

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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