Teste bitte folgendes
JavaScript
// ==UserScript==
// @name Fritzbox Test
// @description Use you favorite favicon
// @match https://192.168.178.1/*
// @match http://192.168.178.1
// @match http://192.168.178.1/#/phone-books/book/259/entry/new
// @version 1.0
// ==/UserScript==
waitForKeyElements(
'#uiEntryname-input',
test
);
function test() {
document.getElementById('uiEntryname-input').value = 'Spam';
document.getElementById('uiNumbernew1-input').focus();
document.getElementById('uiEntryname-input').dispatchEvent(new Event('input', {bubbles: true}));
}
function waitForKeyElements(selector, callback, options) {
const defaults = {
waitOnce: true, // If true (default), wait for a single matching element. If false, continue to scan for
// new elements after the first match is found.
allElements: true, // If true (default), the callback will be triggered repeatedly for every matching element.
// If false, the callback will be triggered only for the first matching element.
logTree: false // If true, will log the full subtree to the console (useful for finding the actual element
// added to the page, which may be a parent of the desired element). Default: false.
};
options = {...defaults, ...(options || {})};
const elements = options.allElements ? document.querySelectorAll(selector) : [document.querySelector(selector)].filter(e => e != null);
if (elements.length > 0) {
// if the elements already exist, then call the function passed
elements.forEach(element => callback(element));
if (options.waitOnce) {
return;
}
}
let called = false;
const observer = new MutationObserver(mutations => {
mutations
.filter(({addedNodes}) => addedNodes.length) // keep only newly added elements
.forEach(({addedNodes}) => {
[...addedNodes]
.filter(element => {
if (element?.querySelector?.(selector)) {
document.getElementById('uiEntryname-input').value = 'Spam';
document.getElementById('uiEntryname-input').dispatchEvent(new Event('input', {bubbles: true}));
document.getElementById('uiNumbernew1-input').focus();
}
//return true;
})
.filter(element => element?.matches?.(selector))
.forEach(element => {
if (options.allElements || !called) {
if (options.waitOnce) {
observer.disconnect(); // here in case the callback modifies the elements
}
called = true; // cancel the callback only when actually matched
callback(element, observer);
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
Alles anzeigen