frontendler
Goto Top

Script Hilfe Keybind

Hallöchen ich habe ein Problem.

Ich würde gerne mein Script erweitern, bin in Sachen Programmierung eine vollkommene Niete :D.
Klar, die ein oder andere Sache habe ich hinbekommen, aber mit meinem vorhaben scheitere ich gerade und bitte daher hier um Hilfe.
Es geht um ein Script Addon für Chrome das sich Tampermonkey nennt.
Dort hat mir jemand ein gewünschtes Script geschrieben (Er meinte ich solle nach Javascript suchen, daher habe ich es mal als Tag hinzugefügt, hoffe es ist richtig.), welches ich dann mit Glück etwas erweitern konnte, einfach weil ich mich noch ein wenig mit Variablen auskannte.
Das war es aber auch und nun stehe ich auf dem schlau.

Ich möchte:
Das das Script, nach dem erfolgreichen Neu Laden einer Webseite, einen Keybind ausführt.

Als Beispiel:
Heißt, das Script läuft, wartet... Event beginnt, Script führt den Reload aus (Seite lädt einmal neu), wartet paar Sekunden und drückt dann automatisch zb. STRG + ENDE.
Der Grund warum ich das möchte: Chrome erlaubt ja: Tastenkombinationen womit extension ausgelöst werden. Und genau das möchte ich damit erreichen.

Script Ohne Versuch:
// ==/UserScript==
(function() {
    'use strict';  
    document.title = "ReloadxRecord"  
    const timeToWait = 15; // in seconds
    //waits a few seconds before checking if someone is live
    setTimeout(() => {
        // only check if channel isn't already live when the script started (main use for reloading the page if live) 
        if (document.querySelector('.twilight-main .live-indicator-container') === null) {  
            checkIfLive();
        }
        else {
            const current = new Date();
            const time = current.toLocaleTimeString("de-DE");  
            console.log("                                                                          %cπŸ“— Reload was successful  βŒ›βŒ› " + time + " βŒ›βŒ›  channel is live πŸ“—","background:green;color:#fff;font-size: x-large");  
        }
    }, timeToWait * 1000);

    function checkIfLive() {
        if (document.querySelector('.twilight-main .live-indicator-container') !== null) {  
            //reload page because channel is live:
            location.reload();
        }
        const current = new Date();
        const time = current.toLocaleTimeString("de-DE");  
        console.log("                                                                         %cπŸ“• Channel is not live  βŒ›βŒ› " + time + " βŒ›βŒ›  checking again... πŸ“•","background:red;color:#fff;font-size: x-large");  
        setTimeout(() => checkIfLive(), timeToWait * 1000);
    }

})();


Probiert habe ich es so, was nur nicht funktioniert :S :

// ==/UserScript==
(function() {
    'use strict';  
    document.title = "ReloadxRecord"  
    const timeToWait = 15; // in seconds
    //waits a few seconds before checking if someone is live
    setTimeout(() => {
        // only check if channel isn't already live when the script started (main use for reloading the page if live) 
        if (document.querySelector('.twilight-main .live-indicator-container') === null) {  
            checkIfLive();
        }
        else {
            const current = new Date();
            const time = current.toLocaleTimeString("de-DE");  
            console.log("                                                                          %cπŸ“— Reload was successful  βŒ›βŒ› " + time + " βŒ›βŒ›  channel is live πŸ“—","background:green;color:#fff;font-size: x-large");  
        }
    }, timeToWait * 1000);

    function checkIfLive() {
        if (document.querySelector('.twilight-main .live-indicator-container') !== null) {  
            //reload page because channel is live:
            location.reload();
        }
        const current = new Date();
        const time = current.toLocaleTimeString("de-DE");  
        console.log("                                                                         %cπŸ“• Channel is not live  βŒ›βŒ› " + time + " βŒ›βŒ›  checking again... πŸ“•","background:red;color:#fff;font-size: x-large");  
        document.onkeyup = function(e) {
            if (e.ctrlKey && e.which == 35) {
                alert("strg+end key was pressed");  
            }
        }
        setTimeout(() => checkIfLive(), timeToWait * 1000);
    }

})();

Ich hoffe mir kann jemand die richtige Lösung geben, denn wie gesagt, ich habs probiert, aber mit null Programmierungskünsten wird das wohl nix. Zumal ich Arbeiten muss und schon 2-3 Tage daran versuche :S face-sad.

Ich bedanke mich vielmals face-smile

Grüße

Content-Key: 4970970737

Url: https://administrator.de/contentid/4970970737

Printed on: May 2, 2024 at 20:05 o'clock