I wonder if it's possible to load jQuery within Opera User JavaScript, so that I can use jQuery functionality in it, even on pages that are not currently using jQuery.
I just wrote an Opera userJS, which I transformed from a Google Chrome extension, where jQuery could easy be loaded, but here in Opera I had to use another solution, and I wanted to make minimal changes in my code.
I just append a new script tag in the document's header with a working jQuery source. It starts to get downloaded BEFORE DOM is ready.
This is my working solution, hope that helps!
// ==UserScript==
// @name This is the name of my userJS
// @description That's the description of my userJS
// @include http://blahblah.hu/*
// @include http://*.blahblah.hu/*
// @match http://blahblah.hu/*
// @match http://*.blahblah.hu/*
// @version 1.0
// ==/UserScript==
(function( ) {
// include jQuery
var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.id = 'myjQuery';
newScript.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';
headID.appendChild(newScript);
window.addEventListener('load', function (e) {
// you can write your jQuery code now!
$('#yourElementId').css('background-color', 'yellow');
// further jQuery codes
// ...
}, false);
})( );
Well it would certainly be possible if you paste the whole lot of jQuery into your UserJS file, or perhaps create a separate UserJS file for all pages with the jQuery library. However, there's a possibility that it would conflict with any pages using jQuery.
Depending on your requirements, maybe you could roll your own mini-framework? For example some simple functions to grab elements by tag/class/id:
function $id(id) {
return document.getElementById(id);
}
Note: you may get a better response over at Opera's forums.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With