1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest Last month we upgraded BlackHatWorld.com to a new platform - . If you notice anything that requires attention please start a new thread here.
    Dismiss Notice

Jquery userscript - adwords issue

Discussion in 'HTML & JavaScript' started by hip_hop_x, Jan 26, 2013.

  1. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    Hey there,
    I was trying to code an userscript for G adwords, the problem is that i can't really detect events that are happening, not to mention that i can't really fetch any of the data...

    Notice: This is not the full userscript, jquery was included and works but i can't really parse the page.


    I did try to use window.open (instead of ready or window.addEventListener ("load", etc... ) but those doesn't detect the click either.
    I also tested to initialize all the code after a timeout of 20 seconds (when ajax was fully loaded), but the same, no results.

    Not even this simple alert doesn't work, not really sure how to be able to fetch data. (i did try to replace with classes, same nothing)
    Code:
    $(document).ready(function(){
    
    
    	$('button').click(function(){
    			alert('click');
    	});
    
    
    });
    
    
    Any help would really be good.
     
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,412
    Likes Received:
    9,797
    $('button')

    Does the target page actually have an html5 button tag or did you pass jQuery a wrong identifier? ;)
     
  3. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    it has, and i even did try with the buttons class, same result, nothing :(
     
  4. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,412
    Likes Received:
    9,797
    Make a jsfiddle and we 'll be able to help you more.
     
  5. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    There's really nothing much about this userscript, it's just a simple feature that doesn't work and it's really the first time when a website successfully blocked the main events detection.

    Code:
    // ==UserScript==
    // @name          User-controlled Google Adsense
    // @namespace     Website
    // @description   Rewrites the URL in adsense iframes to a user-specified value, changing the ads
    // @include       https://adwords.google.com/o/Targeting*
    // ==/UserScript==
    
    /*
    Here will be a copy & paste jquery from jquery download
    */
    
    
    
    $(document).ready(function(){
      $('button').click(function(){ 
          alert('click');    
      });
    });
    
    
     
  6. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,412
    Likes Received:
    9,797
    Did you actually load jQuery before you use it?
     
  7. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    Yes, and i tested with an alert in $(document).ready to see if everything goes well, and it did.

    One of the problems may be the fact that $(document).ready actually loads before the page is fully loaded... and that's really something i don't know how to detect (same happends with window.load)
     
  8. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,412
    Likes Received:
    9,797
    I think I know what 's going on, try this:

    Code:
     $(document).ready(function(){
      $('body').on('click', 'button', function(){ 
          alert('click');    
      });
    });
     
    If it works, ask me why :)
     
  9. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    Doesn't work either, not even this other code
    Code:
    $('body').click(function(){
    		alert('x');
    	});
    
    Their security really seems to be good and nothing seems to be working :(
     
  10. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,412
    Likes Received:
    9,797
    I just tested my version on Firefox and it works fine :)

    You messed up somewhere in your setup. You probably didn't load jQuery.

    Here 's the full script, put it properly into Greasemonkey and it works.

    Code:
    // ==UserScript==
    // @name          User-controlled Google Adsense
    // @namespace     Website
    // @description   Rewrites the URL in adsense iframes to a user-specified value, changing the ads
    // @include       https://adwords.google.com/o/Targeting*
    // @require   http://code.jquery.com/jquery-1.8.1.min.js
    // ==/UserScript==
    
    $(document).ready(function(){
      $('body').on('click', 'button', function(){ 
          alert('click');    
      });
    });
    
     
    • Thanks Thanks x 1
  11. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    Darn, indeed jquery wasn't loading or something (the odd is that $(document).ready worked and didn't return any errors for the $)

    Thank you big time mate!