Greasy Fork

来自缓存

Greasy Fork is available in English.

Memrise Dynamic Font for Kanji v3

Force the Memrise website to change font dynamicly in choice boxes.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Memrise Dynamic Font for Kanji v3
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Force the Memrise website to change font dynamicly in choice boxes.
// @author       superpawko
// @match        *://www.memrise.com/course/*
// @grant        none
// ==/UserScript==

// Add some fancy fonts first.
function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}
addGlobalStyle('@import url("https://fonts.googleapis.com/css?family=Lato|Playfair+Display")');



$(document).ready(function() {
    MEMRISE.garden.boxes.load = (function() {
        var cached_function = MEMRISE.garden.boxes.load;
        return function() {
            MEMRISE.garden.boxes.activate_box = (function() {
                var cached_function = MEMRISE.garden.boxes.activate_box;
                return function() {
                    var result = cached_function.apply(this, arguments);

                    $("#boxes > div > ol > li").each(function( index ) {

                        var $index = index + 1;
                        var $quote = $("#boxes > div > ol > li:nth-child("+ $index +") > span.val");
                        var $questionTrimed = $.trim($quote.text());
                        var $numWords = $questionTrimed.split(" ").length;

                        var $questionCharNum = $questionTrimed.length;
                        var qsize = (3.3 - Math.sqrt($questionCharNum) * 0.4) * (1.2 - $numWords * 0.1); // Function for text size in REM
                        //console.log("------------ FONT CHANGED");
                        //console.log("idx: " + index + " qtrimmed: " + $questionTrimed + " qtrimmedLENGTH: " + $questionCharNum + " numWords: " + $numWords + " ftsize: " + qsize);

                        if (($numWords <= 4) && ($questionCharNum < 28)) {

                            $("#boxes > div > ol > li:nth-child(" + $index + ") > span.val").css({
                                fontSize: qsize +"rem",
                                'line-height': qsize +"rem"
                            });
                        } else {
                            $("#boxes > div > ol > li").css({
                                'float': 'left',
                                'width': '570px'
                            });
                        }

                        return result;

                    });
                };
            }());

            return cached_function.apply(this, arguments);
        };
    }());
});