>Форум Mozilla Россия http://forum.mozilla-russia.org/index.php >Разработка http://forum.mozilla-russia.org/viewforum.php?id=18 >Разработка расширения - чем заменить eval()? http://forum.mozilla-russia.org/viewtopic.php?id=50654 |
LA_ > 12-07-2011 23:56:29 |
в строке 54: Выделить код Код:const fKey = new function () { var prefBranch = null; var hotkeys = []; const getBlankTab = function(url) { var i = 0; var tabs = gBrowser.mTabContainer.childNodes; for (i = 0; i < tabs.length; i++) { if ((gBrowser.getBrowserForTab(tabs[i]).contentDocument.location == "about:blank") || (gBrowser.getBrowserForTab(tabs[i]).contentDocument.location == "chrome://fastdial/content/fastdial.html") || (gBrowser.getBrowserForTab(tabs[i]).contentDocument.location == url)) return tabs[i]; } return null; }; const handleShortcutKey = function(aEvent) { var curKeyCode = Number(aEvent.keyCode - aEvent.DOM_VK_F1); /* DOM_VK_F1 to DOM_VK_F12 */ if (curKeyCode >= 0 && curKeyCode <= 11) { if(hotkeys[curKeyCode].value != undefined && hotkeys[curKeyCode].value != "") { /* enum all tabs */ var url = hotkeys[curKeyCode].value; var tab = getBlankTab(url); if (tab == null) { gBrowser.selectedTab = gBrowser.addTab(url); } else { gBrowser.selectedTab = tab; gBrowser.loadURI(url); } aEvent.preventDefault(); aEvent.stopPropagation(); } } }; const setKeyBinding = function() { }; this.openSetting = function() { window.openDialog('chrome://fkeyshortcut/content/setting.xul', 'fKey-settingDialog', 'resizable, centerscreen, chrome', hotkeys); } this.init = function() { var prefSvc = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService); prefBranch = prefSvc.getBranch('fkeyshortcut.'); hotkeys = eval(prefBranch.getCharPref('hotkey')); window.addEventListener('keypress', handleShortcutKey, true); }; } window.addEventListener('load', function() { gBrowser.addEventListener("load", fKey.init, true); }, false); |
hydrolizer > 13-07-2011 03:44:43 |
Infocatcher > 13-07-2011 09:10:54 |
LA_ > 13-07-2011 18:57:48 |
спасибо! |