Greasy Fork is available in English.

Συζητήσεις » Ανάπτυξη

[SOLVED] jquery line not launching in GM, but does in TM, and works?

§
Δημοσιεύτηκε: 13/09/2015
Επεξεργάστηκε: 13/09/2015

[SOLVED] jquery line not launching in GM, but does in TM, and works?

	$('
  • ').insertBefore($('.dropdown')[0]);

    I'm not sure what the issue is because a line below it appends a script element just perfectly to the head, and when running the whole script in the console, it works then, but not when the page is loaded, this one line is the _only_ line that is not ran, and I don't understand why..

    Any help is appreciated, if I figure out the issue I'll post a second comment with the fix and ask this thread to be closed.

    §
    Δημοσιεύτηκε: 13/09/2015

    I know this doesn't seem like a lot of information, but the script it self works, everything apart from this one line in Greasemonkey, that's why I've only posted 1 line.

    I've tried prepend, append, appentTo, before, after, basically any time of insertion there is for this line, but it will not work when loading the web page, but all the other contents inside the script do load and work.

    woxxomΣυντονιστής
    §
    Δημοσιεύτηκε: 13/09/2015

    The only kinda wrong thing I see at once is the inline js code in event handlers. AFAIK it's a bad thing to do. For example such code won't even execute inside html pages in chrome extensions.

    §
    Δημοσιεύτηκε: 13/09/2015

    Here is the parent script this code is from: https://greasyfork.org/en/scripts/12390/code#n25 (line 25)

    It works flawlessly in Chrome without a problem, but in firefox, the only thing that doesn't work is that.. Idk.. the page loads really slow, so I can set a window.setTimeout, or find something else to get it to work... I think that has to be the case, but it's weird that the script bit is injected into the 'head' tag, but this element I'm trying to create isn't fired..

    Do you think a Mutation would work?

    woxxomΣυντονιστής
    §
    Δημοσιεύτηκε: 13/09/2015
    Επεξεργάστηκε: 13/09/2015

    What should I exactly do on http://www.kongregate.com/games/groupsky/rcm ?
    Nevermind, I see the button added by that script.

    Well, yes MutationObserver will work:

    // @require      https://greasyfork.org/scripts/12228/code/setMutationHandler.js
    // ==/UserScript==
    
    setMutationHandler(document, '.dropdown', function(observer, nodes) {
        $(..........).insertBefore(nodes[0]);
        observer.disconnect();
    });
    
    §
    Δημοσιεύτηκε: 13/09/2015

    Sadly, it did not work for me, not sure I set it right though. I can't tell if it's just me, but Firefox takes ages for that page to load, it's loaded with angularjs or something, but it goes very slow compared to Chrome, or Chrome-like browsers..

    I'm going to try for an .ajaxComplete() and see if that works any.

    woxxomΣυντονιστής
    §
    Δημοσιεύτηκε: 13/09/2015
    Επεξεργάστηκε: 13/09/2015

    It works here in FF41 + GM3.4b3:

    function StartMyAutoClicker(elemArray) {
        if(!localStorage.autoClickInterval){
            localStorage.autoClickInterval = prompt('Please enter the number of miliseconds you would like it to click at\n *Note: 1000ms = 1 second, it\'s not recommended to do less than 10ms', '25');
        }
        setMutationHandler(document, '.dropdown', function(observer, nodes) {
                $('<li class="ng-scope"><a href=""><div class="fa fa-play" style="width:30px;" onclick="toggleAuto(this)" id="autoToggle"></div><input type="text" size="3" onblur="updateInterval(this)" style="height:20px;width:30px;background-color:#000000;border:0;text-align:center;" placeholder="'+ localStorage.autoClickInterval +'"></a></li>').insertBefore(nodes[0]);
                observer.disconnect();
        });
        $('head').append("<script>function toggleAuto(elem){\n\tif(elem.className.search('fa-pause') > 0){\n\t\telem.className = elem.className.replace('pause', 'play');\n\t\tclearInterval(autoClicker);\n\t}else{\n\t\telem.className = elem.className.replace('play','pause');\n\t\tautoClicker = setInterval((function(){$($('.btn.btn-primary.btn-lg.ng-scope')[0]).click();}), localStorage.autoClickInterval);\n\t}\n}\nfunction updateInterval(elem){\n\tlocalStorage.autoClickInterval = elem.value;\n\tif(document.getElementById('autoToggle').className.search('play') == -1){\n\t\tclearInterval(autoClicker);\n\t\tautoClicker = setInterval((function(){$($('.btn.btn-primary.btn-lg.ng-scope')[0]).click();}), localStorage.autoClickInterval);\n\t}\n}</script>");
    }
    

    And the page loads fast, I've tried this one: https://racing-clicker.github.io/index.html?kongregate=1&fixheight=1

    §
    Δημοσιεύτηκε: 13/09/2015
    Επεξεργάστηκε: 13/09/2015

    Woo, thank you so much for the help, I'm not sure what happened, guess my browser broke or something, a clean restart made it work.

    Now it's now working in chrome.. going to restart and see if that helps, if not I will just fire as I did before with the mutation in there, thank you again!

    // @contributor  wOxxOm (https://greasyfork.org/en/forum/profile/323/wOxxOm) //for fixing my script so it worked in Firefox! Huge thank you.
    woxxomΣυντονιστής
    §
    Δημοσιεύτηκε: 15/09/2015

    This RCM game is absolutely pointless and doesn't make any sense but I can't stop playing it for a few days now. Guess the numbers hypnotize me.

    §
    Δημοσιεύτηκε: 15/09/2015

    This game was poorly made from a game called Swarm Swim, but Swarm Sim is open source, so people can use it in their own games, but you should try that game, it's not a clicker, so it's mostly idle, and in my opinion, it's exponentially better. I was going to change the game (RCM)'s source script to make it more playable, but the amount of work that needs to go into it, is more time than I care to place into a game I did not make.

    Δημοσίευση απάντησης

    Συνδεθείτε για να δημοσιεύσετε μια απάντηση.