I need help with the web version of Anki please

I love to use my chromebook on the go and I’m struggling to be productive with the web version of Anki. Is there a shortcut for cloze deletion brackets in the anki web version? It’s a bit of a headache to add new cards without that feature really.

Using Ankidroid on a chromebook is possible, but not that pretty :slight_smile:

Feels like Ankiweb could use a dire update :frowning:

1 Like

I have just created a bookmarklet that allows you to enclose selected text in the cloze braces({{c<number>::...}}) on AnkiWeb. Here is the code for the bookmarklet:

javascript:var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.createTemplateTagFirstArg=function(a){return a.raw=a};$jscomp.createTemplateTagFirstArgWithRaw=function(a,b){a.raw=b;return a};$jscomp.arrayIteratorImpl=function(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}};$jscomp.arrayIterator=function(a){return{next:$jscomp.arrayIteratorImpl(a)}};$jscomp.makeIterator=function(a){var b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):$jscomp.arrayIterator(a)};
$jscomp.arrayFromIterator=function(a){for(var b,c=[];!(b=a.next()).done;)c.push(b.value);return c};$jscomp.arrayFromIterable=function(a){return a instanceof Array?a:$jscomp.arrayFromIterator($jscomp.makeIterator(a))};
(function(){for(var a=[].concat($jscomp.arrayFromIterable(document.activeElement.textContent.matchAll(/\{{2}c(\d+)::/gmi))).reduce(function(d,e){return Math.max(d,e[1])},0),b=window.getSelection(),c=b.toString().length;/\s/.test(b.toString()[c-1]);)b.modify("extend","backward","character"),--c;document.execCommand("insertHTML",!1,"{{c"+(a+1)+"::"+b.toString()+"}}")})();

If you don’t know how to add a bookmarklet to your browser, try googling terms like add bookmarklet browser.

Demo movie (gif):

Here is the source code of the bookmarklet above, and I compiled this code with Google Closure Compiler Service.

(() => {
    const targetText = document.activeElement.textContent;
    const regexCloze = /\{{2}c(\d+)::/gmi;
    const matches = [...targetText.matchAll(regexCloze)];
    const highest = matches.reduce((accumulator, currentValue) => {
        return Math.max(accumulator, currentValue[1]);
    }, 0);

    // trims trailing whitespaces from selected text
    const sel = window.getSelection();
    let lastCharIndex = sel.toString().length;
    while (/\s/.test(sel.toString()[lastCharIndex - 1])) {
        sel.modify('extend', 'backward', 'character');
        lastCharIndex = lastCharIndex - 1;
    }

    const clozed = `{{c${highest + 1}::${sel.toString()}}}`;
    document.execCommand('insertHTML', false, clozed);
})();
3 Likes