Created
May 6, 2010 10:12
-
-
Save Griever/391981 to your computer and use it in GitHub Desktop.
Opera のスタートバーを真似たもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name OperaStyle_startbar.uc.js | |
// @namespace http://d.hatena.ne.jp/Griever/ | |
// @include main | |
// @version 0.0.2 | |
// ==/UserScript== | |
(function(){ | |
if (!isElementVisible(gURLBar)) return; | |
var POPUP_POSITION = 0; // 0 = アドレスバーの下 | |
// 1 = コンテンツエリアに重ねる | |
var MOUSEOVER_POPUP = false; // アドレスバーにマウスが乗ったら表示 | |
var CUSTOMIZABLE = true; // カスタマイズできるようにする | |
// Thanks - http://www.xuldev.org/misc/ucjs.php | |
var mode = 'icons'; // 'icons', 'text' or 'full' | |
var size = 'large'; // 'small' or 'large' | |
// CUSTOMIZABLE = false の時のみ利用 | |
// array of toolbar item id, 'separator', 'spring' and 'spacer'. | |
var currentSet = [ | |
'personal-bookmarks', | |
'unified-back-forward-button', | |
'home-button', | |
'stop-button', | |
'reload-button', | |
'separator', | |
'bookmarks-button', | |
'history-button', | |
'downloads-button', | |
'separator', | |
'fullscreen-button', | |
]; | |
var panel = $E( | |
<panel id="startbar-panel"> | |
<toolbox id="startbar-toolbox"> | |
<toolbar id="startbar-toolbar" | |
class="chromeclass-toolbar" | |
context="toolbar-context-menu" | |
mode={mode} | |
iconsize={size} | |
customizable={CUSTOMIZABLE}/> | |
</toolbox> | |
</panel> | |
); | |
var toolbox = panel.firstChild; | |
toolbox.palette = $('navigator-toolbox').palette; | |
var toolbar = toolbox.firstChild; | |
toolbar.insertItem = $('nav-bar').insertItem; | |
if (!CUSTOMIZABLE) | |
currentSet.forEach(function(id){ toolbar.insertItem(id); }); | |
$('mainPopupSet').appendChild(panel); | |
window.startbar = { | |
panel: panel, | |
toolbox: toolbox, | |
toolbar: toolbar, | |
canPopup: true, | |
customizable: CUSTOMIZABLE, | |
isMouseover: MOUSEOVER_POPUP, | |
position: POPUP_POSITION, | |
init: function(){ | |
gURLBar.addEventListener('focus', this, false); | |
this.panel.addEventListener('popupshown', this, false); | |
this.panel.addEventListener('popuphidden', this, false); | |
//this.panel.addEventListener('command', this, false); | |
window.addEventListener('unload', this, false); | |
if (this.customizable) | |
$("cmd_CustomizeToolbars").addEventListener('DOMAttrModified', this, false); | |
if (this.isMouseover) | |
gURLBar.addEventListener('mouseover', this, false); | |
}, | |
uninit: function(){ | |
gURLBar.removeEventListener('focus', this, false); | |
this.panel.removeEventListener('popupshown', this, false); | |
this.panel.removeEventListener('popuphidden', this, false); | |
//this.panel.removeEventListener('command', this, false); | |
window.removeEventListener('unload', this, false); | |
if (this.customizable) | |
$("cmd_CustomizeToolbars").removeEventListener('DOMAttrModified', this, false); | |
if (this.isMouseover) | |
gURLBar.removeEventListener('mouseover', this, false); | |
}, | |
handleEvent: function(event) { | |
switch(event.type) { | |
case 'focus': | |
case 'mouseover': | |
if (this.panel.state == 'open') | |
return; | |
this.open(); | |
break; | |
case 'blur': | |
if (event.target != gURLBar) | |
return; | |
var self = this; | |
setTimeout(function(){ | |
var node = document.commandDispatcher.focusedElement; | |
if (node && node.compareDocumentPosition(self.panel) & node.DOCUMENT_POSITION_CONTAINS) | |
return; | |
self.panel.hidePopup(); | |
}, 20); | |
break; | |
case 'input': | |
case 'command': | |
this.panel.hidePopup(); | |
break; | |
case 'popupshown': | |
gURLBar.select(); | |
gURLBar.addEventListener('input', this, false); | |
gURLBar.addEventListener('blur', this, false); | |
break; | |
case 'popuphidden': | |
gURLBar.removeEventListener('input', this, false); | |
gURLBar.removeEventListener('blur', this, false); | |
break; | |
case 'DOMAttrModified': | |
if (event.attrName != 'disabled') | |
return; | |
if (event.newValue == 'true') { | |
$('navigator-toolbox').appendChild(this.toolbar); | |
} else { | |
this.toolbox.appendChild(this.toolbar); | |
} | |
break; | |
case 'unload': | |
this.uninit(); | |
break; | |
} | |
}, | |
open: function(){ | |
if (!this.canPopup) | |
return; | |
if (this.position == 1) { | |
this.panel.setAttribute('width', gBrowser.mCurrentBrowser.clientWidth); | |
this.panel.openPopup(gBrowser.mCurrentBrowser, 'overlap'); | |
} else | |
this.panel.openPopup(gURLBar, 'after_start'); | |
}, | |
} | |
// AutoComplete | |
gURLBar.showHistoryPopup_org = gURLBar.showHistoryPopup; | |
gURLBar.showHistoryPopup = function(){ | |
window.startbar.canPopup = false; | |
if (window.startbar.panel.state == 'open') | |
window.startbar.panel.hidePopup(); | |
gURLBar.showHistoryPopup_org(); | |
window.startbar.canPopup = true; | |
} | |
window.startbar.init(); | |
// http://gist.github.com/348749 | |
function $(id) document.getElementById(id); | |
function $E(xml, doc) { | |
doc = doc || document; | |
xml = <root xmlns={doc.documentElement.namespaceURI}/>.appendChild(xml); | |
var settings = XML.settings(); | |
XML.prettyPrinting = false; | |
var root = new DOMParser().parseFromString(xml.toXMLString(), 'application/xml').documentElement; | |
XML.setSettings(settings); | |
doc.adoptNode(root); | |
var range = doc.createRange(); | |
range.selectNodeContents(root); | |
var frag = range.extractContents(); | |
range.detach(); | |
return frag.childNodes.length < 2 ? frag.firstChild : frag; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment