GreasyFork: 導覽列增強

在導覽列上新增使用者列表,主機,收藏等..

目前為 2024-09-09 提交的版本,檢視 最新版本

// ==UserScript==
// @name        GreasyFork: User Control Panel Button
// @name:zh-CN  GreasyFork: 导航栏增强
// @description:zh-CN 在导航栏上添加用户列表,控制台,收藏等..
// @name:ar  GreasyFork: تعزيز شريط التنقل
// @description:ar إضافة قائمة المستخدمين على شريط التنقل,وحدة التحكم,جمع الخ..
// @name:bg  GreasyFork: Подобряване на лентата за навигация
// @description:bg Добавяне на потребителски списък в лентата за навигация,конзола,Колекция и др...
// @name:cs  GreasyFork: Vylepšení navigační lišty
// @description:cs Přidejte seznam uživatelů na navigační lištu,utěšit,Sbírka atd...
// @name:da  GreasyFork: Forbedring af navigationslinjen
// @description:da Tilføj brugerliste på navigationslinjen,konsol,Indsamling mv...
// @name:de  GreasyFork: Verbesserung der Navigationsleiste
// @description:de Benutzerliste zur Navigationsleiste hinzufügen,Konsole,Sammlung usw...
// @name:el  GreasyFork: Βελτίωση της γραμμής πλοήγησης
// @description:el Προσθήκη λίστας χρηστών στη γραμμή πλοήγησης,κονσόλα,Συλλογή κλπ...
// @name:en  GreasyFork: Navigation bar enhancement
// @description:en Add user list on navigation bar,console,Collection etc...
// @name:eo  GreasyFork: Plibonigo de navigado trinkejo
// @description:eo Aldonu uzantliston sur navigadbreto,konzolo,Kolekto ktp...
// @name:es  GreasyFork: Mejora de la barra de navegación
// @description:es Agregar lista de usuarios en la barra de navegación,consola,Colección, etc...
// @name:fi  GreasyFork: Navigointipalkin parannus
// @description:fi Lisää käyttäjäluettelo navigointipalkkiin,konsoli,Kokoelma jne...
// @name:fr  GreasyFork: Amélioration de la barre de navigation
// @description:fr Ajouter une liste d’utilisateurs sur la barre de navigation,console,Collecte etc..
// @name:he  GreasyFork: שיפור סרגל הניווט
// @description:he הוסף רשימת משתמשים בסרגל הניווט,לְנַחֵם,אוסף וכו’...
// @name:hr  GreasyFork: Poboljšanje navigacijske trake
// @description:hr Dodajte popis korisnika na navigacijsku traku,konzola,Zbirka itd...
// @name:hu  GreasyFork: A navigációs sáv továbbfejlesztése
// @description:hu Felhasználói lista hozzáadása a navigációs sávhoz,konzol,Gyűjtemény stb...
// @name:id  GreasyFork: Peningkatan bilah navigasi
// @description:id Tambahkan daftar pengguna di bilah navigasi,menghibur,Koleksi dll...
// @name:it  GreasyFork: Miglioramento della barra di navigazione
// @description:it Aggiungi l’elenco degli utenti sulla barra di navigazione,consolle,Raccolta ecc...
// @name:ja  GreasyFork: ナビゲーションバーの強化
// @description:ja ナビゲーションバーにユーザーリストを追加,コンソール,コレクションなど..
// @name:ka  GreasyFork: ნავიგაციის ზოლის გაუმჯობესება
// @description:ka დაამატეთ მომხმარებლის სია ნავიგაციის ზოლში,კონსოლი,კოლექცია და ა.შ...
// @name:ko  GreasyFork: 탐색 표시줄 개선
// @description:ko 탐색 표시줄에 사용자 목록 추가,콘솔,수집 등..
// @name:nl  GreasyFork: Verbetering van de navigatiebalk
// @description:nl Voeg een gebruikerslijst toe aan de navigatiebalk,troosten,Collectie enz...
// @name:nb  GreasyFork: Forbedring av navigasjonslinjen
// @description:nb Legg til brukerliste på navigasjonslinjen,konsoll,Samling etc...
// @name:pl  GreasyFork: Udoskonalenie paska nawigacji
// @description:pl Dodaj listę użytkowników na pasku nawigacyjnym,konsola,Kolekcja itp...
// @name:pt-BR  GreasyFork: Aprimoramento da barra de navegação
// @description:pt-BR Adicionar lista de usuários na barra de navegação,console,Coleção etc..
// @name:ro  GreasyFork: Îmbunătățirea barei de navigare
// @description:ro Adăugați lista de utilizatori pe bara de navigare,consolă,Colectare etc...
// @name:ru  GreasyFork: Улучшение панели навигации
// @description:ru Добавить список пользователей на панель навигации,консоль,Коллекция и т. д...
// @name:sk  GreasyFork: Vylepšenie navigačnej lišty
// @description:sk Pridajte zoznam používateľov na navigačnú lištu,konzoly,Zbierka atď...
// @name:sr  GreasyFork: Побољшање траке за навигацију
// @description:sr Додајте листу корисника на траку за навигацију,конзола,Збирка итд...
// @name:sv  GreasyFork: Förbättring av navigeringsfältet
// @description:sv Lägg till användarlista i navigeringsfältet,trösta,Samling etc...
// @name:th  GreasyFork: การเพิ่มประสิทธิภาพแถบนำทาง
// @description:th เพิ่มรายชื่อผู้ใช้บนแถบนำทาง,คอนโซล,คอลเลกชัน ฯลฯ..
// @name:tr  GreasyFork: Gezinme çubuğu geliştirmesi
// @description:tr Gezinme çubuğuna kullanıcı listesi ekleyin,konsol,Koleksiyon vb...
// @name:ug  GreasyFork: يولباشچى بالداقنى كۈچەيتىش
// @description:ug يولباشچى ستونىغا ئىشلەتكۈچى تىزىملىكىنى قوشۇڭ,console,توپلاش قاتارلىقلار...
// @name:uk  GreasyFork: Покращення панелі навігації
// @description:uk Додати список користувачів на панель навігації,консоль,Колекція тощо..
// @name:vi  GreasyFork: Cải tiến thanh điều hướng
// @description:vi Thêm danh sách người dùng trên thanh điều hướng,bảng điều khiển,Bộ sưu tập vv...
// @name:zh-TW  GreasyFork: 導覽列增強
// @description:zh-TW 在導覽列上新增使用者列表,主機,收藏等..
// @name:zh-HK  GreasyFork: 導覽列增強
// @description:zh-HK 在導覽列上新增使用者列表,主機,收藏等..
// @name:fr-CA  GreasyFork: Amélioration de la barre de navigation
// @description:fr-CA Ajouter une liste d’utilisateurs sur la barre de navigation,console,Collecte etc..
// @namespace   https://github.com/10086100886
// @match       https://gf.qytechs.cn/*
// @match       https://sleazyfork.org/*
// @grant       none
// @version 0.3.1.54
// @license     MIT
// @author      CY Fung  &  人民的勤务员 <[email protected]>
// @description    To add User Control Panel Button into navigation bar
// @icon           https://gf.qytechs.cn/vite/assets/blacklogo96-CxYTSM_T.png
// @supportURL              https://github.com/ChinaGodMan/UserScripts/issues
// @homepageURL   https://github.com/ChinaGodMan/UserScripts
// ==/UserScript==

