2

I have created Safari Extension that blocks certain elements from Facebook and I was wondering is it possible to make it block all the time. For example, it blocks the elements when you load Facebook, however when you click the Facebook logo in the top left corner all the elements come back, you have to manually reload the page to block them again. So basically all the elements come back when you click something that doesn't reload the page.

Thanks.

Here is my code.

jQuery(document).ready(function(){ 
    $("#content").find("#sideNav").find("#listsNav").css( "display", "none" );
});
musefan
  • 47,875
  • 21
  • 135
  • 185
Ryan Hawdon
  • 389
  • 2
  • 6
  • 15

2 Answers2

1

It all depends on what facebook actually does when you click the logo.

If it makes an AJAX request, then you can listen for that event and re-hide the elements then. For example:

$( document ).ajaxComplete(function() {
    $("#content").find("#sideNav").find("#listsNav").css( "display", "none" );
});

If it just runs some local javascript then you could listen for the click event, and again run your code. For example, assuming the logo has an id of #logo...

$("#logo").click(function(){
    $("#content").find("#sideNav").find("#listsNav").css( "display", "none" );
});

In addition, as suggested by Satpal, ids are meant to be unique to a page so you don't need to find them the hard way, just reference them directly like so:

$("#listsNav").hide();
musefan
  • 47,875
  • 21
  • 135
  • 185
  • Will the AJAX function automatically know when content has changed on the web page and I will be able to run my element hiding function? – Ryan Hawdon Oct 21 '14 at 11:04
  • @RyanHawdon: It should know when facebook has received the data from it's AJAX request. Again, I do not know exactly how facebook runs so it is all very dependent on how they have developed it – musefan Oct 21 '14 at 11:12
  • @RyanHawdon: If my answer helped solve your problem then please consider accepted it by clicking the tick next to it. That way it make it easier to find useful answers for other people. Also, it improves both our reputation on the site – musefan Oct 21 '14 at 11:52
  • Just another quick question, all the elements get blocked when there is new content on Facebook, however is it possible to block everything without it refreshing the whole page, at the moment it refreshes the whole page and the elements come up for half a second then disappear. – Ryan Hawdon Oct 21 '14 at 11:56
  • @RyanHawdon: Not sure, it's really difficult to provide an concrete answer without having a test environment to play with. Perhaps you want to look into injecting some CSS that ensures the elements never show. For example, try setting `visibility:hidden`, maybe facebook didn't cater for that. Or set width/height to `0px`, etc. It's just gonna be one of those where you need to try a few things until you get what you want – musefan Oct 21 '14 at 12:13
0

jQuery(document).ready(); is only called when the DOM is ready.

facebook is using AJAX calls to get new content. You also have to bind a listener to the DOM which watches for changes.

This may help you: Is there a JavaScript/jQuery DOM change listener?

Community
  • 1
  • 1
secelite
  • 1,353
  • 1
  • 11
  • 19