Es ist sehr überfordnernd, wenn eine Anleitung auf vier oder mehr Seiten verstreut ist, anstatt eine einzelne vollständige Erklärung zu haben. Ich habe bis jetzt folgende Dinge geändert und ich habe weiterhin nicht die gewünschten Buttons in Symbolleiste anpassen. Ich hätte gern Buttons, die Chronik und Lesezeichen (und vielleicht ja auch Downloads) direkt in der Sidebar öffnen, anstatt in den Drop-Down-Fenstern. Was habe ich falsch gemacht? Was fehlt noch?
Code: [Profilordner]\chrome\sidebarumschalter.uc.js
(function() {
if (location != 'chrome://browser/content/browser.xul') return;
try {
// Lesezeichen-Seitenleiste Öffnen/Schließen
CustomizableUI.createWidget({
id: 'BookmarksSidebar-ToolBarButton',
type: 'custom',
defaultArea: CustomizableUI.AREAS,
onBuild: function(aDocument) {
var toolbaritem = aDocument.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'toolbarbutton');
var props = {
id: 'BookmarksSidebar-ToolBarButton',
class: 'toolbarbutton-1 chromeclass-toolbar-additional',
label: 'Lesezeichen-Sidebar',
tooltiptext: 'Lesezeichen-Sidebar öffnen/schließen',
style: 'list-style-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAGzElEQVR4Xr2Xe2xT5xnGf985x3Z8iUMChIQ7hd1KabhuBbEOVWMDKoFalKGJXlhXpZCuG9OgnbRWGesfgwYGFWwSWZeJlW5lbXfR6EY31gpKyk0TtxbScd0IgQTHIY4v8bm9w7MtZzSKrG30Jz3+fCxL53mf85zz2fw/eWvbiBWxMwuPvLE+PJ+Pm5bmO56VxF4ROS8HdnyyEVAUgcb/yIsL8P1t16wfz/nqS89jlIM46Hr5kIZaPIAq1oDiv2DT16lYtHrRr6YvaazHTkLiJNhRwuHyspAPT9EJ1Nai7ds8eu2ZnTN3/GVjdd3ONUxtqCPAIDR9gwlfeXj5Hybd+60HSF6GdAeIBq6NbvjDcR1PQ5EJqLleghOqqh799Oz5j3xxyYrtyx5+6kj9sqVHT7w8o3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WWfQ33luZn5OaPC9MPWGPJvxhYlsbVG9c6z0e7Wy7FEvuifbwvGh1o9BrOTV0hkXkCq/wPi6Vjyt8eNyJUgwhohWtfeA9QRAdcONMRP/1BV++f2pPpI6ZwUVn0aBq9PQa9V23STU3YebsGQE2p79vjykpqsBzQDUAvjOS6oIT+oGTgDihFMmVZ77ZHNnenOFii0as5xGM2ydNJrIG2ZmP7KmbNHhpeiy+U3f+VAQLi2Iht4tppRExQDoahUDeFFEz0Bw2icbM9ZXMCjbbTkGz6WX7agTG8UBm3VDoeTZtJKxFPWmayzzZjfY4TS7hOLO3KjT7X7UmIG632eSbPGzlsqTeggeMUDChAsmXtTPS1xh3arA9JNO3DZnAwehxOvX698yGgzBJSjksCnbRA2nEwlYGtXGyADtvZ623rCsweNWqhLyBgJUGpggMnY8A8ZSVIsA+XIjC6DaJBOKoJHiW4joGj2djKwRU9u//h4oaSKCNI97FUamO4vXPkXaPH1Xj9XkhFAQ00MNO2XE9bpwhirwOhSFRtLXrDFzD+veZ6X1CBhkcp2biKMT9ZydLWteVt1oszRLZ9RuSFSpGN1dL5/YrI1jpmZ77HbSC/VwQbH2dC8yrq2787PO5unSmyabzI+ko5/Uzo8A+fYHxmVwW4Hf+MJL6TlDdFV1Rj7/5YZEus46qgB8EWrqXM9/tsYtVNONxOGkDLPLzWP8mU3fVGs71urMi6Knl1pbY6kxCguN1kOtO4ksrGej63/0nf7rOrg63b6rl3Uy1+Pi4aavG+UE/V5nqmblnFrB/VUZ35jOLhXxNNAlveGHtSAAAAAElFTkSuQmCC)',
onclick: 'if (event.button == 0) { \
SidebarUI.toggle("viewBookmarksSidebar"); \
}; '
};
for (var p in props)
toolbaritem.setAttribute(p, props[p]);
return toolbaritem;
}
});
// Chronik-Seitenleiste Öffnen/Schließen
CustomizableUI.createWidget({
id: 'HistorySidebar-ToolBarButton',
type: 'custom',
defaultArea: CustomizableUI.AREAS,
onBuild: function(aDocument) {
var toolbaritem = aDocument.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'toolbarbutton');
var props = {
id: 'HistorySidebar-ToolBarButton',
class: 'toolbarbutton-1 chromeclass-toolbar-additional',
label: 'Chronik-Sidebar',
tooltiptext: 'Chronik-Sidebar öffnen/schließen',
style: 'list-style-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAAEEfUpiAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAADEFJREFUeNoARAC7/wCr0uwAHJATALvliwC65YkAAt/t9QDQYdT/msqz/+Hv5v8AabLaAP/30P8GWNH///rf/wTR3ewAkQj0APiZ+wCN0sEAAohh3eW3YDP2PO3+v+tpBwPT63///z/Ou/P/wqNvDL9+/3/CdPL4OQaGX08Zio2jGP4zP5VmuvmZ/Y9V/TegwfeA2q//AAggxjknnzOwsjAx8PBz/r9y6yyDhfFqBkYGBoY/32JOsrAdsGCs3fOA4fnD5//7IwQYeNh5gVLMDAyMTEDMzLDzZSkDy7m7rxnYWNgZuP+9YPj/4w1YgpGRBUizMNx/d5+B5cG7bwzMTIyMOo1v7qbFTlR68+Ud0BRGhqVn337Ns3HiAQggxjWX3oIUMOTuUWUAgfmhFTn/Gf5NAXMY/jMwzjv1goFPhIv/18efH6Rkexl+/v3I8Ps3GwMbowQjw/9/DEw/WJkYzp299yFSn5nBXriCoX3nGYaMNUsY/rPc+Q80iYHp7Zdf/1sD+BkevbvNwPD3K8P+6M0Mj3NvMKw5xc0ACl2mJ68+M3z58opBjpuTwWZGJDAAPgIVfmKIlAlh+PH/gQLLq88/GbiZvzD8//OD4cHFSUAF78FefM8hxfDmE/s7phdvPjM6L+EFSzzufgJU+B6Mr3wMALrxrzDLlz//GT6+fM+44Mn5/0++rWb4/usPgyi3OoMAuwHjN6CpAAF4JIOQKKIwjv/fm5ndcVrdic3tspGr4CZkYBAdJNAO4SEMSRCEwIsYgSAFgXgSkw5pxyKWSEzBi4ckCukSeuqgKIis26KLom7B1ujurL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HOYkp39M8KlGO+/59f35+/kRKVT7LstlkJcqSQJaL5ITyVX9yvJal5JuCmcXYjOGPZneNDY3r8mn+BO0xaa9m23bSsqwg2buxWCyyqnHyCF7+FzlsZdLDpuKDAAAAAElFTkSuQmCC)',
onclick: 'if (event.button == 0) { \
SidebarUI.toggle("viewHistorySidebar"); \
}; '
};
for (var p in props)
toolbaritem.setAttribute(p, props[p]);
return toolbaritem;
}
});
} catch(e) { };
})();
Alles anzeigen
Code: [Profilordner]\chrome\userChrome.css
#menubar-items,#TabsToolbar,#sidebar-header,#sidebar-search-container{display:none!important}
Code: [Profilordner]\chrome\userChrome.js
// userChrome.js
userChrome.ignoreCache = true;
userChrome.import("*", "UChrm");
Code: [Programmordner]\config.js
// config.js
const Cu = Components.utils;
try {
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/osfile.jsm");
if (!Services.appinfo.inSafeMode) {
let path = OS.Constants.Path.libDir;
if (Services.appinfo.OS == 'Darwin') { // macOS
path = OS.Path.join(OS.Path.dirname(path), "Resources");
};
var ucjsDirPath = OS.Path.join(path, "userChromeJS");
path = OS.Path.join(ucjsDirPath, "main.js");
let mainFileURI = OS.Path.toFileURI(path);
Services.scriptloader.loadSubScript(mainFileURI, this, "UTF-8");
};
} catch(e) {
Cu.reportError(e);
};
Alles anzeigen
Code: [Programmordner]\userChromeJS\main.js
// main.js
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the userChrome.js component.
*
* The Initial Developer of the Original Code is
* Simon Bünzli <zeniko@gmail.com>
*
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* alta88 <alta88@gmail.com>
* aborix <www.camp-firefox.de/forum>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
Cu.import("resource://gre/modules/FileUtils.jsm");
let UserChrome_js = {
init: function() {
Services.obs.addObserver(this, "final-ui-startup", false);
Services.obs.addObserver(this, "domwindowopened", false);
},
// observer
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "final-ui-startup":
let path = OS.Constants.Path.profileDir;
let ucFilePath = OS.Path.join(path, "chrome", "userChrome.js");
let ucFile = new FileUtils.File(ucFilePath);
if (!ucFile.exists()) {
let path = OS.Path.join(ucjsDirPath, "Readme.txt");
let readmeFile = new FileUtils.File(path);
readmeFile.copyTo(ucFile.parent, "userChrome.js");
};
if (ucFile.exists() && ucFile.isFile()) {
let path = OS.Path.join(ucjsDirPath, "utilities.js");
this.utilFileURI = OS.Path.toFileURI(path);
this.ucFileURI = OS.Path.toFileURI(ucFilePath);
// Services.obs.addObserver(this, "domwindowopened", false);
};
Services.obs.removeObserver(this, "final-ui-startup");
break;
case "domwindowopened":
aSubject.addEventListener("load", this, {capture: true, once: true});
break;
}
},
// event listener for load
handleEvent: function(aEvent) {
let document = aEvent.originalTarget;
let window = document.defaultView;
if (document.location && document.location.protocol == "chrome:") {
try {
Services.scriptloader.loadSubScript(this.utilFileURI, window, "UTF-8");
Services.scriptloader.loadSubScript(this.ucFileURI, window, "UTF-8");
}
catch (ex) {
// script execution can be stopped with |throw "stop";|
if (ex != "stop") {
Cu.reportError(ex);
}
}
};
}
};
UserChrome_js.init();
Alles anzeigen
Code: [Programmordner]\userChromeJS\Readme.txt
/*
* userChromeJS
*
* The file userChrome.js can be used to customize the functioning of Mozilla's
* user interface. Usage and syntax follow below; for useful code snippets see
* http://mozilla.zeniko.ch/userchrome.js.html.
*
* Examples:
* setTimeout(function() { document.title = "A new title for every window" }, 2000);
*
* if (location == "chrome://browser/content/browser.xul") {
* alert("Script loaded in main browser only");
* }
*
* // DOMi window
* if (location == "chrome://inspector/content/inspector.xul") {
* // Move Urlbar box to main toolbar
* var tb = document.getElementById('bxURLBar');
* var el = document.getElementById('mbrInspectorMain');
* if (tb && el) el.appendChild(tb, el.firstChild);
* }
*
* NOTE:
* userChromeJS includes an 'import' function to facilitate file management.
* An absolute path or relative path with Directory name property token can be
* used, as follows:
*
* // Single file (javascript .js or overlay .xul file)
* userChrome.import("Full file path");
* userChrome.import("Relative file path", "Token");
* // All .js and .xul files in a folder will be loaded.
* userChrome.import("Full file folder path");
* userChrome.import("Relative file folder path/name", "Token");
* userChrome.import("*", "Token");
*
* NOTE:
* Absolute windows files and folders must be have backslash escaped:
* "C:\\Program Files\\Mozilla\\scripts\\myscript.js"
*
* Examples:
* // Import script in [ProfileDir]/chrome/scripts/myscript.js
* userChrome.import("scripts/myscript.js", "UChrm");
* // Import script in [Profiles]/scripts/myscript.js (share same script in
* // multiple profiles
* userChrome.import("scripts/myscript.js", "DefProfRt");
* // All .js or .xul in profile chrome directory
* userChrome.import("*", "UChrm");
* // Import overlay
* userChrome.import("C:\\Program Files\\Mozilla\\scripts\\myOverlay.xul");
* // Import everything in Desktop folder /scripts
* userChrome.import("scripts", "Desk");
* // Perhaps the only thing you need in this file..
* if (location == "chrome://browser/content/browser.xul") {
* userChrome.import("scripts", "DefProfRt");
* }
*
* NOTE:
* For a full listing of directory tokens see the two links found here:
* https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#Getting_files_in_special_directories
* // What's the path for a token? This will print it in the console.
* userChrome.log(userChrome.getAbsoluteFile("Desk").path, "getAbsoluteFile:'Desk'");
*
* NOTE:
* userChromeJS includes a log function, invoked as follows:
* userChrome.log("string1"[, "string2"])
* Example:
* userChrome.log("hello world!", "myscript.js");
* Results in a console message:
* 2009-05-22 18:07:40 userChromeJS myscript.js: hello world!
*
* NOTE:
* The date format for the userChrome.log console logger may be user defined:
* Example:
* userChrome.dateFormat = "%Y-%m-%d %H:%M:%S";
*
* NOTE:
* The default charSet is "UTF-8"; for code using the 'import' or
* 'importFolder' functions to manage files, the charSet for subscript loader
* may be user defined, prior to calling the import or importFolder functions:
* Example:
* userChrome.charSet = "UTF-8";
*
* NOTE:
* Scripts are stored in a startup cache and loaded from it.
* After a change in userChrome.js you heve to restart Firefox with clearing
* this cache to make sure the changed file is read.
* By default this applies to imported .js files too. You can bypass the cache
* for these scripts with this statement BEFORE any import statement:
* userChrome.ignoreCache = true;
*
*/
Alles anzeigen
Code: [Programmordner]\userChromeJS\utilities.js
// utilities.js
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the userChromeJS utilities.
*
* The Initial Developer of the Original Code is
* alta88 <alta88@gmail.com>
*
* Portions created by the Initial Developer are Copyright (C) 2014
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* aborix <www.camp-firefox.de/forum>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* ........ Utility functions ............................................... */
var userChrome = {
path: null,
dirToken: null,
ignoreCache: false,
get loadOverlayDelay () {
if (!this._loadOverlayDelay)
this._loadOverlayDelay = 500;
return this._loadOverlayDelay;
},
set loadOverlayDelay(delay) {
this._loadOverlayDelay = delay;
},
get loadOverlayDelayIncr() {
if (!this._loadOverlayDelayIncr)
this._loadOverlayDelayIncr = 1600;
return this._loadOverlayDelayIncr;
},
set loadOverlayDelayIncr(delay) {
this._loadOverlayDelayIncr = delay;
},
import: function(aPath, aRelDirToken) {
let file;
this.path = aPath;
this.dirToken = aRelDirToken;
if (aRelDirToken) {
// Relative file
let absDir = this.getAbsoluteFile(aRelDirToken);
if (!absDir)
return;
let pathSep = absDir.path.match(/[\/\\]/)[0];
file = absDir.path + (aPath == "*" ?
"" : pathSep + aPath.replace(/[\/\\]/g, pathSep));
}
else
// Absolute file
file = aPath;
file = this.getFile(file);
if (!file)
return;
if (file.isFile()) {
if (/\.js$/i.test(file.leafName))
this.loadScript(file, aRelDirToken, null);
else if (/\.xul$/i.test(file.leafName)) {
let xul_files = [];
xul_files.push(file);
this.loadOverlay(xul_files, this.dirToken, null, this.loadOverlayDelay);
// this.loadOverlayDelay = this.loadOverlayDelay + this.loadOverlayDelayIncr;
}
else
this.log("File '" + this.path +
"' does not have a valid .js or .xul extension.", "userChrome.import");
}
else if (file.isDirectory())
this.importFolder(file);
else
this.log("File '" + this.path +
"' is neither a file nor a directory.", "userChrome.import");
},
loadScript: function(aFile, aFolder, aRelDirToken) {
setTimeout(function() {
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader)
.loadSubScriptWithOptions(userChrome.getURLSpecFromActualFile(aFile),
{target: window,
charset: userChrome.charSet,
ignoreCache: userChrome.ignoreCache});
// log it
userChrome.log(aRelDirToken ? ("[" + aRelDirToken + "]/" +
(aFolder && aFolder != "*" ? aFolder + "/" : "") + aFile.leafName) :
aFile.path, "userChrome.loadScript");
}, 0);
},
// XXX: Due to bug 330458, an overlay must finish before another can be
// called, otherwise neither are successful. Implementing an observer to
// serialize is better left as a fix in the core bug. Here, settimout values
// are set to minimize but there is no quarantee; overlay cdata (if any)
// needs to consider overlay completions and logging does not strictly mean
// an overlay has completed, rather that the overlay file has been invoked.
loadOverlay: function(aFiles, aRelDirToken, aFolder, aDelay) {
//userChrome.log(aDelay+" multiple import delay", userChrome.loadOverlay);
// Increment multiple import delay
this.loadOverlayDelay = this.loadOverlayDelay + this.loadOverlayDelayIncr;
setTimeout(function() {
if (aFiles.length > 0) {
//userChrome.log(userChrome.loadOverlayDelay+" inter folder delay", userChrome.loadOverlay);
// log it
userChrome.log(aRelDirToken ? ("[" + aRelDirToken + "]/" +
(aFolder && aFolder != "*" ? aFolder + "/" : "") + aFiles[0].leafName) :
aFiles[0].path, "userChrome.loadOverlay");
document.loadOverlay(userChrome.getURLSpecFromActualFile(aFiles.shift()), null);
setTimeout(arguments.callee, userChrome.loadOverlayDelay);
}
}, aDelay);
},
// Include all files ending in .js and .xul from passed folder
importFolder: function(aFolder) {
let files = aFolder.directoryEntries
.QueryInterface(Components.interfaces.nsISimpleEnumerator);
let xul_files = [];
while (files.hasMoreElements()) {
let file = files.getNext().QueryInterface(Components.interfaces.nsIFile);
if (/\.js$/i.test(file.leafName) && file.leafName != "userChrome.js")
this.loadScript(file, this.path, this.dirToken);
else if (/\.xul$/i.test(file.leafName)) {
xul_files.push(file);
}
}
if (xul_files.length > 0)
this.loadOverlay(xul_files, this.dirToken, this.path);
},
getFile: function(aPath, aRelDirToken) {
try {
let file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile);
file.initWithPath(aPath);
// Bad file doesn't throw on initWithPath, need to test
if (file.exists())
return file;
this.log("Invalid file '" + this.path + (this.dirToken ?
("' or file not found in directory with token '" + this.dirToken) :
"") + "' or other access error.", "userChrome.getFile");
}
catch (e) {
// Bad folder throws on initWithPath
this.log("Invalid folder '" + this.path + (this.dirToken ?
("' or folder not found in directory with token '" + this.dirToken) :
"") + "' or other access error.", "userChrome.getFile");
}
return null;
},
getAbsoluteFile: function(aRelDirToken) {
try {
let absDir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get(aRelDirToken, Components.interfaces.nsIFile);
return absDir;
}
catch (e) {
this.log("Invalid directory name token '" + this.dirToken +
"' or directory cannot be accessed.", "userChrome.getAbsoluteFile");
return null;
}
},
getURLSpecFromActualFile: Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.getProtocolHandler("file")
.QueryInterface(Components.interfaces.nsIFileProtocolHandler)
.getURLSpecFromActualFile,
/* Console logger */
log: function(aMsg, aCaller) {
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(this.date + " userChromeJS " +
(aCaller ? aCaller +": " : "") + aMsg);
},
get dateFormat() {
if (!this._dateFormat)
this._dateFormat = "%Y-%m-%d %H:%M:%S";
return this._dateFormat;
},
set dateFormat(format) {
this._dateFormat = format;
},
get date() {
let date = new Date();
// return date.toLocaleFormat(this.dateFormat);
try {
date = date.toLocaleFormat(this.dateFormat);
} catch(e) {
date = date.toString();
};
return date;
},
set charSet(val) {
this._charSet = val;
},
get charSet() {
if (!this._charSet)
this._charSet = "UTF-8"; // use "UTF-8". Defaults to ascii if null.
return this._charSet;
}
};
Alles anzeigen