Anki-Connect-addNotes

本插件通过向页面注入一个功能按钮,来调用Anki-Connect向Anki中添加卡片。

Stan na 02-12-2022. Zobacz najnowsza wersja.

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

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

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         Anki-Connect-addNotes
// @namespace    */*
// @version      0.1
// @description  本插件通过向页面注入一个功能按钮,来调用Anki-Connect向Anki中添加卡片。
// @author       otc
// @match        */*
// @icon         *
// @grant        GM_xmlhttpRequest
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    function addNotes(){
        var mdUrl = ['<a href="',document.URL,'">',document.title,'</a>'].join("")
        var data = JSON.stringify({
            "action": "addNotes",
            "version": 6,
            "params": {
                "notes": [
                    {
                        "deckName": "Default",
                        "modelName": "Basic",
                        "fields": {
                            "Front": mdUrl
                        },
                        "tags": []
                    }
                ]
            }
        });
        GM_xmlhttpRequest({
            method: "post",
            url: 'http://127.0.0.1:8765',
            data: data,
            headers: { "Content-Type":"application/json" },
            onload: function(r) {
                console.log("添加至Anki成功!",r);
            }
        });
    }

    function addButton(){
        let Container = document.createElement('div');
        Container.id = "add-notes-container";
        Container.style.position="fixed"
        Container.style.left="0"
        Container.style.top="0"
        Container.style['z-index']="999999"
        Container.innerHTML =`<button id="addNotes" style="position:absolute; left:30px; top:20px">
  Add2Anki
</button>
`

        document.body.appendChild(Container);

        let button = document.getElementById("addNotes");
        button.onclick=addNotes;
    }
    addButton();
})();