Discussions » Creation Requests

hint for complete the script

§
Posted: 28.10.2015
Edited: 28.10.2015

hint for complete the script

hello all, so i got this script wich does ajax requests of multiple links

var items = document.querySelectorAll('.tableTorrents > tbody > tr > td:nth-child(2) > a');
        Array.prototype.forEach.call(items, function(el, i) {
            setTimeout(function() {
                function request() {
                    $.ajax({ 
                          url: el,
                        type:'GET',
                    }).done(function (responseText) {
                        var azvucika = responseText.match(/Озвучивание<\/b>:\s(.*)

so i want if responseText has variable azvucika and has words Звук с TS change the ajaxed link in red colour , thank you

woxxomMod
§
Posted: 28.10.2015
Edited: 28.10.2015

Since AJAX is asynchronous the only potential trouble is maintaining the element reference for which the text is fetched. You can ensure its validity by storing it in a local variable in forEach/each callback:

$('.tableTorrents > tbody > tr > td:nth-child(2) > a').each(function(i) {
    var el = $(this);
    setTimeout(function() {
        $.ajax({ 
            url: el.href,
            type:'GET',
        }).done(function(responseText) {
            var azvucika = responseText.match(/Озвучивание<\/b>:\s(.*)</)[1];
            var ts = responseText.indexOf('Звук с TS') >= 0;
            if (azvucika && ts) {
                el.css('color', 'red');
            }
        });
    }, 100 + (i * 500));
});
§
Posted: 28.10.2015

thank you very much woxxOm!!! the code was giving me a error that el.css is not a function, i solved like this
if (azvucika && ts) {$(el).css('color', 'red');}

§
Posted: 28.10.2015

Oh, one more question, userscripts can have acces to local storage? let's say i do ajax request one time and to save wich movies have "ozvucika TS"? :)

§
Posted: 28.10.2015

i guess this can be done with
GM_getValue and GM_setValue functions?

woxxomMod
§
Posted: 28.10.2015

the code was giving me a error that el.css is not a function

That wasn't my code, probably, because var el = $(this); is already wrapped with $. However if you use el from the callback parameter then yes, it should be wrapped.

localStorage

Yes, but each domain has it own isolated localStorage or to be more precise origin which is protocol://domain:port

GM_getValue and GM_setValue functions

These will save the values in your userscript's storage maintained by Greasemonkey/Tampermonkey so the values will be available on all the domains that are allowed for the userscript.

§
Posted: 28.10.2015

so should i try with GM_getValue and GM_setValue functions?

woxxomMod
§
Posted: 29.10.2015

You've just repeated the same question and I don't understand why I even explained the difference... You should choose what you need.

Post reply

Sign in to post a reply.