Page 1 of 1

Inyect JQUERYt on a loaded webpage in webgadget?

Posted: Wed Jun 10, 2020 2:02 am
by ricardo
Hi,

I want to visit any site an want to be able to inyect jquery and then a script like this:

Code: Select all

$(document).on('click', '*', function (e) {
	clicked_id = e.target.id;
	clicked_name = e.target.name;
	clicked_idtagName = e.target.tagName;
	clicked_class = e.target.className;
	clicked_html = e.target.innerHTML;
	
    e.stopPropagation();
    var others = document.getElementsByTagName(this.tagName);
    var index = [].indexOf.call(others, this);

    $('#output').html(index);

    // do stuff with ids and classes 
	alert(clicked_id);
	alert(clicked_name);
	alert(clicked_idtagName);
	alert(clicked_class);
	alert(clicked_html);
	alert(index);
	valor = "P";
	$(valor)[2].innerHTML = "probando";
});
I want to get the id, name, Tag, class and inner HTML of anyobject clicked.
NOT in a page i develope, but in anypage i am browsing.
Thats why i need to inyect first Jquery and then my code.



Anybody can point me in the right direction please?

Thanks in advance

Re: Inyect javascript on a loaded web in webgadget?

Posted: Wed Jun 10, 2020 2:05 am
by ricardo
I tried many options, like

Code: Select all

Jquery$ = "var ref = document.getElementsByTagName( 'script' )[ 0 ];" + eol$ 
Jquery$ + "var script = document.createElement( 'script' );" + eol$ 
Jquery$ + "script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js';" + eol$ 
Jquery$ + "script.defer = true;" + eol$
Jquery$ + "ref.parentNode.insertBefore( script, ref );" + eol$ 
or

Code: Select all

Jquery$ = "(function(d, s, id){" + eol$
Jquery$ + "var js, fjs = d.getElementsByTagName(s)[0];" + eol$
Jquery$ + "If (d.getElementById(id)){ Return; }" + eol$
Jquery$ + "js = d.createElement(s); js.id = id;" + eol$
Jquery$ + "  js.onload = function(){" + eol$
Jquery$ + "  // remote script has loaded" + eol$
Jquery$ + "alert('a');" + eol$
Jquery$ + "  };" + eol$
Jquery$ + "  js.src ='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js';" + eol$
Jquery$ + "  fjs.parentNode.insertBefore(js, fjs);" + eol$
Jquery$ + "  }(Document, 'script', 'ri'));" + eol$
But none works.

Re: Inyect javascript on a loaded web in webgadget?

Posted: Wed Jun 10, 2020 4:02 am
by ricardo
Can't understand why this does not work

Code: Select all

Jquery$ = "var script_tag = document.createElement('script');" + eol$
Jquery$ + "script_tag.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js');" + eol$
Jquery$ + "Document.head.appendChild(script_tag);" + eol$
Jquery$ + "window.onload = function() {" + eol$
Jquery$ + "If (window.jQuery) {  " + eol$
Jquery$ + "  // jQuery is loaded  " + eol$
Jquery$ + "  alert('ADD [code]
SCRIPT TAG ON HEAD!');" + eol$
Jquery$ + "} Else {" + eol$
Jquery$ + " // jQuery is Not loaded" + eol$
Jquery$ + " alert('DOESN'T ADD SCRIPT TAG ON HEAD');" + eol$
Jquery$ + " }" + eol$
Jquery$ + " }" + eol$
[/code]

Mmmm.... i found that in html page this works
<script src="https://ajax.googleapis.com/ajax/libs/j ... "></script>
<script>


$(document).on('click', '*', function (e) {
clicked_id = e.target.id;
clicked_name = e.target.name;
clicked_idtagName = e.target.tagName;
clicked_class = e.target.className;
clicked_html = e.target.innerHTML;

e.stopPropagation();
var others = document.getElementsByTagName(this.tagName);
var index = [].indexOf.call(others, this);

$('#output').html(index);

// do stuff with ids and classes
//alert("document");
alert('444');
alert(clicked_id);
alert(clicked_name);
alert(clicked_idtagName);
alert(clicked_class);
alert(clicked_html);
alert(index);
valor = "P";
$(valor)[2].innerHTML = "probando ja ja";
//$( "P" ).(2).VALUE = "probando ja ja";
// e.stopPropagation();
// var others = document.getElementsByTagName(this.tagName);
// var index = [].indexOf.call(others, this);
//alert("indice");
//alert(index);
});


</script>

but THIS does not work.... why???

Code: Select all

