Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
about:newtab を Speed Dial に変えるスクリプト。
// ==UserScript==
// @name NewTabPageDial
// @description Speed dial by about:newtab
// @namespace http://d.hatena.ne.jp/Griever/
// @author Griever
// @license MIT License
// @compatibility Firefox 21
// @charset UTF-8
// @include main
// @version 0.0.1
// ==/UserScript==
/*
about:newtab を Speed Dial に変えるスクリプト。
Opera のように Ctrl+1~9 でページ移動出来ます。
ただし、ピン留めされているページじゃないと移動出来ません。
好きなページはブックマークから D&D で登録できます。
*/
(function(CSS){
"use strict";
if (window.gNewTabPageDial) {
window.gNewTabPageDial.uninit();
delete window.gNewTabPageDial;
}
window.gNewTabPageDial = {
_pinned: [],
_prefName: "browser.newtabpage.pinned",
_readPref: function () {
var json = "";
try {
json = Services.prefs.getCharPref(this._prefName);
} catch (e) {
return
}
this._pinned = JSON.parse(json);
this._pinned.unshift({ url: "about:newtab", title: "" });
},
load: function(num) {
var item = this._pinned[num];
if (!item) return;
loadURI(item.url);
},
init: function() {
var keyset = document.getElementById("mainKeyset");
for (let i = 1; i <= 9; ++i) {
let key = document.createElement("key");
key.setAttribute("oncommand", "gNewTabPageDial.load("+ i +")");
key.setAttribute("id", "key_newtabpagedial_" + i);
key.setAttribute("key", i);
key.setAttribute("modifiers", "accel");
keyset.appendChild(key);
let defkey = document.getElementById("key_select" + (i === 9 ? "LastTab" : ("Tab" + i)));
defkey.setAttribute("disabled", "true");
}
this._readPref();
Services.prefs.addObserver(this._prefName, this, false);
},
uninit: function() {
Services.prefs.removeObserver(this._prefName, this);
},
observe: function(subject, topic, data) {
if (topic === "nsPref:changed") {
this._readPref();
}
},
};
window.gNewTabPageDial.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.