JavaScript - Fetching Multiple Urls With Gm_xmlhttprequest
Hello all. I am working on a userscript for a site that grabs some weather information for each NFL game. I am trying to loop GM_xmlhttpRequest(s), which has worked okay, but doesn't seem to mix well with arrays. By that I mean I am attempting to push values onto an array, but it doesn't seem to work. So basically at the bottom of the code below, I get values for wind, but not for each windArray[i]. My hunch is that has something to do with the asynchronous behavior of GM_xmlhttpRequest, but I am wondering if there is anyway around that (coding wise). I greatly appreciate any input you can provide.
Code: //Strips all html elements from a string String.prototype.stripTags = function() { return this.replace(/<\/?[^>]+>|&[^;]+;|^\s+|\s+$/gi,''); } var weatherURL = new Array(); weatherURL[0] = 'http://www.nflweather.com/game/2011/week-1/bills-at-chiefs'; weatherURL[1] = 'http://www.nflweather.com/game/2011/week-1/bengals-at-browns'; weatherURL[2] = 'http://www.nflweather.com/game/2011/week-1/steelers-at-ravens'; var windArray = new Array(); function getDOC(url, callback) { GM_xmlhttpRequest({ method: 'GET', url: url, onload: function (responseDetails) { var dt = document.implementation.createDocumentType("html", "-//W3C//DTD HTML 4.01 Transitional//EN", "http://www.w3.org/TR/html4/loose.dtd"), doc = document.implementation.createDocument('', '', dt), html = doc.createElement('html'); html.innerHTML = responseDetails.responseText; doc.appendChild(html); callback(doc); } }); } for (var i=0; i<weatherURL.length; i++) { getDOC(weatherURL[i], function(doc) { var pageTds = doc.getElementsByClassName('no-line'); var wind = pageTds[9].innerHTML.stripTags(); //alert(wind); windArray.push(wind); //alert(windArray[i]); }); } Similar TutorialsHey guys, I need some help with fetching a string to be the button text from the html, instead of building it in the javascript, so I can localize it for translations. Right now I have this generating the button: Code: <input type="button" id="share_validate_button" name="share_validate_button" value="<?php echo __('Test Share'); ?> " /> The function __() I am using for the localization stuff, in case you were wondering what that was for. Anyways, below is the JS associated with this button Code: function share_validate_click_add () { $('#share_validate_button').removeAttr('disabled').attr('value', 'Test Share').one('click', function(){ xajax_settings_osb_data_windows_verify(xajax.getFormValues('data_info_form')); $('#share_validate_status').html(''); $(this).attr('disabled', 'disabled').attr('value', 'Testing Share...'); }); } This will display the correct value for the button, and on click, the button disables and text changes to 'Testing Share...' The only problem is the JS overrides the value I set in the html, so I can't localize it. I was wondering if there was a way for me to set the two values (Test Share & Testing Share...) in the html above where we set id and class, and just fetch them in the js where needed. Is this possible? If someone can help me I would really appreciate it! Thanks! Hello everyone, I've got a problem while trying to fetch some informations from multiple forms in the same page. What I'm trying to do with this code is fetching informations from the multiple forms on my page and checking if the information is the information I need. If so, I take this information and add it into a javascript generated form that I submit once every form in the page have been taken care of. It's the only way I found to 'submit' multiple forms at the same time. Everything was fine until I decided to give the user the option to add more forms on the page by clicking on a button (the form is then generated by javascript and appended on the page). There seems to be a problem when checking these particular forms, the script doesn't seem to recognize the value of the radio button (wich is add_question_faq) and never ever enters in this case. Code: case "add_question_faq": alert ("pourquoi, ho, pourquoi") if (mesForms[cpt].question.value=="" || mesForms[cpt].answer.value==""){ chaineModif+="StopSendRightNow" } break; Except when the commentarised Code: //for (h=0;h<mesForms[cpt].elements.length;h++){ //alert (mesForms[cpt].elements[h].name) //} ain't commentarised. Any Idea why a simple alert changes the behavior of the function? Here's the said function: Code: function select_forms_faq(){ var chaineModif="" var mesFormsModif=new Array(); var mesForms=document.getElementsByTagName("form"); for (cpt=0;cpt<mesForms.length;cpt++){ //for (h=0;h<mesForms[cpt].elements.length;h++){ //alert (mesForms[cpt].elements[h].name) //} if (mesForms[cpt].action.length!=0 && mesForms[cpt].action.length!=undefined){ for (k=0;k<mesForms[cpt].action.length;k++){ if (mesForms[cpt].action[k].checked==true){ switch (mesForms[cpt].action[k].value){ case "delete": chaineModif+="<input type=\'text\' name=\'delete_"+mesForms[cpt].id_question.value+"\' value=\'"+mesForms[cpt].id_question.value+"\' />"; break; case "save_changes_question": chaineModif+="<input type=\'text\' name=\'update_question_faq_"+mesForms[cpt].id_question.value+"\' value=\'id"+mesForms[cpt].id_question.value+"question"+mesForms[cpt].question.value+"answer"+mesForms[cpt].answer.value+"\' />" break; case "save_changes_cat": chaineModif+="<input type=\'text\' name=\'update_cat_faq_\' value=\'id"+mesForms[cpt].id_cat.value+"category"+mesForms[cpt].cat.value+"\' />" break; case "add_question_faq": alert ("pourquoi, ho, pourquoi") if (mesForms[cpt].question.value=="" || mesForms[cpt].answer.value==""){ chaineModif+="StopSendRightNow" } break; } } } } } if (chaineModif!="" && chaineModif.indexOf("StopSendRightNow")==-1){ var formFinal=document.createElement("form") with(formFinal){ method="POST" action="" name="formFinal" id="formFinal" style.display="none" } chaineModif+="<input type=\'hidden\' name=\'submit_changes_faq\' value=\'submit_changes_faq\' />" document.getElementById("wpbody-content").appendChild(formFinal) document.getElementById("formFinal").innerHTML=chaineModif formFinal.submit(); return false } else{ return false } } Hey all. I'm looking for a way to have a single, random line fetched from multiple text files, and then have that combination output somewhere, whether just to some field or another text file. For example: Text file A - I like I hate I love I despise I cherish Text file B - apples bananas oranges grapes grapefruit pineapple cherries Text file C - some of the time. most of the time. a lot of the time. pretty much never. So it would go in, get a line from each, and display something like: I love - grapefruit - most of the time. I cherish - pineapple - some of the time. etc. etc. I know it's a weird-sounding example, but you get the point. The line choices don't have to be separated by hyphens, but they preferably would be separated by something, like a comma, semi-colon, slash, whatever. I know this is pretty much a web coding forum, so that would be fine if I had to host it on my server or open it with a browser. But it would be optimal if this could be made into a standalone executable. I'm basically looking for something like Random Line Picker, just with the added functionality I mentioned. I'd be willing to make a little donation to someone if coding this would be a little difficult. Thanks! function Button1_onclick() { var v = 'parser2.php?data='+document.getElementById('message').value; ShowWebSite(v); } This is my code. I want to retain the \n in end of each line so that PHP can handle the input more well. But document.getElementById removes the \n. Is their any way to prevent this? I'm facing an issue with fetching the page URL from an IFRAME with cross domain. Is there any approach/ any ways to achieve this? hi guys. im new to javascript and i require some help on a task so hoping someone on here could help me and possibly push me in the right direction. so i have a website with content on specific pages i need some sort of JS soloution which will fetch an ID/Keyword out of the page content so when a button is clicked it finds the ID/keyword and directs the user to a specific form/page. is this possible and can any1 help? Cheers, Ant. Hello, How I open urls sequencially - one by time -, but automatically (each 5 seconds) from a list with dozens of URLs in the same iFRAME? I have what i think it is a simple question to answer. I have a button to open a new link in a iframe (in the same browser window). And what i need is that after i press the button, the link opened would come from a list of html sequencially. I dont want that the html opened would be from a random choice, but i want to be sequential. I hope that i'm being clear in my line of thought. Is this possible? cheers!!! Jan Lee Hello, I'm a complete novice in anything javascript and I've bit off more than I can chew! This script Code: function fixmenu(whichmenu) { var menu = whichmenu.find("a"); for(x = 0; x < menu.length; x++) { var o = menu.get(x); if(o.href.indexOf(".php") < 0) { var i = o.href.lastIndexOf("/"); var nl = "http://domain.com/" + o.href.substring(i + 1); o.href = nl; } } } function flinks() { fixmenu(j$("#div1")); fixmenu(j$("span#div2")); fixmenu(j$("div.div3")); } if(location.href.indexOf("sub.") >= 0 || location.href.indexOf("SUB.") >= 0) { j$(document).ready(flinks); } is not something I wrote, but something I am to make work, and I don't even know where to begin. I'm working on building a website on a custom CMS (I have no control over) and it uses relative urls (no control over that). The problem is we're integrating it with another system on subdomain. Not too sure if that makes sense. Anyways... what this is suppose to accomplish is when the website is at sub.domain.com it rewrites the relative urls in the 3 div containers to absolute urls, but ignore the links going to sub.domain.com already. In the menu (#div1) there are relative links (/page) and then there are links going to sub.domain.com/page. When we go to sub.domain.com it should rewrite the relative links (/page) to domain.com/page, but ignore sub.domain.com/page (absolute link). instead it is rewriting the entirety. Any idea as to how to make this work? Doing some forum searching, I found the following code: Code: <div id="someThing" style="display:block" >Put something here.</div> <script type="text/javascript"> var nowUrl = location.href; if (nowUrl != "http://jemmakidd.com/categories.php") { document.getElementById("someThing").style.display="none"; } </script> Apparently, this is for use of when you are modifying, for example, a PHP header or footer displayed on every page and you only want something to show up on particular pages. My issue is that I am trying to put something in the header of a Tumblr blog, and I only want it to show on the post pages. The Tumblr main page format is: http://*.tumblr.com/ The Tumblr post page format is: http://*.tumblr.com/post/* Is there any code I can use to do this? At least, I think it is. On my test site (http://goo.gl/P4SLu), you'll see that the URL first goes to "emineer.com/thesis/," but then quickly changes to "emineer.com/thesis/#page=tabsservices" which refers to a piece of .js I have lower on the page (the tabbed navigation). Is there a way for me to configure this js or CSS so that the URLs are unchanged? I know it's possible because my main site functions perfectly fine: (emineer.com). The code on my main site is just clunky so I decided to start from scratch. Any help here? I'd really like my URLs clean and free of any tags or anything like that. Thanks, Brandon I'm trying to learn how to use the url's scene7 gives me to have dynamic zoom images. The problem is I cant figure out how to load the url into a webpage instead of the browser. Here is an example image using the flyout zoom feature in scene 7. In the browser you can see the url is calling the image and the dynamic feature from scene7. How do i do this in a webpage using whatever code I need to. I've tried making it a link with an img src but that doesnt work. Im stuck and need help. Thanks for your advice. Oh, and if this is the wrong section to post in I apologize.
I am trying to load some hundreds of urls from a local text file. I was able to load them into an array. I want to load them sequentially after certain time interval. The script works fine if I remove setinterval but without it only 1 url gets loaded. Is there any other way to load all urls automatically 1-by-1. Here is the code: <html> <head> </head> <script type="text/javascript"> var allText =[]; var allTextLines = []; var Lines = []; var txtFile = new XMLHttpRequest(); //var i=0; txtFile.open("GET", "URL.txt", true); allText = txtFile.responseText; txtFile.onreadystatechange = function f() { if (txtFile.readyState == 4) { allText = txtFile.responseText; allTextLines = allText.split(/\r\n|\n/);//the urls are separated by /n document.write(allText); var i=Math.floor(Math.random()*100); window.location=allTextLines[i]; setInterval(f(),5000);// trying to load after 5 sec. } else { //alert("Didn't work"); } } txtFile.send(null); // <body onLoad="setInterval('f()', 30000)"> /* function onLoad(URL){ if(onLoad.loaded) window.setTimeout(f,0); else if (window.addEventListener) window.addEventListener("load",f,false); else if (window.attachEvent) window.attachEvent("onload",f); } onLoad.loaded=false; onLoad(function() { onLoad.loaded=true; }); */ </script> </html> I want to type urls in a text field, submit such urls and extract pictures of these web pages. Does anyone know how I can do this using javascript? Thanks, Marcelo Brazil I got this code to WORK with Buttons... But, i can NOT get it to work with URLs/LINKs... dose anyone have any suggestions? The URL alternative LINKs are placed below the buttons... but like i have said, they don't work. Help Pleeeeese. Thanks. ****HEAD <script language="javascript" type="text/javascript"> function getCheckedValue() { document.getElementById("presentationsNavBars").style.display = 'block'; document.getElementById("proposalsNavBars").style.display = 'none'; document.getElementById("postingsNavBars").style.display = 'none'; document.getElementById("myaccountNavBars").style.display = 'none'; } function getCheckedValue2() { document.getElementById("presentationsNavBars").style.display = 'none'; document.getElementById("proposalsNavBars").style.display = 'block'; document.getElementById("postingsNavBars").style.display = 'none'; document.getElementById("myaccountNavBars").style.display = 'none'; } function getCheckedValue3() { document.getElementById("presentationsNavBars").style.display = 'none'; document.getElementById("proposalsNavBars").style.display = 'none'; document.getElementById("postingsNavBars").style.display = 'block'; document.getElementById("myaccountNavBars").style.display = 'none'; } function getCheckedValue4() { document.getElementById("presentationsNavBars").style.display = 'none'; document.getElementById("proposalsNavBars").style.display = 'none'; document.getElementById("postingsNavBars").style.display = 'none'; document.getElementById("myaccountNavBars").style.display = 'block'; } </script> ****** BODY <div class="student_text"> <asp:RadioButton ID="RadioButton1" GroupName="reg" Text="presentations" runat="server" OnClick="return getCheckedValue();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" runat="server" onclick="getClickedValue();">Presentations_link_ex</a><br /> </div> <br /><br /> <div class="student_text"> <asp:RadioButton ID="RadioButton2" GroupName="reg" Text="proposals" runat="server" onclick="return getCheckedValue2();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" onclick="getClickedValue2();">Proposals_link_ex</a><br /> </div> <br /><br /> <div class="student_text"> <asp:RadioButton ID="RadioButton3" GroupName="reg" Text="postings" runat="server" onclick="return getCheckedValue3();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" onclick="getClickedValue3();">Postings_link_ex</a><br /> </div> <br /><br /> <div class="student_text"> <asp:RadioButton ID="RadioButton4" GroupName="reg" Text="myaccount" runat="server" onclick="return getCheckedValue4();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" onclick="getClickedValue4();">Myaccount_link_ex</a><br /> </div> <br /><br /> ****************************** start display ***************************** <br /><br /> <div id="presentationsNavBars" style="display: none;"> SOME HTML HERE ..........presentations nav bar............ </div> <div id="proposalsNavBars" style="display: none;" > SOME HTML HERE 44444444 proposals nav bar 44444444444 </div> <div id="postingsNavBars" style="display: none;" > SOME HTML HERE 2222222 postings nav bar 2222222222222 </div> <div id="myaccountNavBars" style="display: block;" > SOME HTML HERE 33333333 myaccount nav bar 33333333 </div> <br /><br /> ****************************** end ***************************** Hello I am trying to create a form which when the submit button is selected will open a new window with 1 of 4 URLs based on the the combination of data in 2 select boxes. For example: if select box 1 = a and select box 2 = a then open new window with URL 1 if select box 1 = a and select box 2 = b then open new window with URL 2 if select box 1 = b and select box 2 = a then open new window with URL 3 if select box 1 = b and select box 2 = b then open new window with URL 4 Any help would be greatly appreciated. Thanks Daniel Hello I am trying to create a form which when the submit button is selected will open a new window with 1 of 4 URLs based on the the combination of data in 2 select boxes. For example: if select box 1 = a and select box 2 = a then open new window with URL 1 if select box 1 = a and select box 2 = b then open new window with URL 2 if select box 1 = b and select box 2 = a then open new window with URL 3 if select box 1 = b and select box 2 = b then open new window with URL 4 Any help would be greatly appreciated. Thanks Daniel Hello, How I can detect URLs in a larger body of text using a regular expression in javascript. For ex.: I type this text in my form and I saved in database: My home page is http:// www. mypage .com.it And in my site I want to appear like he My home page is http://www.mypage.com.it Hi, I hope someone can help me. I'll be honest and say I don't know much about javascript, but am fairly comfortable in html. I am building a website that will have multiple image swaps on multiple pages. I am building this in wordpress, and I'm guessing that means my approach will be different than if I wasn't using wordpress. Here's how one page would work: There are 10 images shown. 1,2,3,4,5,6,7,8,9,10. When number 1 is clicked on, I want a new image - 1a. When 2 is clicked on, 2a. So there are 20 different images in all on a given page. Also, I want the user to be able to click on the image again to restore the original image. I would prefer onclick to onmouseover. There will be literally dozens of pages like this on the site, managed by wordpress, so hundreds of images to swap. Basically the first image is a question - the second image is the answer. Is this possible? I have the following script: Code: mytext = mytext.replace(/(\[\[(.+)\]\])/gi,"(<script src='http://www.mysite.com/mysite?Module=mymodule&Variable=$2&Output=JS'>)"); When I view the Generated Source, using Firefox Webdev plugin, it shows that the ampersands are replaced with "&", which causes the script to break. I have tried the following to no avail: Replacing the &'s with & Replacing the &'s with %26 Replacing the &'s with \u206 Placing the script in an external file Using CDATA and comments Escaping the &'s with \ before them And even unencoding them with +unencode('%26')+ Does anyone know how I can keep the &'s in the URL? Thanks in advance!!! |