<script>
var script_tag = document.createElement('script');
script_tag.setAttribute('src','https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js');
document.head.appendChild(script_tag);
window.onload = function() {
    if (window.jQuery) {  
        // jQuery is loaded  
        alert("ADD SCRIPT TAG ON HEAD!");
    } else {
        // jQuery is not loaded
        alert("DOESN'T ADD SCRIPT TAG ON HEAD");
    }
}

$(document).on('click', '*', function (e) {
	clicked_id = e.target.id;
	clicked_name = e.target.name;
	clicked_idtagName = e.target.tagName;
	clicked_class = e.target.className;
	clicked_html = e.target.innerHTML;
	
    e.stopPropagation();
    var others = document.getElementsByTagName(this.tagName);
    var index = [].indexOf.call(others, this);

    $('#output').html(index);

    // do stuff with ids and classes 
	//alert("document");
	alert('444');
	alert(clicked_id);
	alert(clicked_name);
	alert(clicked_idtagName);
	alert(clicked_class);
	alert(clicked_html);
	alert(index);
	valor = "P";
	$(valor)[2].innerHTML = "probando ja ja";
	//$( "P" ).(2).VALUE = "probando ja ja";
  // e.stopPropagation();
  // var others = document.getElementsByTagName(this.tagName);
  // var index = [].indexOf.call(others, this);
//alert("indice");
//alert(index);
});


</script>

Re: Inyect javascript on a loaded web in webgadget?

Posted: Wed Jun 10, 2020 6:58 pm
by ricardo
Hi,

What is need to do is to inyect JQUERY into a webgadget.



Thanks in advance.

// Edit: Font size adjusted. (Kiffi)

Re: Inyect JQUERYt on a loaded webpage in webgadget?

Posted: Tue Jun 16, 2020 7:03 pm
by ricardo
Hi,

In the past i used vbs to insert a javascript into any webpage loaded into webgadget.

That worked just fine.

It is possible to do it with javascript?

Re: Inyect JQUERYt on a loaded webpage in webgadget?

Posted: Tue Jun 16, 2020 8:15 pm
by Kiffi

Code: Select all

EnableExplicit

Enumeration
  #Window
  #WebGadget
EndEnumeration

Procedure WaitForWebGadget(WebGadget)
  
  Repeat
    If GetGadgetAttribute(WebGadget, #PB_Web_Busy) = 0 : Break : EndIf
    While WindowEvent() : Delay(10) : Wend
  ForEver
  
EndProcedure

OpenWindow(#Window, 0, 0, 800, 600, "Inject jQuery", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

WebGadget(#WebGadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window), "https://example.com/")

; WebBrowser2.IWebBrowser2 = GetWindowLongPtr_(GadgetID(#WebGadget), #GWL_USERDATA)
; WebBrowser2\put_Silent(#True)

WaitForWebGadget(#WebGadget)

Define YourScript.s = "$(document).click(function(e){" +
                      "  alert(e.target.tagName);" +
                      "});" 

Define InjectScript.s = "var a=document.createElement('script');" +
                        "a.src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js';" +
                        "document.getElementsByTagName('head')[0].appendChild(a);" +
                        "$(document).ready(function(){" + YourScript + "});"

SetGadgetText(#WebGadget, "javascript:" + InjectScript + ";void(0);")

Repeat
  
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Inyect JQUERYt on a loaded webpage in webgadget?

Posted: Wed Jun 17, 2020 4:52 am
by ricardo
Kiffi wrote:

Code: Select all

EnableExplicit

Enumeration
  #Window
  #WebGadget
EndEnumeration

Procedure WaitForWebGadget(WebGadget)
  
  Repeat
    If GetGadgetAttribute(WebGadget, #PB_Web_Busy) = 0 : Break : EndIf
    While WindowEvent() : Delay(10) : Wend
  ForEver
  
EndProcedure

OpenWindow(#Window, 0, 0, 800, 600, "Inject jQuery", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

WebGadget(#WebGadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window), "https://example.com/")

; WebBrowser2.IWebBrowser2 = GetWindowLongPtr_(GadgetID(#WebGadget), #GWL_USERDATA)
; WebBrowser2\put_Silent(#True)

WaitForWebGadget(#WebGadget)

Define YourScript.s = "$(document).click(function(e){" +
                      "  alert(e.target.tagName);" +
                      "});" 

Define InjectScript.s = "var a=document.createElement('script');" +
                        "a.src='//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js';" +
                        "document.getElementsByTagName('head')[0].appendChild(a);" +
                        "$(document).ready(function(){" + YourScript + "});"

SetGadgetText(#WebGadget, "javascript:" + InjectScript + ";void(0);")

Repeat
  
Until WaitWindowEvent() = #PB_Event_CloseWindow
Great!!

Thanks a lot !!