Super Anki

Supercharges AnkiWeb. Currently Supported Functionality - Show card total, done and remaining count per session - Dark Mode

目前為 2023-09-21 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Super Anki
// @version      4
// @grant        none
// @match        https://*.ankiuser.net/**
// @match        https://*.ankiweb.net/decks
// @description  Supercharges AnkiWeb. Currently Supported Functionality - Show card total, done and remaining count per session - Dark Mode
// @namespace    asleepysamurai.com
// @license      BSD Zero Clause License
// ==/UserScript==

function formatCounts(total, remaining){
  const done = total - remaining
  return `${remaining} Left + ${done} Done = ${total}`
}

function addTotalCount(){
  const counts = Array.from(document.querySelectorAll('.count'))
  
  const equals = document.createTextNode(' = ')
  
  const totalCards = counts.reduce((total, thisCount) => total + parseInt(thisCount.innerText), 0)
  const totalCount = counts[0].cloneNode(true)
  totalCount.innerText = formatCounts(totalCards, totalCards)
  totalCount.classList.remove('active', 'new', 'learn', 'review')
  
  const countParent = counts[0].parentElement
  countParent.appendChild(equals)
  countParent.appendChild(totalCount)
  
  const observer = new MutationObserver(() => {
    const restCards = counts.reduce((total, thisCount) => total + parseInt(thisCount.innerText), 0)
    totalCount.innerText = formatCounts(totalCards, restCards)
  })

  counts.forEach(countNode => observer.observe(countNode, { characterData: true, attributes: false, childList: true, subtree: true }));
}

function setupObserver(){
  try{
    init()
  }catch(err){
    setTimeout(() => {
    	setupObserver()
    }, 100)
  }
}

function enableDarkMode(){
  const style = document.documentElement.getAttribute('style')
  document.documentElement.setAttribute('style', `${style || ''}; filter: invert(0.9);`)
}

function updateBranding(){
  document.querySelector('.navbar-brand > span').innerHTML = 'SuperAnki <small><small>v3</small></small>'
}

function init(){
  updateBranding()
  enableDarkMode()
  
  if(window.location.pathname.toLowerCase().startsWith('/study')){
    addTotalCount()
  }
}

setupObserver()