firefox按钮菜单自动弹出uc脚本,修正Omnibar上的图标按钮有些不能弹出的问题

// ==UserScript==
// @name           AutoPopup.uc.js
// @description    Auto popup menulist/menupopup
// @compatibility  Firefox 24.0+
// @author         GOLF-AT, modify by gsf
// @version        2015.1.29
// ==UserScript==

(function () {
	var nDelay = 300;
	var overElt = null;
	var PopElt = null;
	var PopTimer = null;
	var HideTimer = null;
	var searchBar = null;
	var AlwaysPop = false;

	//by gsf, 请用CSS,支持Fx的CSS所有语法。#表示id,.表示class,也能用[id='demo']
	var BlackIDs = [];

	//by gsf, 白名单,及触发动作
	var whiteIDs = [{
		id: 'omnibar-defaultEngine',
		popMemu: 'omnibar-engine-menu',
		run: function(overElem){
			document.getElementById('omnibar-in-urlbar').click(0);
		}
	},
	{
		id: 'readLater',
		popMemu: 'readLater-popup',
		run: null
		//function(overElem){ PopElt.popup();}
	},
	{
		id: 'foxyproxy-toolbar-icon',
		popMemu: 'foxyproxy-toolbarbutton-popup',
		run: null
	}];
	var whitesInx = -1;

	var popupPos = ['after_start', 'end_before', 'before_start', 'start_before'];

	var menuPanelID = 'PanelUI-popup';
	var downPanelID = 'downloadsPanel';
	var widgetPanelID = 'customizationui-widget-panel';

	function IsWidgetBtn(elt) {
		try {
			return elt.hasAttribute('widget-id')
				&& elt.getAttribute('widget-type') == 'view';
		} catch (e) {
			return false;
		}
	}

	function IsSearchBtn(elt) {
		try {
			return elt.getAttribute("anonid") == 'searchbar-search-button'
			|| whitesInx === 0;
		} catch (e) {
			return false;
		}
	}

	function IsNewMenuBtn(elt) {
		try {
			return elt.id == 'PanelUI-menu-button';
		} catch (e) {
			return false;
		}
	}

	function IsDownloadBtn(elt) {
		try {
			return elt.localName == 'toolbarbutton'
			&& elt.id == 'downloads-button';
		} catch (e) {
			return false;
		}
	}

	function IsAutoComplete(elt) {
		try {
			return elt.getAttribute('type').substr(0, 12) == 'autocomplete';
		} catch (e) {
			return false;
		}
	}

	function getPopupMenu(elt) {
		if (whitesInx > -1 && PopElt)
			return PopElt;
		var nodes = elt ? elt.ownerDocument.getAnonymousNodes(elt) : null;
		for (let [i, k] in Iterator(nodes)) {
			if (k.localName == 'menupopup')
				return k;
		}

		var s = elt.getAttribute('popup');
		return s ? document.getElementById(s) : null;
	}

	function isBlackNode(elt) {
		//var attr, val, nPos;
		for (let [i, css] in Iterator(BlackIDs)) {
/*			if (str.length == 0)
				continue;
 			if (str.charAt(0) == '#') {
				val = str.substr(1);
				attr = 'id';
			} else if (str.charAt(0) == '.') {
				val = str.substr(1);
				attr = 'class';
			} else {
				nPos = str.indexOf('=');
				if (nPos > 0) {
					val = str.substr(nPos + 1);
					attr = str.substr(0, nPos);
				} else {
					val = str;
					attr = 'id';
				}
			}  by gsf */
			try {
				//if (elt.getAttribute(attr) == val)
				if (css.length > 0 && document.querySelector(css))
					return true;
			} catch (e) {}
		}
		return false;
	}

	function getPopupPos(elt) {
		var x, y, pos, box;

		for (pos = 0, x = elt.boxObject.screenX, y = elt
			.boxObject.screenY; elt != null; elt = elt.parentNode)
		{
			if (elt.localName == 'window' || !elt.parentNode)
				break;
			else if ('toolbar' != elt.localName &&
				'hbox' != elt.localName && 'vbox' != elt.localName);
			else if (elt.boxObject.height >= 3 * elt.boxObject.width) {
				if (elt.boxObject.height >= 45) {
					pos = 9;
					break;
				}
			} else if (elt.boxObject.width >= 3 * elt.boxObject.height) {
				if (elt.boxObject.width >= 45) {
					pos = 8;
					break;
				}
			}
		}
		try {
			box = elt.boxObject;
			x = (pos & 1) ? (x <= box.width / 2 + box.screenX ? 1 : 3) :
							(y <= box.height / 2 + box.screenY ? 0 : 2);
		} catch (e) {
			x = 0;
		}
		return popupPos[x];
	}

	function getPopupNode(node) {
		if (whitesInx > -1 && PopElt)
			return PopElt;
		var elt, isPop, s;

		for (; node != null; node = node.parentNode) {
			if (node == PopElt)
				return node;

			isPop = false; //Node isn't Popup node
			s = node.localName;
			if (s == 'menupopup' || s == 'popup' || s == 'menulist'
			   || IsAutoComplete(node) || IsMenuButton(node))
				isPop = true;
			else if (s == 'dropmarker') {
				if (node.getAttribute('type') == 'menu') {
					elt = node.parentNode;
					if (elt.firstChild.localName == 'menupopup')
						isPop = true;
				} else if (node.className == 'autocomplete-history-dropmarker')
					isPop = true;
				else {
					try {
						isPop = node.parentNode.id == 'urlbar';
					} catch (ex) {}
				}
			} else if (s == 'menu')
				isPop = 'menubar' == node.parentNode.localName;
			else if (IsButton(node)) {
				for (elt = node; (elt = elt.nextSibling) != null;) {
					if (elt.localName == 'dropmarker' &&
						elt.boxObject.width > 0 &&
						elt.boxObject.height > 0)
						break;
				}
				if (elt) break;
			}
			if (isPop) break;
		}
		if (PopElt && node) {
			//Whether node is child of PopElt
			for (elt = node.parentNode; elt != null; elt = elt.parentNode) {
				if (elt == PopElt)
					return PopElt;
			}
		}
		return isPop ? node : null;
	}

	function AutoPopup() {
		PopTimer = null;
		if (!overElt) return;

		if (whitesInx > -1 && PopElt && whiteIDs[whitesInx].run) {
			whiteIDs[whitesInx].run(overElt);
			return;
		}
		!PopElt && (PopElt = overElt);

		if (overElt.localName == 'dropmarker')
			PopElt.showPopup();
		else if (overElt.localName == 'menulist')
			overElt.open = true;
		else if (IsNewMenuBtn(overElt)) {
			PanelUI.show();
			PopElt = document.getElementById(menuPanelID);
		} else if (IsWidgetBtn(overElt)) {
			var cmdEvent = document.createEvent('xulcommandevent');
			cmdEvent.initCommandEvent("command", true, true, window, 0, false,
				false, false, false, null);
			overElt.dispatchEvent(cmdEvent);
			PopElt = document.getElementById(widgetPanelID);
		} else if (IsDownloadBtn(overElt)) {
			PopElt = document.getElementById(downPanelID);
			DownloadsPanel.showPanel();
		} else if (IsSearchBtn(overElt)) {
			searchBar.openSuggestionsPanel();
			//console.log('search click!');
		} else {
			PopElt = getPopupMenu(overElt);
			try {
				var Pos = getPopupPos(overElt);
				PopElt.openPopup(overElt, Pos, 0, 0, false, false, null);
			} catch (e) {
				PopElt = null;
			}
		}
	}

	function HidePopup() {
		try {
			if (overElt.localName == 'dropmarker')
				PopElt.parentNode.closePopup();
			else if (overElt.localName == 'menulist')
				PopElt.open = false;
			else if (IsDownloadBtn(overElt))
				DownloadsPanel.hidePanel();
			//else if (IsNewMenuBtn(overElt) || IsWidgetBtn(overElt))
			else if (PopElt && PopElt.hidePopup)
				PopElt.hidePopup();
			else if (PopElt.popupBoxObject)
				PopElt.popupBoxObject.hidePopup();
			 else if (IsSearchBtn(overElt))
				 searchBar.textbox.closePopup();
		} catch (e) {}

		HideTimer = null;
		overElt = PopElt = null;
	}

	function MouseOver(e) {
		if (!AlwaysPop && !document.hasFocus())
			return;
		var popNode, n = e.originalTarget;

		whitesInx = -1;
		if (n.hasAttribute('id')) {
			for (let [i, k] in Iterator(whiteIDs)) {
				if (k.id == n.id) {
					overElt = n;
					whitesInx = i;
					PopElt = document.getElementById(k.popMemu);
					PopTimer = setTimeout(AutoPopup, nDelay);
					return;
				}
			}
		}
		popNode = getPopupNode(e.originalTarget);
		if (!popNode || (popNode && popNode.disabled) || isBlackNode(popNode)) {
			MouseOut();
			return;
		}

		if (HideTimer) {
			window.clearTimeout(HideTimer);
			HideTimer = null;
		}
		try {
			if (IsAutoComplete(popNode)) return;

			for (var elt = popNode; elt != null; elt = elt.parentNode) {
				if (elt.localName == 'menupopup' ||
				    elt.localName == 'popup')
					return;
			}
		}
		catch (ex) {}

		if (PopElt && popNode == PopElt && PopElt != overElt)
			return;
		if (overElt && popNode != overElt)
			HidePopup();
		overElt = popNode;
		PopElt = null;
		PopTimer = setTimeout(AutoPopup, nDelay);
	}

	function MouseOut(e) {
		if (PopTimer) {
			window.clearTimeout(PopTimer);
			PopTimer = null;
		}
		if (!HideTimer && PopElt)
			HideTimer = window.setTimeout(HidePopup, 500);
	}

	function IsButton(elt) {
		try {
			return elt.localName == 'button' ||
			elt.localName == 'toolbarbutton';
		} catch (e) {
			return false;
		}
	}

	function IsMenuButton(elt) {
		return IsNewMenuBtn(elt) || IsDownloadBtn(elt) || IsWidgetBtn(elt)
			|| (IsButton(elt) && getPopupMenu(elt));
	}

	searchBar = BrowserSearch.searchBar;
	window.addEventListener('mouseover', MouseOver, false);
})();
时间: 2024-10-08 10:25:07

