ffmmx's Blog

Happy coding

vimperator ffmmx的插件屋

ffmmx posted @ 2012年9月23日 12:58 in javascript with tags firefox javascript vimperator 鼠标事件 , 2925 阅读

最近在用vimperator,被它的可以完全自定义扩展特性吸引了,再加上现在的ff支持很多HTML5的新功能,基本上可以通过JAVASCRIPT代码做到很多以前做不到的事情,比如文件系统操作。但是默认提供的功能还是很有限,所以为了方面还是需要自己扩展一些功能或者插件(这里说的这些东西只是给自己做一个备忘,没有什么特别的含义

插件项目地址https://github.com/firefoxmmx2/vimperatorPlugins ,使用了github,速度比较快。

虽然vimperator 的; extend hint 已经提供很多功能,例如复制匹配的链接地址等功能,但是目前还没有 触发鼠标事件的功能,所以我自己写了一个作为补充。

文件 simlateMouseEvents.js

代码:

//
// simulate mouse events
// 
//
(function(){
    let self=liberator.plugins.simulateMouseEvents=(function(){

        var fireMouseEvt=function(elem,evtString){
            var doc=content.document.wrappedJSObject;

            if(doc.createEvent){
                var evt=doc.createEvent('MouseEvents');
                evt.initEvent(evtString,true,false);
                elem.dispatchEvent(evt);
            }
            else if(doc.createEventObject){
                elem.fireEvent('on'+evtString);
            }
        };

        var PUBLICS={
            mouseover:function(elem){
                if(elem){
                    fireMouseEvt(elem,'mouseover');
                    elem.setAttribute('isMouseover',true);
                }
                else{
                    var activeElement=content.document.wrappedJSObject.activeElement;
                    fireMouseEvt(activeElement,'mouseover');
                    activeElement.setAttribute('isMouseover',true);
                }
                
                    
            },
            mouseout:function(elem){
                if(elem){
                    fireMouseEvt(elem,'mouseout');
                    elem.setAttribute('isMouseover',false);
                }
                else{
                    var activeElement=content.document.wrappedJSObject.activeElement;
                    fireMouseEvt(activeElement,'mouseout');

                    activeElement.setAttribute('isMouseover',false);
 
                }
            }
        };

        //registe extend hint command like ;m
        hints.addMode(
                'm',
                'active element trigge mouseover/mouseout',
                function(node){
                    if(node.getAttribute('isMouseover') && node.getAttribute('isMouseover') == 'true'){
                        self.mouseout(node);
                    }
                    else{
                        self.mouseover(node);
                        //全局的上一个触发过over事件的元素
                        if(self.overElem && self.overElem!=node){
                            try{
                                self.overElem.setAttribute('isMouseover',false);
                            }
                            catch(e){}
                        }
                        self.overElem=node;
                    }


        });
        return PUBLICS;
    })();
})();

 

主要的思路就是聚焦到指定的元素,然后通过创建并且注册鼠标事件再触发它。再写vimperator插件的时候,需要注意的是document不是我们熟悉的htmldocument ,他是firefox自身环境的xuldocument,他是不会包含我需要的页面元素的。所有来自于tab的元素都需要从content 对象里面去获取,content指的就是当前的tab的显示信息,例如:content.document.wrappedJSObject. 通常来说wrappedJSObject 是对目标对象的一个封装结果,通常从这里入手获取想要数据和函数。

Avatar_small
ffmmx 说:
2012年9月23日 13:01

不知道为什么 代码框贴出来会乱掉。

Avatar_small
Livik 说:
2023年8月05日 15:24

The 'House of Plugins' for Vimperator ffmmx illustrates how software can adapt to meet diverse user needs, mirroring the adaptability necessary in health and social care. Just as examples of risk assessments in health and social care we're prepared for a variety ty of scenarios .

Avatar_small
College Assignment H 说:
2023年10月31日 20:50

I appreciate your insights on Vimperator's customizable extensions and the evolving HTML5 support in Firefox. Your self-written mouse event function is a valuable addition, making this a must-visit GitHub repository for users like me.

Avatar_small
sarahjohn 说:
2023年11月18日 15:24

The Vimperator FFMMX extension house brings a new level of functionality to browser navigation. Its innovative features enhance the Vimperator user experience by providing a smooth and efficient browsing environment. Today I am looking for <a href="https://thedissertationhelp.co.uk/marketing-research-paper-topics/">marketing research paper topics</a>. If anyone knows my subject well, please guide me professionally. I will investigate further after completing the task.

Avatar_small
My Assignment Help 说:
2023年11月21日 19:11

Vimperator's customizable extensions truly elevate the browsing experience, and the enhanced HTML5 support in ff opens up exciting possibilities. While default functions are somewhat limited, the ability to expand features with plugins ensures a tailored and efficient browsing journey.

Avatar_small
seo service UK 说:
2024年1月16日 16:55

Extremely pleasant and fascinating post. I was searching for this sort of data and appreciated perusing this one. Continue posting. Much obliged for sharing.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter