Memrise - Change word definition

Change original word definition to your own. Some words have weird definitions, sometimes you want to translate definition from english to your own language.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @author      Jure 
// @name           Memrise - Change word definition
// @namespace      jure
// @description    Change original word definition to your own. Some words have weird definitions, sometimes you want to translate definition from english to your own language.
// @match          http://www.memrise.com/*garden/*
// @version        1
// @grant 	    GM_deleteValue
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_xmlhttpRequest
// @grant       GM_log
// @grant       GM_openInTab
// @grant       GM_addStyle
// @grant 	    unsafeWindow
// ==/UserScript==

var onLoad = function($) {

    var h = '<div id="addToList" class="btn-group pull-right" style="position:absolute;top:130px;right:0px;">';
    h +=    '  <p><button class="btn btn-icos-active" id="editbutton">';
    h += '    <span class="ico ico-edit"></span>';
    h +=    '    Change translation';
    h += '  </button></p>';
    h += '  <p><button class="btn btn-icos-active" id="delitebutton">';
    h += '    <span class="ico ico-edit"></span>';
    h += '    Delete translation';
    h += '  </button><p>';
    h +=    '</div>';
    unsafeWindow.$("#right-area").append(h);
    document.getElementById("editbutton").addEventListener('click', changeTranslation, true);
    document.getElementById("delitebutton").addEventListener('click', deleteTranslation, true);
    document.getElementById("boxes").addEventListener('DOMSubtreeModified', function () {
        var thing_id = unsafeWindow.MEMRISE.garden.box.box_dict.thing_id;
        var nova=GM_getValue("id" + thing_id, "")
        if (nova == "")
        {
            return;
        }
        var vpr = document.getElementsByClassName("qquestion qtext ")
        if (vpr.length)
        {
            vpr[0].innerHTML = nova;
        }
        try {
            unsafeWindow.$("div.row.column.secondary").find(".row-value")[0].innerHTML = nova;
        }
        catch (err) { }
        //GM_log("sprememba");

    }, true);
   
};
window.onload = onLoad;
function changeTranslation()
{
    var thing_id = unsafeWindow.MEMRISE.garden.box.box_dict.thing_id;
    var c = unsafeWindow.MEMRISE.garden.session_data.things[thing_id].columns;
    var newvalue = prompt("Please enter new translation for: "+c[2].val, GM_getValue("id" + thing_id, c[2].val));
    //console.log(c)
    if (newvalue != null && newvalue != "") {
        GM_setValue("id" + thing_id, newvalue);
        try {
            unsafeWindow.$("div.row.column.secondary").find(".row-value")[0].innerHTML = newvalue;
        }
        catch (err) { }
        var vpr = document.getElementsByClassName("qquestion qtext ")
        if (vpr.length) {
            vpr[0].innerHTML = newvalue;
        }
        
    }   
}
function deleteTranslation() {
    var thing_id = unsafeWindow.MEMRISE.garden.box.box_dict.thing_id;
    var c = unsafeWindow.MEMRISE.garden.session_data.things[thing_id].columns;
    GM_deleteValue("id" + thing_id);
    var newvalue = GM_getValue("id" + thing_id, c[2].val);
    if (newvalue != null && newvalue != "") {
        try {
            unsafeWindow.$("div.row.column.secondary").find(".row-value")[0].innerHTML = newvalue;
        }
        catch (err) { }
        var vpr = document.getElementsByClassName("qquestion qtext ")
        if (vpr.length) {
            vpr[0].innerHTML = newvalue;
        }

    }
}