var $ = unsafeWindow.jQuery;
highlighting unsafeWindow
saying unsafeWindow was used before it was defined. How to fix this?unsafeWindow.jQuery
for getting the host page's instance of jQuery. You just use window.jQuery
, and // @grant none
(or @grant
whatever other special APIs you need for non-jQuery things).// @grant unsafeWindow
. Also, if you are getting your jQuery reference from the host window object, you won't need the @require
line.// UserScript |
// @name Vortek Preload |
// @namespace vortek |
// @description Load variables |
// @include http://localhost/vortek_php/* |
// @version 1 |
// /UserScript |
// a function that loads jQuery and calls a callback function when jQuery has finished loading |
functionaddJQuery(callback) { |
var script =document.createElement('script'); |
script.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'); |
script.addEventListener('load', function() { |
var script =document.createElement('script'); |
script.textContent='window.jQ=jQuery.noConflict(true);('+callback.toString() +')();'; |
document.body.appendChild(script); |
}, false); |
document.body.appendChild(script); |
} |
functionmain(){ |
$(document).ready(function() |
{ |
setTimeout(function(){ |
/*$('.fluid_types').val('Liquid'); |
$('.fluid_types').triggerHandler('change'); |
setTimeout(function(){ |
$('.fluids').val('Ammonia'); |
},500);*/ |
$('.fluid_types').triggerHandler('change'); |
$('.flow_unit_1').val('lb'); |
$('.flow_unit_2').val('sec'); |
$('.min_flow').val(1); |
$('.nom_flow').val(2); |
$('.max_flow').val(8); |
$('.min_temp').val(280); |
$('.nom_temp').val(280); |
$('.max_temp').val(280); |
//$('.min_press').val(10); |
//$('.nom_press').val(10); |
//$('.max_press').val(20); |
setTimeout(function(){ |
$('#button_calc').triggerHandler('click'); |
setTimeout(function(){ |
$('.icon_size').triggerHandler('click'); |
},500); |
},500); |
},2000); |
}); |
} |
// load jQuery and execute the main function |
addJQuery(main); |
Nice, thank you! |
Did you try adding @require ? // UserScript ... // @requirehttp://code.jquery.com/jquery-latest.js ... // /UserScript instead of writing function which loads jquery? |
@require works just fine. In my testing, it seems that the script URI requires a scheme (http:/https:) to load. |
Please note that you should not use jquery-latest.js on a production site, and I suggest not to use it at all. You can find why of this at the official jquery blog post 'Don’t Use jquery-latest.js' (http://blog.jquery.com/2014/07/03/dont-use-jquery-latest-js/) |