STefan Müller schrieb am 21.10.2023 um 16:30 Uhr folgendes:
> OK, dafür (Python) fehlt mir elementares Wissen. Bekomme das Script
> nicht zum Laufen.
Wenn es nur um das öffnen von Seiten oder Links auf Seiten geht, schaul
Dir mal das ↓ Javascript an.
// ==UserScript==
// @name OpenWith
// @description Fügt dem Kontextmenü ein Menü hinzu, zum Öffnen
der aktuelle Seite und eines ausgewählten Links in einem anderen Browser.
// @description und eines ausgewählten Links in einem anderen
Browser.
// @version 1.2.1b 69+
// @author y2k
// @include main
// @charset UTF-8
// @namespace
http://tabunfirefox.web.fc2.com/
// @note Anwendungssymbol anzeigen
// @note als .uc.js Script umgeschrieben
// ==/UserScript==
(function() {
"use strict";
/*
Vor Verwendung, Pfad auf eigene Umgebung ändern(\ wird durch \\ ersetzt)
Zum Übergeben von Argumenten, wie folgt vorgehen:
C:\\Program Files\\Internet Explorer\\iexplore.exe<>$1 Argument Argument
※ $1 wird in URL umgewandelt
*/
const BrowserPath = {
"Brave": "C:\\Program Files
(x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe",
"Chromium":
"C:\\Users\\Inet\\AppData\\Local\\Chromium\\Application\\chrome.exe",
"Edge": "C:\\Program Files
(x86)\\Microsoft\\Edge\\Application\\msedge.exe",
"Internet Explorer": "C:\\Program Files\\Internet
Explorer\\iexplore.exe",
"Vivaldi": "C:\\Program Files\\Vivaldi\\Application\\vivaldi.exe",
};
const FlatMenu = false;
const OpenWith = {
start: function() {
const cm = document.getElementById("contentAreaContextMenu");
cm.addEventListener("popupshowing", function(e) {
if (e.target == this) { OpenWith.onpopup(e); }
}, false);
},
createMenu: function() {
if (this.pageItem || this.linkItem) {
return;
}
const contextMenu =
document.getElementById("contentAreaContextMenu");
const pageMenu = this.$C("menu", { id: "context-open-with-page",
label: "Seite öffnen mit..." });
contextMenu.insertBefore(pageMenu,
contextMenu.querySelector(":scope > #context-bookmarkpage, :scope >
#context-savepage"));
const linkMenu = this.$C("menu", { id: "context-open-with-link",
label: "Link öffnen mit..." });
contextMenu.insertBefore(linkMenu,
contextMenu.querySelector(":scope > #context-sep-open"));
this.pageItem = this.createMenuItem(pageMenu, "openPage",
FlatMenu? "Seite öffnen mit $1 ":" Öffnen mit $1");
this.linkItem = this.createMenuItem(linkMenu, "openLink",
FlatMenu? "Link öffnen mit $1 ":" Öffnen mit $1");
},
createMenuItem: function(menu, method, format) {
const frag = document.createDocumentFragment();
let menuitem = [];
for (let i of Object.keys(BrowserPath)) {
const item = this.$C("menuitem", {
label: format.replace("$1", i),
class: "menuitem-iconic",
image: "moz-icon:file:///" +
BrowserPath[i].split("<>")[0] + "?size=16",
value: JSON.stringify([ method, i ]),
});
item.addEventListener("command", this, false);
frag.appendChild(item);
menuitem[menuitem.length] = item;
}
if (!FlatMenu) {
const menupopup = this.$C("menupopup");
menupopup.appendChild(frag);
menu.appendChild(menupopup);
menuitem = [ menu ];
}
else {
const parent = menu.parentNode;
parent.insertBefore(frag, menu);
parent.removeChild(menu);
}
return menuitem;
},
$C: function(tag, attrs) {
const elem = document.createXULElement(tag);
if (attrs) {
for (let key of Object.keys(attrs))
elem.setAttribute(key, attrs[key]);
}
return elem;
},
onpopup: function(e) {
this.createMenu();
const isHtml = /^(https?|file):/.test(gBrowser.currentURI.spec);
const pageItemHidden = !isHtml || gContextMenu.onLink ||
gContextMenu.onTextInput;
const linkItemHidden = !isHtml || !gContextMenu.onLink ||
gContextMenu.onTextInput;
const pageItem = this.pageItem;
for (let i = 0, l = pageItem.length; i < l; i++) {
pageItem[i].hidden = pageItemHidden;
}
const linkItem = this.linkItem;
for (let i = 0, l = linkItem.length; i < l; i++) {
linkItem[i].hidden = linkItemHidden;
}
},
handleEvent: function(event) {
if (event.type === "command") {
const [ method, key ] =
JSON.parse(event.originalTarget.getAttribute("value"));
const url = method === "openPage"? gBrowser.currentURI.spec:
gContextMenu.linkURL;
this.launch(BrowserPath[key], url);
}
},
launch: function(browserPath, openURL) {
let [ path, args ] = browserPath.split("<>");
if (args) {
args = args.split("^^").map(a => a.replace("$1", openURL));
} else {
args = [ openURL ];
}
const file =
Cc['@
mozilla.org/file/local;1'].createInstance(Ci.nsIFile);
file.initWithPath(path);
const process =
Cc['@
mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
process.init(file);
process.run(false, args, args.length, {});
},
};
OpenWith.start();
})();
// Ende
Dafür müssen allerdings ein paar Vorbereitungen erfolgen, guckst Du da ↓.
<
https://www.camp-firefox.de/forum/thema/122615-funktionelle-%C3%A4nderungen-am-firefox-durch-skripte/>
<
https://www.camp-firefox.de/forum/thema/133123-firefox-115-wichtige-%C3%A4nderung-zur-nutzung-von-skripten/>
und wech
Ralf
--
ERROR: Coffeepot not found - Operator halted.