Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Duolingo Courses Switcher -- All courses (P1&P2&P3)
// ==UserScript==
// @name Duolingo Courses Switcher -- All courses (P1&P2&P3)
// @version 1.0-juicy_topbarmenu_version
// URL https://gist.github.com/jrikhal/1d3fc649d496ca03a3da0d728e1e8ced
// @author jrikhal
// @run-at document-start
// @match www.duolingo.com
// @match www.duolingo.com/*
// @match www.duolingo.cn
// @match www.duolingo.cn/*
// @match forum.duolingo.com
// @match forum.duolingo.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @grant none
// @description Updates
// From 0.8 to 1.0:
// - MODIFIED (27/04/2019): Making it work on both www.duoling.* and forum.duoling.*, given that Duo uniformized things… but using a new design everywhere… :(
//
// From 0.7.2 to 0.8:
// - MODIFIED (27/01/2019): Fixing code used for Klingon: Duo's switch function doesn't use Duo's own code "tlh" for klingon but its alternative code "kl".
// - MODIFIED (24/03/2019): Adapt to CSS changes on Duo's side.
// - MODIFIED (25/03/2019): Fix "Last WIS" which was not anymore 1. returning the last one and 2. working out of EN and FR interfaces.
// - MODIFIED (04/04/2019): Adapt to change of button's CSS class.
// Finnish's code and localization (into EN and few others) added.
//
// From 0.7.1 to 0.7.2:
// - ADDED (16/01/2019): Adding Latin's language-code.
// - MODIFIED (16/01/2019): Change for incubator's list of courses, instead of www.duolingo.com's list of course (which already included non released courses but... not all of them).
//
// From 0.7 to 0.7.1:
// - ADDED (11/10/2018): Adding Navajo flag's code.
//
// From 0.6.6 to 0.7:
// - FIXED (05/10/2018): Script bugging if a (new) language is not listed in the script's localization functions.
// - ADDED (05/10/2018): Adding "Navajo" in the list.
//
// From 0.6.5 to 0.6.6:
// - ADDED (21/09/2018): Adding Chinese localization of "Italian", "Japanese" and "Korean".
//
// From 0.6.4.4 to 0.6.5:
// - MODIFIED (31/07/2018): Adapting to new search-engine requests' format, to find last WIS.
//
// From 0.6.4.3 to 0.6.4.4:
// - MODIFIED (22/06/2018): Including Duo's Hawaiian flag's code.
//
// From 0.6.4.2 to 0.6.4.3:
// - MODIFIED (21/06/2018): Including Hawaiian's name and code.
//
// From 0.6.4.1 to 0.6.4.2:
// - FIX (16/03/2018): Small update to adapt to (non-dated) change by Duo which was making the dropdownmenu to not resize anymore.
//
// From 0.6.4 to 0.6.4.1:
// - MODIFIED (14/03/2018): Updated Klingon flag's code. (Duo changed it).
//
// From 0.6.3.3 to 0.6.4:
// - MODIFIED (13/02/2018): Added a test in order to not run it on Discussions page (which are still under the old website).
//
// From 0.6.3.2 to 0.6.3.3:
// - MODIFIED (04/02/2018): Cosmetic change to reflect the change of name WIU-> WIS (NHI->RHI).
//
// From 0.6.3.1 to 0.6.3.2:
// - FIXED (15/11/2017): Replaced 'document.getElementsByClassName("_20LC5 OSaWc _2HujR _1ZY-H")' by 'document.getElementsByClassName("_20LC5 _2HujR _1ZY-H")' to adapt to a change by Duo.
//
// From 0.6.3 to 0.6.3.1:
// - FIXED (12/11/2017): Replaced '"zh-CN":"_2gNgd"' by '"zh-CN":"xi6jQ"' and deleted '"zh-¿?":"xi6jQ"' to reflect same changes in Duo's CSS File.
//
// From 0.6.2.cn to 0.6.3:
// - FIXED (11/11/2017): Replaced "_2XSZu" by "_3JPjo" as Duo made this replacement in the CSS file.
//
// From 0.6.2 to 0.6.2.cn:
// - ADDED: Made compatible with www.duolingo.cn (except for the WIU part because this needs access to forums which seems to not be accesible from www.duolingo.cn).
//
// From 0.6.1 to 0.6.2:
// - FIXED: Adapting to another small change by Duolingo (in the drop-down list of courses)
// - FIXED: All results of the WIU_search are now retrieved: '&start=0' became '&start=0&rows=100'
//
// From 0.6 to 0.6.1:
// - ADDED: Code of High Valyrian's flag
//
// From 0.5 to 0.6 (22/06/2017):
// - FIXED: Adapting to new version by Duolingo (including all courses from all interfaces)
// - FIXED: Issue with sublist not clickable.
// - MODIFIED: Reduce by a factor of approx. 10 the time of execution.
//
// From 0.4.2 to 0.5:
// - ADDED: Link to last WIU.
// - MODIFIED: first line ("I speak"+ "(P1+)P2+P3") outside of the scrollable menu.
// - ADDED: More localizations.
//
// From 0.4.1 to 0.4.2:
// - ADDED: More localizations.
// - FIXED: Bengali's localization of Bengali language's name.
//
// From 0.3.2 to 0.4:
// - FIXED: Display of submenus for RTL languages.
//
// From 0.3.1 to 0.3.2:
// - ADDED: Special case of no-BO (similar to special cases of nl-NL and zh-CN).
// - ADDED: Remove of Duo's default "Add new courses" item at the bottom.
// - FIXED: Some display issues fixed.
//
// From 0.3 to 0.3.1:
// - ADDED: More localizations.
//
// From 0.2 to 0.3:
// - ADDED: ScrollBar when the dropdown menu's height is too large (display to be improved: find a way to display sublist outside the main one despite "overflow").
// - MODIFIED: Phase1 courses' alert message now also displayed in Interface language (in addition to the source language of the clicked course).
// - ADDED: More localizations.
//
// From 0.1 to 0.2:
// - ADDED: More localizations
// - ADDED: Spinnin "o" while loading
// - ADDED: Each sublist sorted by target languages names in sublist's source language
// - FIXED: Spining "o" while loading
// - FIXED: Missing alert message on some P1 entries
// - FIXED: Method cto retrieve user_ID changed to work even if the user didn't defined a profile picture
// - Code reorganized and cleaned
// ==/UserScript==
console.log('Start loading "Duolingo Courses Switcher" script.');
//-----------------------------------------------------
//------------------- Localization --------------------
//-----------------------------------------------------
var textapostrophe ="'";
//-------------------------------
//----------- Headers -----------
//-------------------------------
var jeparle=JSON.parse('{"ar":"أنا أتحدث","bn":"আমি বলি","cs":"Můj jazyk","de":"Ich spreche","el":"Μιλάω","en":"I speak","es":"Hablo","fr":"Je parle","hi":"हम बोलते हैं","hu":"Beszélek","id":"Saya berbicara","it":"Parlo","ja":"私が話す言語","ko":"내가 할 줄 아는 언어","nl-NL":"Ik spreek","pl":"Znam","pt":"Falo","ro":"Vorbesc","ru":"Я знаю","ta":"எனக்கு தெரிந்த மொழி","th":"ฉันพูด","tl":"Nagsasalita ako ng","tr":"Bildiğim dil","uk":"Моя мова","vi":"Tôi nói","zh-CN":"我说"}');
var japprends=JSON.parse('{"ar":"أريد أن أتعلم","bn":"আমি শিখতে চাই...","cs":"Co se chcete učit?","de":"Ich will lernen","el":"Θέλω να μάθω","en":"I want to learn","es":"Quiero aprender","fr":"Je veux apprendre","hi":"हम सीखना चाहते हैं","hu":"Ezt a nyelvet szeretném tanulni","id":"Saya ingin belajar","it":"Voglio imparare","ja":"勉強したい言語は","ko":"내가 배우고 싶은 언어는","nl-NL":"Ik wil leren","pl":"Język do nauki","pt":"Quero aprender","ro":"Vreau să învăț","ru":"Я хочу изучать","ta":"அறிய விரும்பும் மொழி","th":"ฉันอยากเรียน","tl":"Gusto kong matuto ng","tr":"Öğrenmek istediğim dil","uk":"Я хочу вчити","vi":"Tôi muốn học","zh-CN":"我想学"}');
var phase1alert=JSON.parse('{"ar":"هذا المنهج لا يزال قيد الإنشاء وليس متاحاً بعد للتعلّم","bn":"এই কোর্সটির কাজ এখনও চলছে। শেখার জন্য এটি পাওয়া যাবে না।","cs":"Tento kurz se nadále buduje a není ještě k dispozici.","de":"Dieser Kurs befindet sich noch im Aufbau.\\nEr ist noch nicht zum Lernen verfügbar.","el":"Αυτό το μάθημα είναι υπό κατασκευή.\\nΔεν είναι ακόμα διαθέσιμο για εκμάθηση.","en":"This course is still under construction.\\nIt is not yet available for learning.","es":"Este curso está en construcción.\\nNo se puede estudiar todavía.","fr":"Ce cours est en construction.\\nIl n'+textapostrophe+'est pas encore possible de travailler dessus.","hi":"इस पाठ्यक्रम पर काम चल रहा है।\\nअभी सीखने के लिये उपलब्ध नहीं है।","hu":"Ez a tanfolyam még fejlesztés alatt áll.\\nTanulásra még nem érhető el.","id":"Kursus ini masih dalam tahap pengembangan.\\nKursus ini belum bisa dipakai untuk belajar.","it":"Questo corso è in costruzione.\\nNon è ancora possibile lavorarci.","ko":"이 코스는 현재 구축 중입니다.\\n아직 학습이 가능하지 않습니다.","pl":"Prace nad tym kursem nadal trwają.\\nNa razie, nie można się go uczyć.","pt":"Este curso está em construção.\\nAinda não está disponível para aprender.","ro":"Acum se lucrează la acest curs.\\nNu se poate învăța această limbă momentan.","ru":"Курс всё ещё в стадии разработки.\\nВ данный момент он недоступен.","ta":"இந்த பயிற்சி கட்டுமானத்தில் உள்ளதால் கற்றுக்கொள்வதற்கு இன்னும் கிடைப்பில் இல்லை.","tl":"Hindi pa tapos ang kursong ito.\\nHindi pa ito puwedeng gamitin para sa pag-aaral.","tr":"Bu kurs hala geliştiriliyor.\\nHenüz öğrenmeye müsait değil.","uk":"Цей курс знаходиться в розробці.\\nВін ще недоступний для вивчення.","zh-CN":"此课程仍在建设中。\\n目前尚不可用于学习。"}');
//current source languages: ar, bn, cs, de, el, en, es, fr, hi, hu, id, it, ja, ko, nl-NL, pa, pl, pt, ro, ru, ta, te, th, tl, tr, uk, vi, zh-CN
//-------------------------------
//------ Languages' names -------
//-------------------------------
var language = {};
language.ar=JSON.parse('{"ar":"العربية","de":"الألمانية","en":"الإنجليزية","es":"الإسبانية","fr":"الفرنسية","sv":"السويدية"}');
language.bn=JSON.parse('{"bn":"বাংলা","de":"জার্মান","en":"ইংরেজি","es":"স্প্যানিশ"}');
language.ca=JSON.parse('{"ca":"Català","de":"Alemany","en":"Anglès","es":"Castellà","fr":"Francès"}');
language.cs=JSON.parse('{"ar":"Arabština","cs":"Česky","de":"Němčina","en":"Angličtina","es":"Španělština","fr":"Francouzština"}');
language.de=JSON.parse('{"cs":"Tschechisch","de":"Deutsch","en":"Englisch","es":"Spanisch","fi":"Finnisch","fr":"Französisch","la":"Latein"}');
language.el=JSON.parse('{"de":"Γερμανικά","el":"Ελληνικά","en":"Αγγλική","es":"Ισπανικά","fr":"Γαλλικά"}');
language.en=JSON.parse('{"ar":"Arabic","bn":"Bengali","ca":"Catalan","cs":"Czech","cy":"Welsh","da":"Danish","de":"German","el":"Greek","en":"English","eo":"Esperanto","es":"Spanish","fi":"Finnish","fr":"French","ga":"Irish","gn":"Guarani (Jopará)","he":"Hebrew","hi":"Hindi","ht":"Haitian Creole","hu":"Hungarian","hv":"High Valyrian","hw":"Hawaiian","id":"Indonesian","it":"Italian","ja":"Japanese","ko":"Korean","la":"Latin","nl-NL":"Dutch","no-BO":"Norwegian (Bokmål)","nv":"Navajo","pa":"Punjabi (Gurmukhi)","pl":"Polish","pt":"Portuguese","ro":"Romanian","ru":"Russian","sv":"Swedish", "sw":"Swahili","ta":"Tamil","te":"Telugu","th":"Thai","tl":"Tagalog","tlh":"Klingon","tr":"Turkish","uk":"Ukrainian","vi":"Vietnamese","yi":"Yiddish","zh-CN":"Chinese"}');
language.eo=JSON.parse('{"de":"Germanaj","el":"Greka","eo":"Esperanto","en":"Angla","es":"Hispana","fr":"Franca"}');
language.es=JSON.parse('{"ar":"Árabe","bn":"Bengalí","ca":"Catalán","cs":"Checo","cy":"Galés","da":"Danés","de":"Alemán","el":"Griego","en":"Inglés","eo":"Esperanto","es":"Español","fi":"Finés","fr":"Francés","ga":"Irlandés","gn":"Guaraní (Jopará)","he":"Hebreo","hi":"Hindi","ht":"Criollo haitiano","hu":"Húngaro","hv":"Alto valyrio","id":"Indonesio","it":"Italiano","ja":"Japonés","ko":"Coreano","la":"Latín","nl-NL":"Neerlandés","no-BO":"Noruego","nv":"Navajo","pa":"Panyabí (Gurmukhi)","pl":"Polaco","pt":"Portugués","ro":"Rumano","ru":"Ruso","sv":"Sueco", "sw":"Suajili","ta":"Tamil","te":"Télugu","th":"Tailandés","tl":"Tagalo","tlh":"Klingon","tr":"Turco","uk":"Ucraniano","vi":"Vietnamita","zh-CN":"Chino"}');
language.fr=JSON.parse('{"ar":"Arabe","bn":"Bengali","ca":"Catalan","cs":"Tchèque","cy":"Gallois","da":"Danois","de":"Allemand","el":"Grec","en":"Anglais","eo":"Espéranto","es":"Espagnol","fi":"Finnois","fr":"Français","ga":"Irlandais","gn":"Guarani (Jopará)","he":"Hébreu","hi":"Hindi","ht":"Créole haïtien","hu":"Hongrois","hv":"Haut valyrien","id":"Indonésien","it":"Italien","ja":"Japonais","ko":"Coréen","la":"Latin","nl-NL":"Néerlandais (Pays-Bas)","no-BO":"Norvégien","nv":"Navajo","pa":"Panjabi (gurmukhi)","pl":"Polonais","pt":"Portugais","ro":"Roumain","ru":"Russe","sv":"Suédois", "sw":"Swahili","ta":"Tamoul","te":"Telougou","th":"Thaï","tl":"Tagalog","tlh":"Klingon","tr":"Turc","uk":"Ukrainien","vi":"Vietnamien","zh-CN":"Chinois"}');
language.gn=JSON.parse('{"de":"Alemañañe'+textapostrophe+'ẽ","en":"Ingleñe'+textapostrophe+'ẽ","eo":"Esperanto","es":"Karaiñe'+textapostrophe+'ẽ","fr":"Hyãsiañe'+textapostrophe+'ẽ","gn":"Avañe'+textapostrophe+'ẽ"}');
language.hi=JSON.parse('{"de":"जर्मन","en":"अंग्रेज़ी","eo":"एस्पेरांतो","es":"स्पेनी","fr":"फ्रांसीसी","gn":"गुआरानी","hi":"हिन्दी"}');
language.hu=JSON.parse('{"de":"német","en":"angol","es":"spanyol","fr":"francia","hi":"hindi","hu":"magyar"}');
language.id=JSON.parse('{"de":"Bahasa Jerman","en":"Bahasa Inggris","es":"Bahasa Spanyol","fr":"Bahasa Perancis","hu":"Bahasa Hungaria","id":"Bahasa Indonesia"}');
language.it=JSON.parse('{"de":"Tedesco","en":"Inglese","es":"Spagnolo","fr":"Francese","id":"Indonesiano","it":"Italiano","la":"latino"}');
language.ja=JSON.parse('{"de":"ドイツ語","en":"英語","es":"スペイン語","fr":"フランス語","ja":"日本語"}');
language.ko=JSON.parse('{"de":"독일어","en":"영어","es":"스페인어","fr":"프랑스어","ja":"일본어","ko":"한국어"}');
language["nl-NL"]=JSON.parse('{"de":"Duits","en":"Engels","es":"Spaans","fr":"Frans","ko":"Koreaans","la":"Latijn","nl-NL":"Nederlands"}');
language.pa=JSON.parse('{"de":"ਜਰਮਨ","en":"ਅੰਗਰੇਜ਼ੀ","es":"ਸਪੇਨੀ","fr":"ਫ਼ਰਾਂਸੀਸੀ","pa":"ਪੰਜਾਬੀ"}');
language.pl=JSON.parse('{"de":"Niemiecki","en":"Angielski","es":"Hiszpański","fr":"Francuski","pl":"Polski"}');
language.pt=JSON.parse('{"de":"Alemão","en":"Inglês","eo":"Esperanto","es":"Espanhol","fr":"Francês","it":"Italiano","pl":"Polonês","pt":"Português"}');
language.ro=JSON.parse('{"de":"Germană","en":"Engleză","es":"Spaniolă","fr":"Franceză","pt":"Portugheză","ro":"Română"}');
language.ru=JSON.parse('{"de":"Немецкий","en":"Английский","es":"Испанский","fr":"Французский","la":"Латы́нь","ro":"Румынский","ru":"Русский","sv":"Шве́дский"}');
language.ta=JSON.parse('{"de":"ஜெர்மன்","en":"ஆங்கிலம்","es":"எசுப்பனியம்","fr":"பிரெஞ்சு","ru":"ரஷியன்","ta":"தமிழ்"}');
language.te=JSON.parse('{"de":"జర్మన్","en":"ఆంగ్ల భాష","es":"స్పానిష్","fr":"ఫ్రెంచి భాష","te":"తెలుగు"}');
language.th=JSON.parse('{"de":"ภาษาเยอรมัน","en":"ภาษาอังกฤษ","es":"ภาษาสเปน","fr":"ภาษาฝรั่งเศส","th":"ภาษาไทย"}');
language.tl=JSON.parse('{"de":"Aleman","en":"Inggles","es":"Kastila","fr":"Pranses","tl":"Tagalog"}');
language.tr=JSON.parse('{"de":"Almanca","en":"İngilizce","es":"İspanyolca","fr":"Fransızca","la":"Latince","ru":"Rusça","tl":"Tagalog","tr":"Türkçe"}');
language.uk=JSON.parse('{"de":"Німецька","en":"Англійська","es":"Іспанська","fr":"Французька","fr":"Французька","tr":"Турецька","uk":"Українська"}');
language.vi=JSON.parse('{"de":"Tiếng Đức","en":"Tiếng Anh","es":"Tiếng Tây Ban Nha","fr":"Tiếng Pháp","vi":"Tiếng Việt"}');
language["zh-CN"]=JSON.parse('{"de":"德语","en":"英语","es":"西班牙语","fr":"法语","it":"意大利语","ja":"日语","ko":"韩语","vi":"越南语","zh-CN":"中文"}');
//=JSON.parse('{"ar":"","bn":"","ca":"","cs":"","cy":"","da":"","de":"","el":"","en":"","eo":"","es":"","fr":"","ga":"","gn":"","he":"","hi":"","ht":"","hu":"","id":"","it":"","ja":"","ko":"","nl-NL":"","no-BO":"","pa":"","pl":"","pt":"","ro":"","ru":"","sv":"", "sw":"","ta":"","te":"","th":"","tl":"","tlh":"","tr":"","uk":"","vi":"","zh-CN":""}');
//current source languages: ar, bn, cs, de, el, en, es, fr, hi, hu, id, it, ja, ko, nl-NL, pa, pl, pt, ro, ru, ta, te, th, tl, tr, uk, vi, zh-CN
//-------------------------------
//------ Duo's flags code -------
//-------------------------------
var flags = [];
flags.ar = "_1ARRD";
flags.bn = "_2TXAL";
flags.ca = "mc4rg";
flags.cs = "_1uPQW";
flags.cy = "_1jO8h";
flags.da = "_1h0xh";
flags.de = "oboa9";
flags.el = "_2tQo9";
flags.en = "_2cR-E";
flags.eo = "pWj0w";
flags.es = "u5W-o";
//flags.fi = "";//fi's code missing
flags.fr = "_2KQN3";
flags.ga = "_1vhNM";
flags.gn = "_24xu4";
flags.he = "_PDrK";
flags.hi = "OgUIe";
//flags.ht = "";//ht's code missing
flags.hu = "_1S3hi";
flags.hv = "YhWo_";
flags.hw = "_38uqs";
flags.id = "_107sn";
flags.it = "_1PruQ";
flags.ja = "_2N-Uj";
flags.ko = "_2lkzc";
flags["nl-NL"] = "_1fajz";
flags["no-BO"] = "_200jU";
flags.nv = "_1Wxyg";
flags.pl = "_3uusw";
flags.pt = "pmGwL";
flags.ro = "_12U6e";
flags.ru = "_1eqxJ";
flags.sv = "_2DMfV";
flags.sw = "_3T1km";
flags.th = "_2oTcA";
flags.tl = "_1q_MQ";
flags.tlh = "_2qMq6";//Old: _6mRM
flags.tr = "_1tJJ2";
flags.uk = "_1zZsN";
flags.vi = "_1KtzC";
//flags.yi = "";//Yiddish's code missing
flags["zh-CN"] = "xi6jQ";//Old: _2gNgd
flags.interrogation = "t-XH-";
flags.Horse = "_3AA1F";
flags.Trefle = "q_PD-"
//"zh-¿?":"xi6jQ" is republic of China flag.
//_3AA1F and q_PD- are false flags
//egg flag's code missing
//-----------------------------------------------------
//-----------------------------------------------------
//-----------------------------------------------------
//Setup
var InterfaceLang = '';
var myALLcourses = Object.create(null);
var ListOfKeysOfmyALLcourses = {};
var generalMenu = {};
var myListOfSrcLang = {};
var LangSrcStyle = '';
var LangTgtStyle = '';
var LangClassP1 = '';
var LangSrcStyleP1 = '';
var LangTgtStyleP1 = '';
var LangClassScript = '';
var myTemplateTgt = {};
var ALLcourses = {};
var request_courses = {};
request_courses=new XMLHttpRequest();
request_courses.open("GET", 'https://incubator.duolingo.com/api/1/courses/list', true);
request_courses.send();
var myrequest = {};
var userdata = {};
var username = '';
var user_ID = -1;
var DuoBasicDomain = 'https://www.duolingo.com';
var userSearchURLtext = '/2017-06-30/users/';
var URLusers = DuoBasicDomain+userSearchURLtext;
var myWISbuttonContainer = htmlToElement('<div class="_1rf8o"><a class="_3H5Yc">…</a></div>');
function wait_userdata_request(myrequest){
if(myrequest.readyState<4){setTimeout(function(){wait_userdata_request(myrequest);},1000);}
else if(myrequest.status === 200){
userdata = JSON.parse(myrequest.response);
username = userdata.username;
user_ID = userdata.id;
retrieveInterfaceLanguage();
}
}
//Note: needs "@run-at" as "document-start", otherwise the first XMLHttpRequest requests are not catched by the script.
(function(xhr) {
// console.log("before any change");
// console.log(XMLHttpRequest.prototype.open);
var open = XMLHttpRequest.prototype.open;
xhr.prototype.open = function() {
if(arguments[1].indexOf(userSearchURLtext)>-1 && arguments[1].indexOf("id")>-1 && arguments[1].indexOf("username")>-1){
myrequest = this;
setTimeout(function(){wait_userdata_request(myrequest);},2000);
XMLHttpRequest.prototype.open = open;
// console.log("after attempt reset");
// console.log(XMLHttpRequest.prototype.open);
}
open.apply(this, arguments);
};
// console.log("after change");
// console.log(XMLHttpRequest.prototype.open);
// console.log("old is");
// console.log(open);
})(XMLHttpRequest);
// var blue_bar_Class = '_6t5Uh';
// var top_blue_barmenu_flag_target_lang_class = "_3viv6 HCWXf";//Old "_3viv6 HCWXf _3PU7E _3JPjo" and older "_3viv6 HCWXf _3PU7E _2XSZu"
// var top_blue_barmenu_loading_o_class = "_3I8Kk";
// var top_blue_barmenu_loading_o_spinning_class = "_3I8Kk _2wMRd";
var TopBarMenu = '_3FqQY _2EZRi';
var TopBarMenu_flag_targetlang_container_class = '_3gtu3 _1-Eux iDKFi';//Not used, just to keep track of elements. --- Several elements share this class: avatar pic's container e.g.
var TopBarMenu_flag_targetlang_class = '_1glj9 _1cYvM hnQEa aFy70';//Not used, just to keep track of elements.
var SwitchDropdownMenuContainer_class = '_3yH6G';
var SwitchDropdownMenuOutter_class = '_3bFAF _2jbOb';//Second (and last) child of SwitchDropdownMenuContainer_class
var SwitchDropdownMenuInner_class = '_3Bh8m';////Not used, just to keep track of elements. --- child of SwitchDropdownMenuOutter_class
var myDropdownMenu = {};//Will be the SwitchDropdownMenuOutter
function SwitchMenuDetection(mutations, observer) {
var i = mutations.length;
while (i--) {
if(mutations[i].addedNodes.length > 0 && mutations[i].addedNodes[0].nodeName === "DIV" && mutations[i].addedNodes[0].className.indexOf(SwitchDropdownMenuContainer_class) > -1 && mutations[i].addedNodes[0].lastChild.className === SwitchDropdownMenuOutter_class){
mutations[i].addedNodes[0].childNodes[1].childNodes[0].appendChild(myWISbuttonContainer);
}
// else if(mutations[i].removedNodes.length > 0 && mutations[i].removedNodes[0].nodeName === "DIV" && mutations[i].removedNodes[0].className.indexOf(SwitchDropdownMenuContainer_class) > -1 && mutations[i].removedNodes[0].lastChild.className === SwitchDropdownMenuOutter_class){
// console.dir("mutations: switch menu hidden.");
// }
}
}
var observer = new MutationObserver(SwitchMenuDetection);
function waitDocumentBody(){
if(document.body === null){setTimeout(function(){waitDocumentBody();}, 50);}
else observer.observe(document.body, {childList: true, subtree: true});
}
waitDocumentBody();
var LangClass = '_2kNgI _1qBnH';//Class lines of (source)language in the switch list
var FlagEndOfClass = ' _3viv6 _3vx2Z _13WHt _3jZoR';//Old " _3viv6 _3vx2Z _1ct7y _3JPjo";
function Localize(myObject,Lang){
return myObject[Lang] || myObject.en;
}
function CheckFlag(myObject,Lang){
if(!(Lang in myObject)){ // if no flag code listed then use the "interrogation mark" flag
return "t-XH-";
} else return myObject[Lang];
}
function getElementContentDimension(element,dimension) {
var styles = window.getComputedStyle(element);
var padding = 0;
if(dimension==='Width'){
padding = parseFloat(styles.paddingLeft) + parseFloat(styles.paddingRight);
} else if(dimension==='Height'){
padding = parseFloat(styles.paddingTop) + parseFloat(styles.paddingBottom);
}
return element.clientWidth - padding;
}
function compareSortTargetLanguage(a, b){return a[2].localeCompare(b[2]);}
function SwitchCourse(SrcLang,TgtLang){
if(SrcLang==='nl-NL'){SrcLang='dn';}//Needed due to inconsistency in Duo's language codes!!!
if(SrcLang==='zh-CN'){SrcLang='zs';}//Needed due to inconsistency in Duo's language codes!!!
if(SrcLang==='no-BO'){SrcLang='nb';}//Needed due to inconsistency in Duo's language codes!!!
if(SrcLang==='tlh'){SrcLang='kl';}//Needed due to inconsistency in Duo's language codes!!!
if(TgtLang==='nl-NL'){TgtLang='dn';}//Needed due to inconsistency in Duo's language codes!!!
if(TgtLang==='zh-CN'){TgtLang='zs';}//Needed due to inconsistency in Duo's language codes!!!
if(TgtLang==='no-BO'){TgtLang='nb';}//Needed due to inconsistency in Duo's language codes!!!
if(TgtLang==='tlh'){TgtLang='kl';}//Needed due to inconsistency in Duo's language codes!!!
var request=new XMLHttpRequest();
// request.open("POST", "https://www.duolingo.com/api/1/me/switch_language", true);
request.open("POST", "https://www.duolingo.com/api/1/me/switch_language", true);
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
request.send('learning_language='+TgtLang+'&from_language='+SrcLang);
WaitForSwitchCourseLoad(request);
}
function WaitForSwitchCourseLoad(request){
if(request.readyState<4){
setTimeout(function(){ WaitForSwitchCourseLoad(request); }, 250);
} else location.reload();
}
function AddInterfaceLanguageToListCourses(IntrfLang){
generalMenu.childNodes[0].setAttribute("style","margin-top:-10px;");
generalMenu.childNodes[0].setAttribute("id","jeparleANDphasesSwitch");
generalMenu.childNodes[0].childNodes[0].innerHTML=Localize(jeparle,InterfaceLang);
generalMenu.childNodes[0].appendChild(document.createElement('li'));
generalMenu.childNodes[0].childNodes[1].setAttribute("class","phasesdisplay");
var PhasesHeader = myTemplateTgt.childNodes[0].cloneNode(true);
PhasesHeader.innerHTML = 'P1+P2+P3';
generalMenu.childNodes[0].childNodes[1].appendChild(PhasesHeader);
var newSrc = document.createElement("li");
var i=0;
while(i<myALLcourses[IntrfLang].length && myALLcourses[IntrfLang][i][1]===1){i++;}
if(i<myALLcourses[IntrfLang].length){
newSrc.setAttribute("class",LangClass);
newSrc.setAttribute("style",LangSrcStyle);
} else {
newSrc.setAttribute("class",LangClass+LangClassP1);
newSrc.setAttribute("style",LangSrcStyle+LangSrcStyleP1);
}
var newSrcFlag = document.createElement('span');
newSrcFlag.setAttribute("class",CheckFlag(flags,IntrfLang)+FlagEndOfClass);
newSrcFlag.setAttribute("style","z-index:2;margin-top: 3px;");
var newDropdown = document.createElement('div');
newDropdown.setAttribute("class","dropdownLANG");
var newDropdownContent = document.createElement('div');
newDropdownContent.setAttribute("class","dropdownLANG-content");
var newTgt = myTemplateTgt.cloneNode(true);
newTgt.childNodes[0].innerHTML=Localize(japprends,InterfaceLang);
newDropdownContent.appendChild(newTgt);
i=0;
var CurrentTgt = {};
while(i<myALLcourses[IntrfLang].length){
CurrentTgt = myALLcourses[IntrfLang][i];
var mySrcLocal = document.getElementsByClassName(CheckFlag(flags,CurrentTgt[0])+FlagEndOfClass)[0];
var mytext = '';
if(!(CurrentTgt[0] in Localize(language,IntrfLang))){
mytext=Localize(language,"en")[CurrentTgt[0]];
} else {
mytext=Localize(language,IntrfLang)[CurrentTgt[0]];
}
if(mytext === undefined){mytext=CurrentTgt[0];}
if(document.body.contains(mySrcLocal)){
mySrcLocal.parentElement.setAttribute("style",LangTgtStyle);
newDropdownContent.appendChild(mySrcLocal.parentElement);
newDropdownContent.lastChild.childNodes[2].textContent=mytext;
} else {
newDropdownContent.appendChild(document.createElement("li"));
if(CurrentTgt[1]>1){
newDropdownContent.lastChild.setAttribute("class",LangClass+LangClassScript);
newDropdownContent.lastChild.setAttribute("style",LangTgtStyle);
} else {
newDropdownContent.lastChild.setAttribute("class",LangClass+LangClassScript+LangClassP1);
newDropdownContent.lastChild.setAttribute("style",LangTgtStyle+LangTgtStyleP1);
}
newDropdownContent.lastChild.setAttribute("SrcLang",IntrfLang);
newDropdownContent.lastChild.setAttribute("TgtLang",CurrentTgt[0]);
newDropdownContent.lastChild.appendChild(document.createElement('span'));
newDropdownContent.lastChild.lastChild.setAttribute("class",CheckFlag(flags,CurrentTgt[0])+FlagEndOfClass);
newDropdownContent.lastChild.appendChild(document.createTextNode(mytext));
}
i++;
}
newDropdown.appendChild(newDropdownContent);
newSrcFlag.appendChild(newDropdown);
newSrc.appendChild(newSrcFlag);
newSrc.appendChild(document.createTextNode(Localize(Localize(language,IntrfLang),IntrfLang)));
myListOfSrcLang.appendChild(newSrc);
}
function AddSrcLanguageToListCourses(SrcLang,position){
var newSrc = {};
newSrc = document.createElement("li");
var i=0;
while(i<myALLcourses[SrcLang].length && myALLcourses[SrcLang][i][1]===1){i++;}
if(i<myALLcourses[SrcLang].length){
newSrc.setAttribute("class",LangClass);
newSrc.setAttribute("style",LangSrcStyle);
} else {
newSrc.setAttribute("class",LangClass+LangClassP1);
newSrc.setAttribute("style",LangSrcStyle+LangSrcStyleP1);
}
var newSrcFlag = document.createElement('span');
newSrcFlag.setAttribute("class",CheckFlag(flags,SrcLang)+FlagEndOfClass);
newSrcFlag.setAttribute("style","z-index:2;margin-top: 3px;");
var newDropdown = document.createElement('div');
newDropdown.setAttribute("class","dropdownLANG");
var newDropdownContent = document.createElement('div');
newDropdownContent.setAttribute("class","dropdownLANG-content");
var newTgt = generalMenu.childNodes[0].cloneNode(true);
newTgt.removeChild(newTgt.childNodes[1]);
newTgt.childNodes[0].innerHTML=Localize(japprends,SrcLang);
newDropdownContent.appendChild(newTgt);
i=0;
var CurrentTgt = {};
while(i<myALLcourses[SrcLang].length){
CurrentTgt = myALLcourses[SrcLang][i];
newDropdownContent.appendChild(document.createElement("li"));
if(CurrentTgt[1]>1){
newDropdownContent.lastChild.setAttribute("class",LangClass+LangClassScript);
newDropdownContent.lastChild.setAttribute("style",LangTgtStyle);
} else {
newDropdownContent.lastChild.setAttribute("class",LangClass+LangClassScript+LangClassP1);
newDropdownContent.lastChild.setAttribute("style",LangTgtStyle+LangTgtStyleP1);
}
newDropdownContent.lastChild.setAttribute("SrcLang",SrcLang);
newDropdownContent.lastChild.setAttribute("TgtLang",CurrentTgt[0]);
newDropdownContent.lastChild.appendChild(document.createElement('span'));
newDropdownContent.lastChild.lastChild.setAttribute("class",CheckFlag(flags,CurrentTgt[0])+FlagEndOfClass);
var mytext = '';
if(!(CurrentTgt[0] in Localize(language,SrcLang))){
mytext=Localize(language,"en")[CurrentTgt[0]];
} else {
mytext=Localize(language,SrcLang)[CurrentTgt[0]];
}
if(mytext === undefined){mytext=CurrentTgt[0];}
newDropdownContent.lastChild.appendChild(document.createTextNode(mytext));
i++;
}
newDropdown.appendChild(newDropdownContent);
newSrcFlag.appendChild(newDropdown);
newSrc.appendChild(newSrcFlag);
newSrc.appendChild(document.createTextNode(Localize(Localize(language,SrcLang),SrcLang)));
myListOfSrcLang.insertBefore(newSrc, myListOfSrcLang.children[position]);
}
function load_style_dropdownLANG(){
//Erase style previously defined by another run of this script.
if(document.head.contains(document.getElementById("mystyle"))){document.getElementById("mystyle").outerHTML='';}
//Retrieve generalMenu's 'real' width
generalMenu.parentElement.setAttribute("style","display:block;");
generalMenu.setAttribute("style","display:block;");
var mywidth = generalMenu.offsetWidth+105;
generalMenu.removeAttribute("style");
generalMenu.parentElement.removeAttribute("style");
//Add the script's dropdown menu style to the page.
var sign_LTR_RTL = 'left';
if(document.getElementsByTagName("html")[0].getAttribute("dir")==="rtl"){sign_LTR_RTL = 'right';}
var content = document.createTextNode('.dropdownLANG {position: relative;top: -15px;left: -15px;display: inline-block;width:'+mywidth+'px;height:65px;text-align: left;vertical-align: middle;padding: 10px 0;} .dropdownLANG-content {display: none;position: absolute;top:0px;'+sign_LTR_RTL+':'+mywidth+'px;border-radius: 10px;background-color: white;box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);padding: 12px 16px;z-index: 1;overflow-x:hidden;overflow-y:auto;} .dropdownLANG:hover .dropdownLANG-content {display: block;} #jeparleANDphasesSwitch {display:flex;justify-content:space-between;} #jeparleANDphasesSwitch > div:nth-child(2) {flex:1;}');
var newScript = document.createElement('style');
newScript.setAttribute("id","mystyle");
newScript.appendChild(content);
document.getElementsByTagName('head')[0].appendChild(newScript);
}
function retrieveInterfaceLanguage(){
var myfields='?fields=fromLanguage';
var request_IntfceLang=new XMLHttpRequest();
request_IntfceLang.open("GET", URLusers+user_ID+myfields, true);
request_IntfceLang.send();
setTimeout(function(){ WaitInterfaceLanguageToLoad(request_IntfceLang); }, 100);
}
function WaitInterfaceLanguageToLoad(request){
if(request.readyState<4){
setTimeout(function(){ WaitInterfaceLanguageToLoad(request); }, 100);
} else {
var userINFO=JSON.parse(request.response);
if(userINFO.fromLanguage==='zh'){InterfaceLang='zh-CN';} else {InterfaceLang=userINFO.fromLanguage;}//Needed due to inconsistency in Duo's language codes!!!
//Animation "Loading WIS"
if(InterfaceLang==='fr'){myWISbuttonContainer.childNodes[0].innerHTML = "Chargement RHI...";} else myWISbuttonContainer.childNodes[0].innerHTML = "Loading WIS...";
LoadingWISanimation(myWISbuttonContainer.childNodes[0]);
var currentTime = new Date();
LoadWISdiscussions(InterfaceLang,currentTime.getFullYear());
// setTimeout(function(){ WaitALLcoursesToLoad(); }, 100);
}
}
function WaitALLcoursesToLoad(){
console.log("WaitALLcoursesToLoad");
if(request_courses.readyState<4){
setTimeout(function(){ WaitALLcoursesToLoad(); }, 100);
} else {
ALLcourses=JSON.parse(request_courses.response).directions;//If list from Incub instead of from www.duolingo.com
////Create our own list
var i=0;
while(i<ALLcourses.length){
if(!(ALLcourses[i].from_language_id in myALLcourses)){ // true if "ALLcourses[i].from_language_id" doesn't exist in myALLcourses
myALLcourses[ALLcourses[i].from_language_id]=[];
}
myALLcourses[ALLcourses[i].from_language_id].push([ALLcourses[i].learning_language_id,ALLcourses[i].phase,Localize(language,ALLcourses[i].from_language_id)[ALLcourses[i].learning_language_id] || ALLcourses[i].learning_language_id]);
i++;
}
////Sort Source languages
ListOfKeysOfmyALLcourses = Object.keys(myALLcourses).sort();
////Sort Target languages for each Source language
for(var k=0;k<Object.keys(myALLcourses).length;k++){
myALLcourses[ListOfKeysOfmyALLcourses[k]].sort(compareSortTargetLanguage);
}
// TO BE PUT BACK LATER !!!!!
// //SETUP
// var top_blue_barmenu_list_general_area_class = "_20LC5 _2HujR _1ZY-H";//Old "_20LC5 OSaWc _2HujR _1ZY-H" Older "_20LC5 FUNrE _3w0_r OSaWc _2HujR _1ZY-H"
// generalMenu = document.getElementsByClassName(top_blue_barmenu_list_general_area_class)[0];
// myListOfSrcLang = generalMenu.childNodes[1];
// myListOfSrcLang.removeAttribute("class");
// myTemplateTgt = generalMenu.childNodes[0].cloneNode(true);
// LangClassScript = " scriptcreated";
// LangClassP1 = " Phase1";
// LangSrcStyle = "height:30px;overflow:visible;";
// LangSrcStyleP1 = "background-color:DimGray;color:white;";
// LangTgtStyle = "font-size:22px;height:35.33px;";
// LangTgtStyleP1 = "background-color:DimGray;color:white;";
// routine();
}
}
function routine(){
//Delete "other source languages" courses from the list
if(myListOfSrcLang.getElementsByClassName("qsrrc").length>0){
while(myListOfSrcLang.lastChild.getAttribute("class")!=="qsrrc"){
myListOfSrcLang.removeChild(myListOfSrcLang.lastChild);
}
}
myListOfSrcLang.removeChild(myListOfSrcLang.lastChild);
//Load new dropdown lists
AddInterfaceLanguageToListCourses(InterfaceLang);
var j=2;
for(var m=0;m<ListOfKeysOfmyALLcourses.length;m++){
if(ListOfKeysOfmyALLcourses[m]!==InterfaceLang){AddSrcLanguageToListCourses(ListOfKeysOfmyALLcourses[m],j);j++;}
}
//Animation "Loading WIS"
if(InterfaceLang==='fr'){generalMenu.lastChild.innerHTML = "Chargement RHI...";} else generalMenu.lastChild.innerHTML = "Loading WIS...";
LoadingWISanimation();
//Load self-defined style
load_style_dropdownLANG();
//Load clicks' actions
$('.dropdownLANG-content').not('.Phase1').on("click", "._2kNgI._1qBnH.scriptcreated:not(.Phase1)", function() {
var localSrcLang = $(this).attr('SrcLang');
var localTgtLang = $(this).attr('TgtLang');
document.getElementsByClassName(top_blue_barmenu_loading_o_class)[0].setAttribute("class",top_blue_barmenu_loading_o_spinning_class);
setTimeout(function(){ SwitchCourse(localSrcLang,localTgtLang); }, 50);
});
$('.dropdownLANG-content').on("click", "._2kNgI._1qBnH.Phase1", function() {
var localSrcLang = $(this).attr('SrcLang');
if(Localize(phase1alert,localSrcLang)===Localize(phase1alert,InterfaceLang)){
alert(Localize(phase1alert,localSrcLang));
} else {
alert(Localize(phase1alert,localSrcLang)+"\n\n"+Localize(phase1alert,InterfaceLang));
}
});
$('#jeparleANDphasesSwitch').on("click", ".phasesdisplay", function() {
var currentdisplay = $(this)[0].childNodes[0].innerHTML;
if(currentdisplay==='P1+P2+P3'){
$(this)[0].childNodes[0].innerHTML='P2+P3';
$('.Phase1').css('display', 'none');
resizeDropDownMenu();
} else {
$(this)[0].childNodes[0].innerHTML='P1+P2+P3';
$('.Phase1').css('display', 'block');
resizeDropDownMenu();
}
});
}
function LoadingWISanimation(myelement){
if(myelement.innerHTML.substr(0,6)==="Charge" || myelement.innerHTML.substr(0,6)==="Loadin"){
if(myelement.innerHTML.substr(myelement.innerHTML.length - 3)==="..."){
myelement.innerHTML = myelement.innerHTML.substr(0,myelement.innerHTML.length - 3);
} else {myelement.innerHTML += '.';}
setTimeout(function(){ LoadingWISanimation(myelement); }, 300);
}
}
function PushWISButton(parametre){
myWISbuttonContainer.childNodes[0].setAttribute("target","_blank");
var mylink = '';
var mydateminus1 = new Date(Date.now());
mydateminus1.setDate(mydateminus1.getDate() - 1);
if(parametre==='error'){
if(InterfaceLang==="fr"){
mylink = 'https://forum.duolingo.com/comment/23529435';//returns the index
myWISbuttonContainer.childNodes[0].innerHTML = "RHI (index)";
} else {
mylink = 'https://forum.duolingo.com/comment/22360462'; //returns the index
myWISbuttonContainer.childNodes[0].innerHTML = "WIS (index)";
}
} else {
mylink = 'https://forum.duolingo.com/comment/'+parametre.id;
if(InterfaceLang==="fr"){
myWISbuttonContainer.childNodes[0].innerHTML = "Dernière RHI ("+parametre.datetime.substr(8, 2)+'/'+parametre.datetime.substr(5, 2)+'/'+parametre.datetime.substr(0, 4)+")";
} else {
myWISbuttonContainer.childNodes[0].innerHTML = "Last WIS ("+parametre.datetime.substr(0, 10).replace('-', '/').replace('-', '/')+")";
}
if(parseDate(parametre.datetime)>mydateminus1){myWISbuttonContainer.childNodes[0].setAttribute("style","color:blue");}
}
myWISbuttonContainer.childNodes[0].setAttribute("href",mylink);
// //Ensure the dropdown menu's height isn't too large
// resizeDropDownMenu();
}
function resizeDropDownMenu(){
generalMenu.parentElement.setAttribute("style","display:block;");
generalMenu.setAttribute("style","display:block;");
var i=0;
var DropDownMenuHeight=0;
while(i<generalMenu.children.length){
DropDownMenuHeight+=generalMenu.childNodes[i].offsetHeight;
i++;
}
var generalMenuClassWithDot = '.'+generalMenu.getAttribute("class").replace(/\s/g, ".");
DropDownMenuHeight+=-(-$(generalMenuClassWithDot).css("margin-top").substring(0,$(generalMenuClassWithDot).css("margin-top").length-2));
DropDownMenuHeight+=-(-$(generalMenuClassWithDot).css("padding-top").substring(0,$(generalMenuClassWithDot).css("padding-top").length-2));
var maxHeight = window.innerHeight-document.getElementsByClassName(blue_bar_Class)[0].offsetHeight-50;//Total height minus the top blue bar's one minus a margin of 50.
var maxHeight2 = maxHeight-(generalMenu.childNodes[0].offsetHeight+generalMenu.childNodes[2].offsetHeight+generalMenu.childNodes[3].offsetHeight)-20;//New 2018/03/16: seems Duo changed something.
if(document.body.contains(generalMenu.childNodes[4])){maxHeight2 -= generalMenu.childNodes[4].offsetHeight;}
if(DropDownMenuHeight>maxHeight){
i=0;
var MainListWidth = getElementContentDimension(generalMenu,'Width');
var MaxSubListWidth = 0;
var MySubList = {};
while(i<document.getElementsByClassName("dropdownLANG-content").length){
MySubList = document.getElementsByClassName("dropdownLANG-content")[i];
MySubList.setAttribute("style","display:block;");
MaxSubListWidth = Math.max(MaxSubListWidth, getElementContentDimension(MySubList.childNodes[1],'Width'));
if(document.getElementsByClassName("dropdownLANG-content")[i].offsetHeight>1.3*maxHeight){
MySubList.setAttribute("style","height:"+(1.3*maxHeight).toString()+"px;");
} else MySubList.removeAttribute("style");
i++;
}
generalMenu.setAttribute("style","display:block;height:"+maxHeight.toString()+"px;width:"+(MainListWidth+MaxSubListWidth+30).toString()+"px;");
//Add a vertical space at the very end of the main list in order for the last submenus to display well.
var MyLastSrcLang = {};
var extraspace = {};
if(myListOfSrcLang.lastChild.getAttribute("class")==="extraspace"){
MyLastSrcLang = myListOfSrcLang.childNodes[myListOfSrcLang.children.length-2].childNodes[0].childNodes[0].childNodes[0];
extraspace = myListOfSrcLang.lastChild;
} else {
MyLastSrcLang = myListOfSrcLang.lastChild.childNodes[0].childNodes[0].childNodes[0];
extraspace = document.createElement('div');
extraspace.setAttribute("class","extraspace");
}
MyLastSrcLang.setAttribute("style","display:block;");
var MyElementStyle = window.getComputedStyle(MyLastSrcLang, null);
var extraspaceHeight = -(-MyElementStyle.getPropertyValue("height").substring(0,MyElementStyle.getPropertyValue("height").length-2));
extraspaceHeight-=-(-MyElementStyle.getPropertyValue("margin-top").substring(0,MyElementStyle.getPropertyValue("margin-top").length-2));
extraspaceHeight-=-(-MyElementStyle.getPropertyValue("margin-bottom").substring(0,MyElementStyle.getPropertyValue("margin-bottom").length-2));
extraspaceHeight-=-(-MyElementStyle.getPropertyValue("padding-top").substring(0,MyElementStyle.getPropertyValue("padding-top").length-2));
extraspaceHeight-=-(-MyElementStyle.getPropertyValue("padding-bottom").substring(0,MyElementStyle.getPropertyValue("padding-bottom").length-2));
extraspaceHeight-=myListOfSrcLang.childNodes[myListOfSrcLang.children.length-2].offsetHeight;
extraspaceHeight-=10;
MyLastSrcLang.removeAttribute("style");
extraspace.setAttribute("style","height:"+extraspaceHeight+"px;");
if(myListOfSrcLang.lastChild.getAttribute("class")!=="extraspace"){myListOfSrcLang.appendChild(extraspace);}
generalMenu.setAttribute("style","height:"+maxHeight.toString()+"px;width:"+(MainListWidth+MaxSubListWidth+30).toString()+"px;");
generalMenu.parentElement.removeAttribute("style");
myListOfSrcLang.setAttribute("style","height:"+maxHeight2.toString()+"px;overflow-x:visible;overflow-y:auto;padding-bottom:5px;position:relative;");
} else {
generalMenu.removeAttribute("style");
generalMenu.parentElement.removeAttribute("style");
}
}
//##### Things for retrieving the WIS' infos
function compare_date(a, b){return new Date(b.datetime) - new Date(a.datetime);}
function LoadWISdiscussions(language,year){
var mysearch = '';
if(language==="fr"){
mysearch = 'Note : Données récupérées le';
} else {
mysearch = 'Note: Data retrieved on';
language = "en";//At the moment we have only FR and EN WIS, so if not FR, the EN one must be returned. And the forum search is (now) returning only the discussion of the interface's language, so we have to force it to return EN ones.
}
var request_WISdiscussions = new XMLHttpRequest();
request_WISdiscussions.open("GET", 'https://forum-api.duolingo.com/api/1/searchables?q='+mysearch+'&page=0&ui_language='+language+'&limit=200', true);//New search-engine
request_WISdiscussions.send();
setTimeout(function(){ WaitLoadWISdiscussions(request_WISdiscussions,language,year); }, 100);
}
function WaitLoadWISdiscussions(request,language,year){
if(request.readyState<4){
setTimeout(function(){ WaitLoadWISdiscussions(request,language,year); }, 100);
} else {
var answer=JSON.parse(request.response);
if(answer.results.length===0){
if(year>2016){LoadWISdiscussions(language,year-1);}
else PushWISButton('error');
} else {
var i=0;
var j=0;
var MyListOfWIS = [];
var myCurrentDoc = {};
i=0;
myCurrentDoc = answer.results[i];
var request_author = {};
var author_ID = {};
while(i<answer.results.length){
myCurrentDoc = answer.results[i];
if(myCurrentDoc.topic_id===651 && myCurrentDoc.title.replace(/<em>/g, '').replace(/<\/em>/g, '').substring(0,46)==="[RHI] Résumé Hebdomadaire de l'Incubateur : 20" && myCurrentDoc.message.replace(/<em>/g, '').replace(/<\/em>/g, '').indexOf("Note : Données récupérées le")>-1){
MyListOfWIS.push(myCurrentDoc);
} else if(myCurrentDoc.topic_id===1 && myCurrentDoc.title.replace(/<em>/g, '').replace(/<\/em>/g, '').substring(0,34)==="[WIS] Weekly Incubator Summary: 20" && myCurrentDoc.message.replace(/<em>/g, '').replace(/<\/em>/g, '').indexOf("Note: Data retrieved on")>-1){
MyListOfWIS.push(myCurrentDoc);
}
i++;
}
MyListOfWIS.sort(compare_date);
PushWISButton(MyListOfWIS[0]);
}
}
}
function parseDate(str_date) {
return new Date(Date.parse(str_date));
}
/**
* @param {String} HTML representing a single element
* @return {Element}
*/
function htmlToElement(html) {
var template = document.createElement('template');
html = html.trim(); // Never return a text node of whitespace as the result
template.innerHTML = html;
return template.content.firstChild;
}
console.log('End loading "Duolingo Courses Switcher" script.');
@jrikhal

This comment has been minimized.

Copy link
Owner Author

jrikhal commented Apr 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.