Forgejo owner search support

Support search owners while creating repos on Forgejo/Gogs pages.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Forgejo owner search support
// @namespace    http://tampermonkey.net/
// @version      0.1.4
// @description  Support search owners while creating repos on Forgejo/Gogs pages.
// @author       Scruel Tao
// @match        http*://*/repo/create
// @match        http*://*/repo/migrate*
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    if (document.querySelector('footer').textContent.indexOf('Powered by Gitea') !== -1) {
        alert('Gitea is a commercial project and has the worst open-source community now, use Forgejo instead.');
        return;
    }
    const ownerMenuElement = document.querySelector('div.ui.selection.owner.dropdown div.menu');
    const itemElements = Array.from(ownerMenuElement.querySelectorAll('div.item'));
    const inputElement = document.createElement('input');
    inputElement.setAttribute("type", "search");
    inputElement.setAttribute("placeholder", "Search...");
    inputElement.setAttribute("aria-label", "Search");
    inputElement.style.setProperty("width", "100%", "important");
    inputElement.style.setProperty("position", "sticky");
    inputElement.style.setProperty("top", "0");
    inputElement.style.setProperty("z-index", "16");
    ownerMenuElement.prepend(inputElement);

    function filterItems() {
        itemElements.forEach(item => {
            const itemText = item.innerText.trim().toLowerCase();
            if (itemText.indexOf(inputElement.value) == -1) {
                item.style.setProperty("display", "none", "important");
                return;
            }
            item.style.removeProperty("display");
        });
    }

    inputElement.onkeydown = (e) => {
        e.stopPropagation();
        return true;
    }
    inputElement.addEventListener('input', filterItems);
})();