Roukys / HHauto

GNU General Public License v3.0
45 stars 44 forks source link

Enhancement : manual Timer reset #147

Closed cossname closed 3 years ago

cossname commented 3 years ago

Design:

+   '<div style="border: 1px dotted;">'
+   '<span>'+   'Reset Timers' /*getTextForUI("timerReset","elementText")*/+    '</span>'
+   '<div style="display:flex;flex-direction:row;">'
+   '<div class="tooltip"><span class="tooltiptext">'+  getTextForUI("timerResetButton", "tooltip")+    '</span><label class="myButton" id="timerResetButton" style="border-radius: 2px;">'+    'Reset Timer' /*getTextForUI("timerResetButton","elementText")*/+   '</label></div>'
+   '<div class="tooltip"><span class="tooltiptext">'+  getTextForUI("timerResetSelector", "tooltip")+  '</span><select id="timerResetSelector"></select></div>'
+   '<span id="timerLeftTime">00:00:00</span>'
+   '</div>'
+   '</div>'

Options:

 // Add Timer reset options //changed
let timerOptions = document.getElementById("timerResetSelector");
let TimersList = ["nextMissionTime", "minPowerPlacesTime", "maxPowerPlacesTime", "nextContestTime", "nextSalaryTime", "nextChampionTime", "nextClubChampionTime", "nextSeasonTime", "nextArenaTime", "nextLeaguesTime", "nextPachinkoTime", "nextPachinko2Time", "nextShopTime"]
for (let i2 = 0; i2 < TimersList.length; i2++) {
    let optionElement = document.createElement("option");
    optionElement.value = i2;
    optionElement.text = TimersList[i2];
    timerOptions.add(optionElement);
};

Events:

    document.getElementById("timerResetButton").addEventListener("click", function(){
        let timerSelector = document.getElementById("timerResetSelector");
        setTimer(timerSelector.options[timerSelector.selectedIndex].text,2); });
    $(document).on('change',"#timerResetSelector", function() {
        let timerSelector = document.getElementById("timerResetSelector");
        document.getElementById("timerLeftTime").innerText = getTimeLeft(timerSelector.options[timerSelector.selectedIndex].text)});

preview: image

Roukys commented 3 years ago

added in 42 ;) I've added it in debug menu and with dynamic timers list :) thanks again @cossname

cossname commented 3 years ago

@Roukys yw any idea for this problem? image

Roukys commented 3 years ago

ah ... nutaku is a strange one for me I'm not using it, I think somewhere in the code this is to prevent :

if (hh_nutaku)
    {
        function Alive()
        {
            window.top.postMessage({ImAlive:true},'*');
            if (sessionStorage.HHAuto_Temp_autoLoop=="true")
            {
                setTimeout(Alive,2000);
            }
        }
        Alive();
    }

but does not seems to be uptodate ...

cossname commented 3 years ago

where "hh_nutaku" defined? :upd nvm found it

Roukys commented 3 years ago

I'll connect to nutaku to try and understand this alive thing

Roukys commented 3 years ago

@cossname this is a recent issue right ?

cossname commented 3 years ago

3 times today

cossname commented 3 years ago

cant reload top window from frame

Roukys commented 3 years ago

yes because of cross domain security right ?

cossname commented 3 years ago

yes

Roukys commented 3 years ago

I've got the same issue for autologin

cossname commented 3 years ago

will try to find solution for it with

window.top.postMessage({someMessage},'*');
cossname commented 3 years ago

found this

// ==UserScript==
// @name         Nutaku reload helper
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Satellite script for HHAuto++, Nutaku version
// @author       Dorten D
// @match        http*://www.nutaku.net/games/harem-heroes/play*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var lastAnswer = (new Date()).getTime();
    window.addEventListener('message', function(event)
        {
        //console.log('NRH: recieved ',event);
            if (event.origin=="https://nutaku.haremheroes.com")
            {
                //console.log('NRH: recieved ',event);
                if (event.data.reloadMe)
                {
                    window.location.reload();
                }
                if (event.data.ImAlive)
                {
                    //console.log('NRH: ITS ALIVE!');
                    lastAnswer = (new Date()).getTime();
                }
                if (!event.data.ImAlive && !event.data.reloadMe)
                {
                    console.log('NRH: recieved ',event);
                }
            }
        }
    );

    setInterval(function(){
        if((new Date()).getTime() - lastAnswer > 25000) {
            console.log("NRH: it's dead :(");
            window.location.reload();
        }
    },2000);
})();
Roukys commented 3 years ago

1st is generated by script and second generated by app, need to find how to do the good one ... Capture d’écran 2021-02-12 à 16 13 46

Roukys commented 3 years ago

could you try with window.top.parent.postMessage({ImAlive:true},'*'); ?

cossname commented 3 years ago

cant understand what you need to do... both events similar, except origin, "ImAlive:true" stored in "data" section also why first one have "nutaku.net" origin?

Roukys commented 3 years ago

in script replace the line : window.top.postMessage({ImAlive:true},'*');

by : window.top.parent.postMessage({ImAlive:true},'*');

they may have changed some frames probably

cossname commented 3 years ago

image