Membean New Words

script to find how many new words there were within the last two weeks since it doesnt show this already for some reason

目前為 2020-11-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Membean New Words
// @version      0.5
// @description  script to find how many new words there were within the last two weeks since it doesnt show this already for some reason
// @author       You
// @match        *://*.membean.com/dashboard/training-sessions/*
// @match        *://*.membean.com/dashboard/training-history*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        window.close
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @namespace https://greasyfork.org/users/706584
// ==/UserScript==

(function() {
    'use strict';
    var $ = window.jQuery;
    var url=window.location.href;
    var jqNewButton="html>body>div:eq(0)>div>div>div>div>div:eq(1)>main>div>div>div>ul>li:eq(4)>span";
    var jqNewWords="html>body>div:eq(0)>div>div>div>div>div:eq(1)>main>div>div>div>div:eq(4)>div>div>div:eq(0)>div>span>strong>span";
    $( document ).ready(()=>{
        // Your code here...
        if(url.indexOf("training-sessions")>-1){
            var interval=setInterval(()=>{
                if($(jqNewButton).length){//if exists
                    $(jqNewButton).click();
                    var newWords;
                    if($(jqNewWords).text().indexOf("new words")>-1){
                        newWords=parseInt($(jqNewWords).text().split(" new words")[0],10);//i.e. get "10" in "10 new words were introduced in this session." as int
                    }else{
                        newWords=0;
                    }
                    GM_setValue("total",parseInt(GM_getValue("total",0),10)+newWords);
                    GM_setValue("closed",true);
                    window.close();

                    clearInterval(interval);
                }
            },50);
        }

        function twoDigits(n){return n<10? '0'+n:''+n;}
        if(url.indexOf("training-history")>-1){
            //GM_setValue("checkedSessions","{}");
            //GM_setValue("total",0);
            var twbt = new Date();//(two weeks before today)
            var cd=new Date();//(current date)
            var urlParam="";//?startAt=2020-11-03T00:00:00-05:00&endAt=2020-11-17T11:05:22-05:00  encoded: ?startAt=2020-11-03T00%3A00%3A00-05%3A00&endAt=2020-11-17T11%3A05%3A22-05%3A00
            twbt.setDate(twbt.getDate() - (7*2));
            urlParam="?startAt="+twbt.getFullYear()+"-"+twoDigits(twbt.getMonth())+"-"+twoDigits(twbt.getDate())+"T00:00:00-05:00&endAt="+cd.getFullYear()+"-"+twoDigits(cd.getMonth())+"-"+twoDigits(cd.getDate())+"T11:05:22-05:00";
            if(!(url.indexOf(urlParam)>-1)){
                window.location.href="https://membean.com/dashboard/training-history"+urlParam;
            }
            var intrval = setInterval(()=>{
                if($("html>body>div:eq(0)>div>div>div>div>div:eq(1)>main>div>div>div:eq(1)>ul>li:eq(0)>a").length){
                    //makeButton();
                    var i=0;
                    var intervaal=setInterval(()=>{
                        if($("html>body>div:eq(0)>div>div>div>div>div:eq(1)>main>div>div>div:eq(1)>ul>li:eq("+i+")>a").length){
                            if(GM_getValue("closed",true)==true){
                                var linkHref=$("html>body>div:eq(0)>div>div>div>div>div:eq(1)>main>div>div>div:eq(1)>ul>li:eq("+i+")>a").attr("href");
                                var sessionID=linkHref.split("/training-sessions/")[1];//the number after /training-sessions/
                                var checkedSessionsJSON=JSON.parse(GM_getValue("checkedSessions","{}"));
                                if(!(checkedSessionsJSON[sessionID]=="checked")){//if didnt check session already
                                    checkedSessionsJSON[sessionID]="checked";//add current sessionID to JSON
                                    GM_setValue("checkedSessions",JSON.stringify(checkedSessionsJSON));//GM_setValue can not store arrays so stringify and parse are used.
                                    /////////
                                    window.open(linkHref);
                                    GM_setValue("closed",false);
                                    updateText(parseInt(GM_getValue("total",0),10));
                                }
                                    i++;
                                    updateText(parseInt(GM_getValue("total",0),10));
                                }
                            }
                            else{
                                clearInterval(intervaal);
                            }
                        },50);
                        clearInterval(intrval);
                    }
                                              },1000);

                }
                function updateText(a){
                    var jqTHText="html>body>div:eq(0)>div>div>div>div>div:eq(0)>div>div:eq(1)>h1";
                    if($(jqTHText).text!="Training History |\n"+a+" new words in the past 2 weeks"){
                        $(jqTHText).text("Training History |\n"+a+" new words in the past 2 weeks");
                    }
                }
                function makeButton(){
                    var button = document.createElement('button');
                    button.style.top = 0;
                    button.style.left = 0;
                    button.style.width = 50;
                    button.style.height = 50;
                    button.style.position = "fixed";
                    button.innerHTML="click to check words again";
                    document.body.appendChild(button);

                }
            });
        })();