Jetzt?
JavaScript
// BookmarkThisPage_Test03.uc.js
(function () {
if (location.href !== 'chrome://browser/content/browser.xhtml')
return;
// ## START UserCustomisation ##
const buttonIcon1 = 'bookmark-hollow.svg'; // Name.Dateiendung des anzuzeigenden Symbols | Name.file extension of the symbol to be displayed
const buttonIcon2 = 'bookmark.svg'; // Name.Dateiendung des anzuzeigenden Symbols | Name.file extension of the symbol to be displayed
const iconPath = '/chrome/icons/'; // Pfad zum Ordner der das Icon beinhaltet | Path to folder containing the icon
const label1 = 'Als Lesezeichen speichern'; // [starred=null]
const label2 = 'Lesezeichen bearbeiten'; // [starred="true"]
const tooltiptext = 'Site als Lesezeichen speichern/bearbeiten';
// ## END UserCustomisation ##
const oncommand = 'gContextMenu.bookmarkThisPage();';
const curProfDir = PathUtils.toFileURI(PathUtils.join(PathUtils.profileDir));
const menuitem1 = document.createXULElement('menuitem');
menuitem1.id = 'contextBookmarkpage';
menuitem1.setAttribute('tooltiptext', tooltiptext);
menuitem1.setAttribute('oncommand', oncommand);
menuitem1.classList.add('menuitem-iconic');
const refItem1 = document.getElementById('context-inspect');
refItem1.parentNode.insertBefore(menuitem1, refItem1.nextSibling);
// Status aktualisieren
const orig = document.getElementById('context-bookmarkpage');
// Funktion zum Aktualisieren des Labels und Icons
function updateMenuItem() {
const starred = orig.getAttribute('starred');
console.log(`starred attribute: ${starred}`); // Debugging-Ausgabe
if (starred === "true") {
menuitem1.setAttribute('label', 'funzt');
} else {
menuitem1.setAttribute('label', 'funzt nicht');
}
// starred-attribut vom Original 'context-bookmarkpage' clonen
menuitem1.setAttribute('starred', starred);
}
// MutationObserver einrichten
const observer = new MutationObserver(updateMenuItem);
observer.observe(orig, { attributes: true, attributeFilter: ['starred'] });
// Initiales Update
updateMenuItem();
let sss = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);
let uri = Services.io.newURI('data:text/css;charset=utf-8,' + encodeURIComponent(`
#contextBookmarkpage[starred="true"] image {
list-style-image: url(${curProfDir}${iconPath}${buttonIcon2}) !important;
transform: scale(0.9) !important;
-moz-context-properties: fill;
fill: orange !important;
}
#contextBookmarkpage[starred="true"]:hover image {
list-style-image: url(${curProfDir}${iconPath}${buttonIcon2}) !important;
fill: lightgreen !important;
}
#contextBookmarkpage[starred=null] image/*,
#contextBookmarkpage image*/{
list-style-image: url(${curProfDir}${iconPath}${buttonIcon1}) !important;
transform: scale(0.9) !important;
-moz-context-properties: fill;
fill: orange !important;
}
#contextBookmarkpage[starred=null]:hover image/*,
#contextBookmarkpage:hover image*/{
list-style-image: url(${curProfDir}${iconPath}${buttonIcon1}) !important;
fill: lightgreen !important;
}
`), null, null);
sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
})();
Alles anzeigen