Greasy Fork

Greasy Fork is available in English.

KonfluxMessageCleanup

Blast away konflux messages

目前为 2025-02-19 提交的版本。查看 最新版本

// ==UserScript==
// @name         KonfluxMessageCleanup
// @namespace    https://gitlab.cee.redhat.com/
// @version      2025-02-19
// @description  Blast away konflux messages
// @author       David O Neill
// @match        https://gitlab.cee.redhat.com/*
// @license      Apache2
// @icon         https://cdn.imgbin.com/3/22/25/imgbin-six-thinking-hats-red-hat-enterprise-linux-fedora-cartoon-cowboy-hat-i5r6w8BjC5Ua6Y7HxHZzFsEb9.jpg
// @grant        none
// ==/UserScript==

// Helper function to click all open confirmation modals
function clickAllModals() {
    const modals = document.querySelectorAll('div[data-testid="confirmation-modal"] button[data-testid="confirm-ok-button"]');
    if (modals.length > 0) {
        modals.forEach(btn => {
        btn.click();
        console.log('Clicked confirm on a modal');
        });
    }
}

// Continuously check for confirmation modals every 300ms
const modalInterval = setInterval(() => {
    clickAllModals();
    // Optionally stop checking if no more comments are being processed
}, 300);

// Function to delete all comments by 'konflux'
function deleteAllKonfluxComments() {
    document.querySelectorAll('.timeline-entry').forEach(comment => {
      const author = comment.querySelector('span[data-testid="author-name"]');
      if (author && author.textContent.trim() === 'konflux') {
        console.log(`Found comment by konflux: ${comment.id}`);

        // Open the 'More actions' menu
        const moreActionsButton = comment.querySelector('.more-actions-toggle button');
        if (moreActionsButton) {
          moreActionsButton.click();
          console.log('Opened more actions menu');

          // Short delay for dropdown
          setTimeout(() => {
            const deleteButton = comment.querySelector('.js-note-delete button');
            if (deleteButton) {
              deleteButton.click();
              console.log('Clicked delete button, waiting for modal...');
            }
          }, 500);
        }
      }
    });
}

function RHOTPLoaded() {
    console.log("Delete all comments")
    deleteAllKonfluxComments();

    console.log("RHOTPLoaded");

    console.log("Check ephemeral");
    if (window.location.href.includes("env-ephemeral")) {
        chrome.storage.sync.get("automaticLoginEph", (result) => {
            if (result["automaticLoginEph"].toString() == "true") {

                if (document.getElementById("#input-error") != null) {
                    return;
                }

                document.getElementById("kc-page-title").innerText = "Standby, signing you in..."
                chrome.runtime.sendMessage(
                    {
                        action: 'doAutomaticLogin',
                        context: "jdoeEphemeral"
                    },
                    function (response) {
                        chrome.storage.sync.get('creds', (result) => {
                            console.log('update password box');
                            const pwfield = document.getElementById("password");
                            const unfield1 = document.getElementById("username");

                            const unpw = result.creds.split(",");
                            const un = unpw[0];
                            const pw = unpw[1];
                            unfield1.value = un;
                            unfield1.style.border = "thick solid #0000FF";
                            pwfield.value = pw;
                            pwfield.style.border = "thick solid #0000FF";

                            setTimeout(function () {
                                const pwfield = document.getElementById("password");
                                let button = document.getElementById("kc-login");
                                console.log(pwfield.value);
                                console.log(button);
                                button.click();
                            }, 1000);
                        });
                    }
                );
            }
        });
    }

    console.log("Check openshiftapps.com/oauth/authorize");
    if (window.location.href.includes("openshiftapps.com/oauth/authorize")) {
        document.getElementsByClassName("pf-c-button")[0].click();
    }

    console.log("Check gitlab.cee.redhat.com/users/sign_in");
    if (window.location.href.includes("gitlab.cee.redhat.com/users/sign_in")) {
        document.getElementsByClassName("qa-saml-login-button")[0].click();
    }

    console.log("Check ci.int.devshift.net");
    if (window.location.href.includes("ci.int.devshift.net")) {
        console.log("ci.int.devshift.net login");
        let elements = document.getElementsByTagName("b");
        let arrayLength = elements.length;
        for (let i = 0; i < arrayLength; i++) {
            if (elements[i].innerText.trim() == "log in") {
                console.log("Set location: " + elements[i].parentElement.href);
                window.location.href = elements[i].parentElement.href;
                break;
            }
        }
    }
}


(function() {
    'use strict';
    window.addEventListener('load', RHOTPLoaded, false);
})();