firefox按钮菜单自动弹出uc脚本,修正Omnibar上的图标按钮有些不能弹出的问题的相关文章

toggleClass() 方法做类似于微信扣扣点击语音图标按钮变成切换到语音输入功能,点击键盘图标按钮切换到文字输入状态的效果

就是这种效果的类似. <html><head><script type="text/javascript" src="/jquery/jquery.js"></script><script type="text/javascript">$(document).ready(function(){ $(".wo").click(function(){ $("#l

layui弹出层type=2无法正常验证问题

思路:在弹出层页面form表单中增加一个隐藏的提交按钮,当弹出层点击确定按钮时,触发弹出层页面中的隐藏按钮,触发提交校验 弹出层脚本如下: function LoadDemo(id) { layer.open({ title: '弹出层标题', //弹出层标题 type: 2, content: 'demo.shtml', btn: ['确定', '关闭'], area: ["650px", "550px"], success: function (layero,

黄聪:TinyMCE 4 增强 添加样式、按钮、字体、下拉菜单和弹出式窗口

我最喜欢 WordPress 3.9 的更新是使用了 TinyMCE 4.0 编辑器.新的 TinyMCE 看起来看起来更整洁(真正匹配WP仪表板),它有一些非常不错的附加功能.我的很多老主题和插件必须更新为新 TinyMCE 的工作,所以我花了一些时间研究 API 并找出一些很酷的东西.下面我给你介绍下如何可以拓展 TinyMCE 功能的例子.我不会指导您完成所有步骤,或者是什么的代码意味着(这是为开发者),但会为您提供您的主题或插件可用的代码,你可以复制完全相同的代码,粘贴,然后相应地调整.

js+css实现带缓冲效果右键弹出菜单

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

仿微信右上角弹出菜单

使用PopupWindow实现仿微信右上角弹出菜单. 效果图如下: popupWindow代码如下: import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.stcyclub.e_community.R; import android.app.Activity; import android.content.Context; impo

向上弹出菜单jQuery插件

插件名:柯乐义英文名:Keleyijs文件名称:jquery.keleyi.js插件功能:该插件可以让你轻易地在页面上构建一个向上弹出的二级菜单. 支持浏览器: keleyi 0.1.4版本支持IE6以及以上.Chrome.火狐(Firefox).欧朋(Opera).Safari等浏览器,也支持IE6 keleyi 0.1.3版本支持IE8以及以上.Chrome.火狐(Firefox).欧朋(Opera).Safari等浏览器,不支持IE6. 示例查看:http://keleyi.com/kel

在弹出的菜单中模仿微信的右上角

采用PopupWindow在弹出的菜单右上角实现仿微信. 效果如下面的: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGlhb3lpX3RkY3E=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" > popupWindow代码例如以下: import java.util.ArrayList; import java.util.HashMap;

iOS_21团购_顶部菜单和弹出菜单联动

最后效果图: 各控件关系图1: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >\ 各控件关系图2: 点击Dock上面的buttonDockItem, 创建经导航控制器包装的DealListController, 而且加入到主控制器的右側空间 // // Deal

MFC右键弹出菜单

右键弹出菜单是指右键抬起的时候弹出的菜单.通常放置在Dialog的OnRButtonUp响应函数里. 下面就给出右键弹出菜单的实例: 1 添加右键事件及响应函数 可以用Class Wizard...来添加一个右键消息WM_RBUTTONUP,为其添加Handler,会自动生成OnRButtonUp响应函数 2 为弹出菜单添加资源 可以用"Resource View"中的"String Table"添加一个新的弹出菜单资源,这里假设资源ID : IDC_MENU_UP