[tpm] [OT] Javascript to watch for certain KW from a web page

Shaun Fryer sfryer at sourcery.ca
Fri Oct 12 01:31:45 PDT 2012


Or for yet another way, also sans jquery...

var iframe = document.createElement("iframe");
var o = {display:"none", height:0, width:0};
for (var attr in o) iframe.style[attr] = o[attr]; // append a
timestamp below to bypass cache
var getServerStatus = function () { iframe.src =
"/url/to/your/log/output?" + (new Date ()).getTime() };
iframe.onload = function() {

  var win = iframe.contentWindow || iframe.contentDocument;
  if (/your regexp/.test(win.document.body.innerHTML))
    alert("your process completed");
  else setTimeout( getServerStatus, 60*1000 ); // ~1 minute

};
getServerStatus();
document.body.appendChild(iframe);
--
Shaun Fryer
647-709-6509
----------------------------------------------------------
perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \
        52959394107588899482799210587992861082757785799222
----------------------------------------------------------


On Thu, Oct 11, 2012 at 11:05 AM, Antonio Sun <antoniosun at lavabit.com> wrote:
> Thanks a lot Mark,
> That works like a charm. I really appreciate your simplified solution sample
> code.
>
> Thanks again everyone for your helps.
>
> On Wed, Oct 10, 2012 at 12:12 PM, Mark Jubenville <ioncache at gmail.com>
> wrote:
>>
>> Alternatively if you don't want to do the whole ajax thing, you can do
>> something similar just checking the text of the body:
>>
>> <script>
>>
>>     var page_check;
>>
>>     var nMilliseconds = 60*1000; // frequency of server check in
>> milliseconds
>>     var checkServerStatus = function () {
>>         if ( /Text that you are searching
>> for/.test(document.body.innerHTML) ) {
>>             // simple javascript alert box
>>             alert("Text you want to display when the search is found");
>>
>>             // an actual new window/tab
>>             var text_window=window.open("","","width=200,height=100");
>>             text_window.document.write("<p>Text you want to display when
>> the search is found</p>");
>>             text_window.focus();
>>
>>             clearInterval(page_check);
>>
>>         }
>>     };
>>     page_check = setInterval( checkServerStatus, nMilliseconds );
>> </script>
>>
>> That doesn't require jQuery either.
>>
>> I put in examples of opening an actual window or just showing an alert
>> box.
>>
>>
>> On 2012-10-10 11:40 AM, Mark Jubenville wrote:
>>
>> I'd use setInerval instead of setTimeout though:
>>
>> var page_check;
>>
>> var nMilliseconds = 60*1000; // frequency of server check in milliseconds
>> var checkServerStatus = function () {
>>   $.ajax({ url: "/path/to/your/log/file/script" }).done(function
>> (jqXHR, textStatus) {
>>     if (/a regexp matching text in your log
>> file/.test(jqXHR.responseText)) {
>>       $.facybox("The text you wish the user to see in the popup
>> dialogue.");
>>       clearInterval(page_check);
>>     }
>>   });
>> };
>> page_check = setInterval( checkServerStatus, nMilliseconds );
>>
>>
>>
>> On 2012-10-10 11:27 AM, Antonio Sun wrote:
>>
>> Thanks a lot Shaun.
>>
>> That sure will pave my way to the right direction.
>> I'll start playing.
>>
>> Thanks everyone!
>>
>> On Wed, Oct 10, 2012 at 10:27 AM, Shaun Fryer <sfryer at sourcery.ca> wrote:
>>>
>>> Hi Antonio,
>>>
>>> That makes sense. Unfortunately it's a little beyond the scope of a
>>> simple email to provide a complete solution for your situation.
>>> However, you might try something like the following.
>>>
>>> You'll need two things. #1. an ajax function of some kind. Given that
>>> you aren't interested in learning JS, I'd recommend using a
>>> cross-browser abstraction library which has an ajax method, such as
>>> jQuery. #2. You'll need a popup dialogue of some kind. There are
>>> plenty to choose from. For the purposes of providing an example, I've
>>> [arbitrarily] chosen the facybox jQuery plugin. I have no direct
>>> experience with it, but the API seems simple enough, so it should work
>>> fine.
>>>
>>> Add a script tag including the jQuery library, followed by one for the
>>> plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a
>>> separate script tag below this, add code similar to that below
>>> (modified accordingly).
>>>
>>> var nMilliseconds = 60*1000; // frequency of server check in milliseconds
>>> var checkServerStatus = function () {
>>>   $.ajax({ url: "/path/to/your/log/file/script" }).done(function
>>> (jqXHR, textStatus) {
>>>     if (/a regexp matching text in your log
>>> file/.test(jqXHR.responseText))
>>>       $.facybox("The text you wish the user to see in the popup
>>> dialogue.");
>>>     else setTimeout( checkServerStatus, nMilliseconds );
>>>   });
>>> };
>>> setTimeout( checkServerStatus, nMilliseconds );
>>>
>>> The above is just pseudo-code, but it *should* work with very little
>>> modification, assuming you're using the indicated JS libraries.
>>>
>>> Hope this helps.
>>> --
>>> Shaun Fryer
>>> ----------------------------------------------------------
>>> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \
>>>         52959394107588899482799210587992861082757785799222
>>> ----------------------------------------------------------
>>>
>>>
>>> On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun <antoniosun at lavabit.com>
>>> wrote:
>>> > Hi, thanks a lot for your offer Shaun.
>>> >
>>> > That was actually what I thought the solution to be. Now let's forget
>>> > what I
>>> > said and focus on what I need to accomplish.
>>> >
>>> > Yes, I totally control the page content. The situation is,
>>> >
>>> > I am designing a web portal that can launch back-end server side
>>> > processes.
>>> > The problem is that the process can finish in seconds, or it might need
>>> > hours to finish, depending how much work the process has. So my design
>>> > is to
>>> > spawn a sub process, and capture all its outputs to a log text file,
>>> > then
>>> > return immediately to the user, in a web notice page saying, your job
>>> > is
>>> > queued; here is the log url; please check manually if is finished or
>>> > not.
>>> >
>>> > But my all my fellow coworkers said they don't want to check
>>> > themselves.
>>> > Instead, they want my web portal to check for them. I couldn't think of
>>> > any
>>> > solution from the server side to capture the end of the sub process,
>>> > then
>>> > informed the already submitted web notice page. Hence, I'm turning to
>>> > the
>>> > javascript front-end for solutions. Because I have zero knowledge of
>>> > Javascript, it might not be feasible at all. But I know the best
>>> > solution is
>>> > that if I can have a desktop notification mechanism just like gmail
>>> > does,
>>> > that should solve the problem, because my sub process control task does
>>> > know
>>> > when the sub process ends, and write a specific ending tag to the end
>>> > of the
>>> > log file, which is what I was planning to watch/search for. Every page
>>> > of my
>>> > portal does include a standard master template (except the log text
>>> > file),
>>> > so if I can send a signal at the end of my sub process and capture that
>>> > by
>>> > the master template, then pop up a javascript window, that will do as
>>> > well.
>>> >
>>> > Sorry for the lengthy gibberish, hope that you can figure something out
>>> > from
>>> > it.
>>> >
>>> > Thanks
>>
>> --
>>
>> Mark Jubenville | ioncache at gmail.com
>>
>>
>> _______________________________________________
>> toronto-pm mailing list
>> toronto-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/toronto-pm
>>
>
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>


More information about the toronto-pm mailing list