Add a draggable window to a page using Greasemonkey

后端 未结 2 763
悲&欢浪女
悲&欢浪女 2021-01-23 02:49

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?

2条回答
  •  后悔当初
    2021-01-23 03:42

    I've created a working userscript that adds a draggable div to every page. Here is the source code:

    // ==UserScript==
    // @name       Div on top
    // @namespace  http://use.i.E.your.homepage/
    // @version    0.1
    // @description  enter something useful
    // @match      https://*/*
    // @match      http://*/*
    // @match      *.com*
    // @match      *.net*
    // @require    http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
    // @require     http://code.jquery.com/ui/1.9.2/jquery-ui.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.
    '); $( "#draggableDiv" ).draggable(); $('#draggableDiv').mouseup(function() { //alert('Set the x and y values using GM_getValue.'); var divOffset = $("#draggableDiv").offset(); var left = divOffset.left; var top = divOffset.top; GM_setValue("left", left); GM_setValue("top", top); //alert("Set left to " + left + " and top to " + top); }); });

提交回复
热议问题