Discussions » Creation Requests
hint for complete the script
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));
});
thank you very much woxxOm!!! the code was giving me a error that el.css is not a function, i solved like thisif (azvucika && ts) {$(el).css('color', 'red');}
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"? :)
i guess this can be done with
GM_getValue and GM_setValue functions?
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.
so should i try with GM_getValue and GM_setValue functions?
You've just repeated the same question and I don't understand why I even explained the difference... You should choose what you need.
hint for complete the script
hello all, so i got this script wich does ajax requests of multiple links
so i want if responseText has variable
azvucika
and has wordsЗвук с TS
change the ajaxed link in red colour , thank you