Content added by AJAX-driven pages is often added long after your userscript runs, so the script does not normally see it.
You can use a long, fixed, interval as shown in Kursion's answer, but that has drawbacks:
- Choosing the delay value is problematic. And if the page is slow to load for the usual reasons, a fixed delay is likely to be inadequate.
- Making a longer delay will still not always work and slows/stops your userscript for annoyingly long periods.
- An very dynamic pages, a
setTimeout
will only catch the first instance, at best. Subsequent nodes will be missed.
A better way is to either use MutationObserver
s or a utility like waitForKeyElements().
Both have advantages and disadvantages, but I've found waitForKeyElements
to be simpler and more robust in general. (Disclosure: I wrote it.)
Here is a complete userscript showing the question code factored to work on dynamic web pages:
// ==UserScript==
// @name _Fix div CSS on AJAX-driven pages
// @match http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
//- The @grant directive is needed to restore the proper sandbox.
waitForKeyElements ("div", adjustSelectDivdimensions);
function adjustSelectDivdimensions (jNode) {
if (jNode.css('width') == '648px') {
jNode.css( {"width": "900px", "height": "550px"} )
}
}