Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name NotAboutBlank.uc.js
// @namespace http://d.hatena.ne.jp/Griever/
// @include main
// @version 0.0.1
// ==/UserScript==
var notAboutBlank = {
folderName : "",
// 読み込みたいフォルダ名
// スマートブックマークは無理っぽい
// ライブブックマークは OK
folderId : 3,
// 2 = ブックマークメニュー, 3 = ブックマークツールバー, 4 = 最近付けたタグ, 5 = 未整理のブックマーク, etc = フォルダの itemId
// folderName が "" の時にはこのフォルダが読み込まれる
viewFolder : false,
// フォルダも表示するか
viewLiveBookmark : true,
// ライブブックマークも表示する
viewSmartBookmark : true,
// スマートブックマークも表示する
viewLogo: true,
// 背景の Firefox 画像を表示する
icon : {
none : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABMklEQVQ4jZWMTYqDQBBGvems5wgewLUX8Aa6EJE0Yogb7xCyUuYE6f8/wzeLpIcuMjBMweNRUPWKoiiKZVnwF/M8H0KIsvhtlmXBESOOI1K/WNcV+76DMfbYvrbPt8DlckGMAUeMxIl1XWGMgTEGp9PJ3263DxI4n88IwSPGQJzIA9frFdM0gQTmeUbw7vmQ+wVjjPAWmKYJ3lkE74gTwTvs2/YDY4wGGGNw1sA7S5zIY97Z98A4jrDmeZw7kcecNRjHkQaGYYDRGtZo4oQ1lGEYaKDvexilng+5E5oG+76nga7roKWEVoo6oRSh6zoaaNsWSghoKYkTJCYl2ralgaZpIF/HuWW25zRNQwN1XUNyDik4Nc/2jLquaaCqKoj7HZJz4gSJcY6qqmigLEv8l/T7DQCF4M+cckVPAAAAAElFTkSuQmCC',
folder : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACM0lEQVQ4jZ3P72sScQDH8ftr9lfUBhH0KEJWY1H6YMHVENYqI1KI9cDoQSNl9KCEVpCzXytGqVtbNVeuTJpt/jidO39sbv6Ynp47vTs9/fTg5LRNn3Tw4svne/CGL0EQBJH2kRMl+haK0ZtgWgqR69gPjmE/MIa0bxTptVGk165gxzMyQRz+ips6CMxroEH3lAs9ABo0tlc1OBJgNnXg89NoCnY0hY9tvLwhpZAL3EVT/I7Eirp7QCy+glSZReMwbhbNehKpX+No8J8R7xYohG9AZKyQWCsk9oWi3jqbtTiS7kuQOCdirovdA3x+GmLBglqnvAViwYKGGEV0aRh19j3o5Qv/F4gsnO0dyPmvgs8+gZAxQciYwGfN4LNmCBkzhIwJEk8h6FBBLMyA/nIeYRf5kvZo+5TAjpdEdW8K1dS9FmOLvKWKH0GHCtWUEXsb9xFdGkZsVftYCSR/jKC6+whc3AAuYQAX18sSenBxA+qcD+tzp8El9KjuTiFHmRFZHGo/hXapUdmeRDl6DeXouOKgddbLXnjenEJ5S94is4jwQkcg5BzEQcyIUogES5EoUZcVLEWixv6E23YSLCX/F/IOUAuD7QA1fw7lrTso+jWygFrm16DkV0MsuvHNegJFv3zH5+YQdHYEgnYV2MhtMOtDYP4cJTIrWH7Wr2w+8w4Bu+rfJ7BhXU819je+Pj2mbD7zFhsfzrQDnx72ab22AXis/T25nh+H1zagCM6rJgmCIP4C+T2r1CSiWZ4AAAAASUVORK5CYII=',
live : 'chrome://browser/skin/livemark-folder.png',
smart : 'chrome://browser/skin/places/query.png',
},
css : <![CDATA[
body {
margin: 0;
padding: 0;
text-align: center;
overflow-y: hidden;
}
#logo {
width: 100%;
position: absolute;
top: 0;
left:0;
z-index: 0;
}
ul {
padding: 0;
margin : 2% 1% 0 0;
list-style: none;
text-align: left;
z-index: 1;
position: relative;
}
li {
opacity: 0.9;
padding : 0;
margin: 0.2em 1%;
cursor: pointer;
vertical-align: middle;
display: block;
width: 45%;
-moz-border-radius: 8px;
background-color: #eef;
border: 4px solid;
-moz-border-top-colors: #999 #ddd #fafafd #f8f8fc;
-moz-border-right-colors: #999 #fff #fafafd #f8f8fc;
-moz-border-bottom-colors: #999 #fff #fafafd #f8f8fc;
-moz-border-left-colors: #999 #ddd #fafafd #f8f8fc;
}
li:nth-child(4n+2), li:nth-child(4n+3){
background-color: #FFFFF0;
border: 4px solid;
-moz-border-top-colors: #999 #ddd #fafaf8 #fcfcf6;
-moz-border-right-colors: #999 #fff #fafaf8 #fcfcf6;
-moz-border-bottom-colors: #999 #fff #fafaf8 #fcfcf6;
-moz-border-left-colors: #999 #ddd #fafaf8 #fcfcf6;
}
li:hover {
background-color: #fff0ff;
border: 4px solid;
-moz-border-top-colors: #999 #fff #faf8fa #fcf6fc;
-moz-border-right-colors: #999 #ddd #f0f8f0 #fcf6fc;
-moz-border-bottom-colors: #999 #ddd #f0f8f0 #fcf6fc;
-moz-border-left-colors: #999 #fff #faf8fa #fcf6fc;
}
.favicon {
vertical-align: middle;
width: 16px;
height: 16px;
position: absolute;
margin-top: 8px;
margin-left: 8px;
}
.text-title{
white-space: nowrap;
overflow: hidden;
display: block;
color: #002;
font-size: 0.85em;
font-weight: bold;
text-shadow : 3px 2px 1px #bac;
padding-left: 30px;
padding-right: 0.5em;
}
.text-uri {
padding-left: 40px;
padding-right: 0.5em;
white-space: nowrap;
overflow: hidden;
display: block;
color: #080;
font-size: 0.8em;
text-align:right;
}
]]>.toString(),
popups : [],
getVersion : function(){
var info = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
return parseInt(info.version.substr(0,3) * 10,10) / 10;
},
getFolderId : function(aItemId, folderName){
var rootNode = PlacesUtils.getFolderContents(aItemId).root;
for (var i = 0; i < rootNode.childCount; i++) {
var node = rootNode.getChild(i);
if (node.type == 5 || node.type == 6){
if (node.title == folderName){
return node.itemId;
}else
if (PlacesUtils.nodeIsFolder(node)
&& !PlacesUtils.nodeIsLivemarkContainer(node)){
var hoge = arguments.callee(node.itemId, folderName);
if (hoge)
return hoge;
}
}
}
return;
},
getFolderItems : function(aItemId){
var rootNode = PlacesUtils.getFolderContents(aItemId).root;
for (var i = 0, items = []; i < rootNode.childCount; i++) {
var node = rootNode.getChild(i);
items.push({
title : node.title,
uri : node.uri,
type : node.type,
icon : (node.icon ? node.icon.spec : ""),
itemId : node.itemId,
tags : node.tags,
isLive : PlacesUtils.nodeIsLivemarkContainer(node),
});
}
return items;
},
getBookmarks : function(){
var folder = this.folderName? this.getFolderId(1, this.folderName) : this.folderId;
var folderItems = this.getFolderItems( (folder || this.folderId) );
return folderItems;
},
run : function(){
var df = notAboutBlank.df.cloneNode(true);
gBrowser.contentDocument.body.appendChild(df);
gBrowser.contentWindow.addEventListener('click', notAboutBlank, false);
gBrowser.contentWindow.addEventListener('unload', notAboutBlank, false);
},
handleEvent : function(event){
if (event.type == 'unload'){
gBrowser.contentWindow.removeEventListener('click', this, false);
gBrowser.contentWindow.removeEventListener('unload', this, false);
return;
}
if (event.button == 2)
return;
var target = event.target;
while(target){
if (target instanceof HTMLLIElement)
break;
target = target.parentNode;
}
if (!target)
return;
var uri = target.getAttribute('uri');
if (/^(http|file)/.test(uri)){
event.button == 0? loadURI(uri) : gBrowser.loadOneTab(uri);
}else{
if (!this.popups[uri]){
var popup = document.createElement('menupopup');
popup.setAttribute("class", "dislikesBlank_menu");
popup.setAttribute("type", "places");
popup.setAttribute("place", uri);
popup.setAttribute("context", "placesContext");
popup.setAttribute("openInTabs", "children");
popup.setAttribute("oncommand", "BookmarksEventHandler.onCommand(event);");
popup.setAttribute("onclick", "if(event.button==2){event.preventDefault();event.stopPropagation();}else BookmarksEventHandler.onClick(event);");
popup.setAttribute("onpopupshowing", "BookmarksEventHandler.onPopupShowing(event);");
document.getElementById('mainPopupSet').appendChild(popup);
this.popups[uri] = popup;
}
this.popups[uri].openPopupAtScreen(event.screenX, event.screenY, true);
}
},
init : function(){
if (typeof BrowserOpenTab_original == 'undefined'){
BrowserOpenTab_original = BrowserOpenTab;
if (this.getVersion() >= 3.1){
eval('BrowserOpenTab = ' + BrowserOpenTab.toString().replace(/\}$/, "content.addEventListener('load', notAboutBlank.run, true);}"));
}else{
eval('BrowserOpenTab = ' + BrowserOpenTab.toString().replace(/\}$/, "setTimeout(notAboutBlank.run, 100);}"));
}
}
var html = 'http://www.w3.org/1999/xhtml';
this.df = document.createDocumentFragment();
this.df.appendChild(document.createElementNS(html, 'style')).appendChild(document.createTextNode(this.css));
if (this.viewLogo){
var logo = document.createElementNS(html, 'img');
logo.setAttribute("id", "logo");
logo.setAttribute("src", "about:logo");
this.df.appendChild(logo);
}
var ul = document.createElementNS(html, 'ul');
this.getBookmarks().forEach(function(elem, index){
if (elem.uri.substr(0, 11) == 'javascript:'
|| elem.type == 7
|| (this.viewFolder == false && elem.type == 6 && !elem.isLive)
|| (this.viewSmartBookmark == false && elem.type == 5)
|| (this.viewLiveBookmark == false && elem.isLive))
return;
var li = document.createElementNS(html, 'li');
li.setAttribute("uri", elem.uri);
var img = document.createElementNS(html, 'img');
switch(elem.type){
case 0 :
img.setAttribute("src", (elem.icon || this.icon.none));
li.className = 'page';
break;
case 5 :
img.setAttribute("src", this.icon.smart);
li.className = 'smart';
break;
case 6 :
if (elem.isLive){
img.setAttribute("src", this.icon.live);
li.className = 'live';
break;
}
img.setAttribute("src", this.icon.folder);
li.className = 'folder';
break;
}
img.className = 'favicon';
li.appendChild(img);
var title = document.createElementNS(html, 'span');
title.appendChild(document.createTextNode(elem.title));
title.className = 'text-title';
li.appendChild(title);
var uri = document.createElementNS(html, 'span');
uri.className = 'text-uri';
uri.appendChild(document.createTextNode(elem.uri));
li.appendChild(uri);
ul.appendChild(li);
}, this);
this.df.appendChild(ul);
},
};
notAboutBlank.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.