// ==UserScript==
// @name Duolingo Search
// @namespace http://tampermonkey.net/
// @version 0.1
// @description A tiny tool making for duolingo exercises better.
// @author Lepturus
// @match *://*.duolingo.com/l*
// @match *://*.duolingo.cn/l*
// @match *://*.duolingo.com/skill*
// @match *://*.duolingo.cn/skill*
// @license MIT
// @icon https://d35aaqx5ub95lt.cloudfront.net/images/duolingo-touch-icon2.png
// @grant none
// @downloadURL none
// ==/UserScript==
(function () {
'use strict';
function copy(e, isHTML = true) {
let obj = document.createElement('input');
document.body.appendChild(obj);
obj.value = isHTML ? e.innerText : e;
obj.select();
document.execCommand('copy', false);
obj.remove();
}
function Duolingo() {
let kws = document.querySelector('div[dir="ltr"]');let txt="";
if (kws) {
let cont = kws.parentNode;
let goGoogle = document.createElement("span");
if (kws.querySelector('ruby')){
kws.querySelectorAll('ruby rb div').forEach(function(tp){
txt += tp.innerText;
})
}
else{
txt = kws.innerText
}
let goUrl = `https://www.google.com/search?q=${txt}%20site%3Aduolingo.com&ie=utf-8`
let goTranslate = `https://translate.google.com/?hl=en&sl=auto&tl=en&text=${txt}`
goGoogle.innerHTML =
`Google Translation `;
if (!cont.textContent.match("Google")) {
cont.appendChild(goGoogle);
}
let cpy = document.getElementById("copyText");
cpy.onclick = function () {
copy(txt,false);
cpy.innerText = "Copied";
window.setTimeout(function () {
cpy.innerText = "Copy it"
}, 1500);
}
}
}
if (/duolingo/.test(document.URL)) {
setInterval(Duolingo, 1500);
}
})();