I\'m trying to create a Greasemonkey script that adds a draggable div to every web page. For some reason, the div isn\'t displaying at all. What might be the reason for this?
Completely wrong on the first go - the issue is the use of $(document).append
. You cannot append directly to the document, you can only append to a node.
So Either
$(document.body).append()
or
$('body').append()
Here's the fiddle for proof.
It's probably the lack of the @require, maybe your greasemonkey is out of date?
// ==UserScript==
// @name My Fancy New Userscript
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match http://*/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// @copyright 2012+, You
// ==/UserScript==
jQuery(function($){
var _highest = 0;
$("div").each(function() {
var _current = parseInt($(this).css("zIndex"), 10);
if(_current > _highest) {
_highest = _current + 1;
}
});
$('body').append(' Hello, This is an addon div from Greasemonkey. ');
});
Boilerplate template. Should work fine OOB.