1

I have a script that call a function on document ready. It works well when I load facebook from the browser, but when for example I click on my profile photo, it goes on my profile but the script doesn't reload itself because facebook maybe use ajax for page changing. How can I reload my script when I change the page using internal link on facebook? This is my script:

// ==UserScript==
// @name         Facebook Script
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.facebook.com/*
// @grant        none
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
(function() {
    'use strict';
    function facebook()
    {
        ...
    }
    $(document).ready(function(){
        facebook();
    });
})();

I'm using Chrome.

Edit: I don't need to reload my script for every ajax call but only on page changed from ajax. And I need to reload my script when the document is ready after the page changed.

Cristian Cundari
  • 317
  • 1
  • 3
  • 13
  • See, also, http://stackoverflow.com/questions/5890110/greasemonkey-script-to-work-on-dynamically-loaded-posts-on-facebook – Brock Adams Jan 27 '17 at 22:20
  • Regarding your edit: 1) The linked answers do that and, 2) `$(document).ready` is superfluous in Tampermonkey scripts -- except in rare scenarios that do not apply to your script (or most scripts). – Brock Adams Jan 27 '17 at 23:21

0 Answers0