(async () => {
    let sections = [
        { id: '#user-script-sets-section' },
        { id: '#control-panel' },
        // { id: '#user-library-list-section', name: '库' },
        //{ id: '#user-unlisted-script-list-section', name: '没上架' },
        //  { id: '#user-discussions', name: '讨论' },
        { id: '#user-script-list-section' }
    ]

    function preSetup() {
        let pos = document.querySelectorAll('#site-nav>nav>li.with-submenu')
        pos = pos.length >= 1 ? pos[pos.length - 1] : null

        if (!pos) return

        pos.parentNode.style.minHeight = '2.8rem'

        return { pos }
    }

    function setup(m, namespace) {
        const { cpmRoot } = m

        let h = cpmRoot.querySelector('h3') || cpmRoot.querySelector('header')
        if (!h) return

        let nav = document.createElement('nav')

        let addedText = new Set()
        let lastText = null

        for (const anchor of cpmRoot.querySelectorAll('li a[href]')) {
            let textContent = anchor.textContent.trim()

            if (addedText.has(textContent)) {
                lastText = textContent
                continue
            }

            let li = nav.appendChild(document.createElement('li'))
            li.appendChild(anchor)

            addedText.add(textContent)
        }

        if (lastText !== null) {
            nav.querySelectorAll('li').forEach(li => {
                if (li.querySelector('a').textContent.trim() === lastText) {
                    li.remove()
                }
            })
        }

        let tm = document.createElement('template')
        tm.innerHTML = `
        <li class="with-submenu" style="display: block;">
            <a href="#" onclick="return false">${namespace ? namespace : h.textContent}</a>
            <nav style="min-width: initial;">
                ${nav.innerHTML}
            </nav>
        </li>
    `.trim()

        return tm.content
    }

    function bufferToHex(buffer) {
        const byteArray = new Uint8Array(buffer)
        const len = byteArray.length
        const hexCodes = new Array(len * 2)
        const chars = '0123456789abcdef'
        for (let i = 0, j = 0; i < len; i++) {
            const byte = byteArray[i]
            hexCodes[j++] = chars[byte >> 4]
            hexCodes[j++] = chars[byte & 0x0F]
        }
        return hexCodes.join('')
    }

    async function digestMessage(message) {
        const encoder = new TextEncoder("utf-8")
        const msgUint8 = encoder.encode(message)
        const hashBuffer = await crypto.subtle.digest('SHA-1', msgUint8)
        return bufferToHex(hashBuffer)
    }

    async function fetchHTML(href) {
        let response = await fetch(href, {
            method: "GET",
            mode: "same-origin",
            cache: "force-cache",
            credentials: "same-origin",
            redirect: "follow",
            referrerPolicy: "no-referrer",
        })

        return response.text()
    }

    async function addSectionsToNav() {
        let presetup = preSetup()
        if (!presetup) return
        const { pos } = presetup

        let plink = document.querySelector('.user-profile-link')
        if (!plink) return
        let href = plink.querySelector('a[href*="/users/"]').href
        if (href.includes('/users/sign')) return

        let dm = await digestMessage(href)
        const stKey = `gf_user_page_${dm}`

        for (let trialN = 8; trialN--;) {
            let s = sessionStorage.getItem(stKey)
            let d = typeof s === 'string' ? parseInt(s) : 0
            if (d > 9 && Date.now() - d < 8000) await new Promise(r => setTimeout(r, 320))
            else break
        }

        const userPageHTML = await fetchHTML(href)
        if (!userPageHTML || typeof userPageHTML !== 'string') return

        sessionStorage.setItem(stKey, userPageHTML)

        let template = document.createElement('template')
        template.innerHTML = userPageHTML
        const content = template.content



        sections.forEach(({ id, name }) => {
            let section = content.querySelector(id)
            if (section) {
                const kc = setup({ cpmRoot: section, pos }, name)
                if (kc) {
                    pos.parentNode.insertBefore(kc, pos.nextSibling)
                }
            }
        })
    }

    if (!document.querySelector('.sign-out-link') || document.querySelector('.sign-in-link')) return

    await addSectionsToNav()
})()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址