GreasyFork: 导航栏增强

在导航栏上添加用户列表,控制台,收藏等..

目前为 2024-09-10 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GreasyFork: User Control Panel Button
  3. // @name:zh-CN GreasyFork: 导航栏增强
  4. // @description:zh-CN 在导航栏上添加用户列表,控制台,收藏等..
  5. // @name:ar GreasyFork: تعزيز شريط التنقل
  6. // @description:ar إضافة قائمة المستخدمين على شريط التنقل,وحدة التحكم,جمع الخ..
  7. // @name:bg GreasyFork: Подобряване на лентата за навигация
  8. // @description:bg Добавяне на потребителски списък в лентата за навигация,конзола,Колекция и др...
  9. // @name:cs GreasyFork: Vylepšení navigační lišty
  10. // @description:cs Přidejte seznam uživatelů na navigační lištu,utěšit,Sbírka atd...
  11. // @name:da GreasyFork: Forbedring af navigationslinjen
  12. // @description:da Tilføj brugerliste på navigationslinjen,konsol,Indsamling mv...
  13. // @name:de GreasyFork: Verbesserung der Navigationsleiste
  14. // @description:de Benutzerliste zur Navigationsleiste hinzufügen,Konsole,Sammlung usw...
  15. // @name:el GreasyFork: Βελτίωση της γραμμής πλοήγησης
  16. // @description:el Προσθήκη λίστας χρηστών στη γραμμή πλοήγησης,κονσόλα,Συλλογή κλπ...
  17. // @name:en GreasyFork: Navigation bar enhancement
  18. // @description:en Add user list on navigation bar,console,Collection etc...
  19. // @name:eo GreasyFork: Plibonigo de navigado trinkejo
  20. // @description:eo Aldonu uzantliston sur navigadbreto,konzolo,Kolekto ktp...
  21. // @name:es GreasyFork: Mejora de la barra de navegación
  22. // @description:es Agregar lista de usuarios en la barra de navegación,consola,Colección, etc...
  23. // @name:fi GreasyFork: Navigointipalkin parannus
  24. // @description:fi Lisää käyttäjäluettelo navigointipalkkiin,konsoli,Kokoelma jne...
  25. // @name:fr GreasyFork: Amélioration de la barre de navigation
  26. // @description:fr Ajouter une liste d’utilisateurs sur la barre de navigation,console,Collecte etc..
  27. // @name:he GreasyFork: שיפור סרגל הניווט
  28. // @description:he הוסף רשימת משתמשים בסרגל הניווט,לְנַחֵם,אוסף וכו’...
  29. // @name:hr GreasyFork: Poboljšanje navigacijske trake
  30. // @description:hr Dodajte popis korisnika na navigacijsku traku,konzola,Zbirka itd...
  31. // @name:hu GreasyFork: A navigációs sáv továbbfejlesztése
  32. // @description:hu Felhasználói lista hozzáadása a navigációs sávhoz,konzol,Gyűjtemény stb...
  33. // @name:id GreasyFork: Peningkatan bilah navigasi
  34. // @description:id Tambahkan daftar pengguna di bilah navigasi,menghibur,Koleksi dll...
  35. // @name:it GreasyFork: Miglioramento della barra di navigazione
  36. // @description:it Aggiungi l’elenco degli utenti sulla barra di navigazione,consolle,Raccolta ecc...
  37. // @name:ja GreasyFork: ナビゲーションバーの強化
  38. // @description:ja ナビゲーションバーにユーザーリストを追加,コンソール,コレクションなど..
  39. // @name:ka GreasyFork: ნავიგაციის ზოლის გაუმჯობესება
  40. // @description:ka დაამატეთ მომხმარებლის სია ნავიგაციის ზოლში,კონსოლი,კოლექცია და ა.შ...
  41. // @name:ko GreasyFork: 탐색 표시줄 개선
  42. // @description:ko 탐색 표시줄에 사용자 목록 추가,콘솔,수집 등..
  43. // @name:nl GreasyFork: Verbetering van de navigatiebalk
  44. // @description:nl Voeg een gebruikerslijst toe aan de navigatiebalk,troosten,Collectie enz...
  45. // @name:nb GreasyFork: Forbedring av navigasjonslinjen
  46. // @description:nb Legg til brukerliste på navigasjonslinjen,konsoll,Samling etc...
  47. // @name:pl GreasyFork: Udoskonalenie paska nawigacji
  48. // @description:pl Dodaj listę użytkowników na pasku nawigacyjnym,konsola,Kolekcja itp...
  49. // @name:pt-BR GreasyFork: Aprimoramento da barra de navegação
  50. // @description:pt-BR Adicionar lista de usuários na barra de navegação,console,Coleção etc..
  51. // @name:ro GreasyFork: Îmbunătățirea barei de navigare
  52. // @description:ro Adăugați lista de utilizatori pe bara de navigare,consolă,Colectare etc...
  53. // @name:ru GreasyFork: Улучшение панели навигации
  54. // @description:ru Добавить список пользователей на панель навигации,консоль,Коллекция и т. д...
  55. // @name:sk GreasyFork: Vylepšenie navigačnej lišty
  56. // @description:sk Pridajte zoznam používateľov na navigačnú lištu,konzoly,Zbierka atď...
  57. // @name:sr GreasyFork: Побољшање траке за навигацију
  58. // @description:sr Додајте листу корисника на траку за навигацију,конзола,Збирка итд...
  59. // @name:sv GreasyFork: Förbättring av navigeringsfältet
  60. // @description:sv Lägg till användarlista i navigeringsfältet,trösta,Samling etc...
  61. // @name:th GreasyFork: การเพิ่มประสิทธิภาพแถบนำทาง
  62. // @description:th เพิ่มรายชื่อผู้ใช้บนแถบนำทาง,คอนโซล,คอลเลกชัน ฯลฯ..
  63. // @name:tr GreasyFork: Gezinme çubuğu geliştirmesi
  64. // @description:tr Gezinme çubuğuna kullanıcı listesi ekleyin,konsol,Koleksiyon vb...
  65. // @name:ug GreasyFork: يولباشچى بالداقنى كۈچەيتىش
  66. // @description:ug يولباشچى ستونىغا ئىشلەتكۈچى تىزىملىكىنى قوشۇڭ,console,توپلاش قاتارلىقلار...
  67. // @name:uk GreasyFork: Покращення панелі навігації
  68. // @description:uk Додати список користувачів на панель навігації,консоль,Колекція тощо..
  69. // @name:vi GreasyFork: Cải tiến thanh điều hướng
  70. // @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...
  71. // @name:zh-TW GreasyFork: 導覽列增強
  72. // @description:zh-TW 在導覽列上新增使用者列表,主機,收藏等..
  73. // @name:zh-HK GreasyFork: 導覽列增強
  74. // @description:zh-HK 在導覽列上新增使用者列表,主機,收藏等..
  75. // @name:fr-CA GreasyFork: Amélioration de la barre de navigation
  76. // @description:fr-CA Ajouter une liste d’utilisateurs sur la barre de navigation,console,Collecte etc..
  77. // @namespace https://github.com/10086100886
  78. // @match https://greasyfork.org/*
  79. // @match https://sleazyfork.org/*
  80. // @grant none
  81. // @version 0.3.1.55
  82. // @license MIT
  83. // @author CY Fung & 人民的勤务员 <toniaiwanowskiskr47@gmail.com>
  84. // @description To add User Control Panel Button into navigation bar
  85. // @icon https://greasyfork.org/vite/assets/blacklogo96-CxYTSM_T.png
  86. // @supportURL https://github.com/ChinaGodMan/UserScripts/issues
  87. // @homepageURL https://github.com/ChinaGodMan/UserScripts
  88. // ==/UserScript==
  89.  
  90. (async () => {
  91. let sections = [
  92. { id: '#user-script-sets-section' },
  93. { id: '#control-panel' },
  94. // { id: '#user-library-list-section', name: '库' },
  95. //{ id: '#user-unlisted-script-list-section', name: '没上架' },
  96. // { id: '#user-discussions', name: '讨论' },
  97. { id: '#user-script-list-section' }
  98. ]
  99.  
  100. function preSetup() {
  101. let pos = document.querySelectorAll('#site-nav>nav>li.with-submenu')
  102. pos = pos.length >= 1 ? pos[pos.length - 1] : null
  103.  
  104. if (!pos) return
  105.  
  106. pos.parentNode.style.minHeight = '2.8rem'
  107.  
  108. return { pos }
  109. }
  110.  
  111. function setup(m, namespace) {
  112. const { cpmRoot } = m
  113.  
  114. let h = cpmRoot.querySelector('h3') || cpmRoot.querySelector('header')
  115. if (!h) return
  116.  
  117. let nav = document.createElement('nav')
  118.  
  119. let addedText = new Set()
  120. let lastText = null
  121.  
  122. for (const anchor of cpmRoot.querySelectorAll('li a[href]')) {
  123. let textContent = anchor.textContent.trim()
  124.  
  125. if (addedText.has(textContent)) {
  126. lastText = textContent
  127. continue
  128. }
  129.  
  130. let li = nav.appendChild(document.createElement('li'))
  131. li.appendChild(anchor)
  132.  
  133. addedText.add(textContent)
  134. }
  135.  
  136. if (lastText !== null) {
  137. nav.querySelectorAll('li').forEach(li => {
  138. if (li.querySelector('a').textContent.trim() === lastText) {
  139. li.remove()
  140. }
  141. })
  142. }
  143.  
  144. let tm = document.createElement('template')
  145. tm.innerHTML = `
  146. <li class="with-submenu" style="display: block;">
  147. <a href="#" onclick="return false">${namespace ? namespace : h.textContent}</a>
  148. <nav style="min-width: initial;">
  149. ${nav.innerHTML}
  150. </nav>
  151. </li>
  152. `.trim()
  153.  
  154. return tm.content
  155. }
  156.  
  157. function bufferToHex(buffer) {
  158. const byteArray = new Uint8Array(buffer)
  159. const len = byteArray.length
  160. const hexCodes = new Array(len * 2)
  161. const chars = '0123456789abcdef'
  162. for (let i = 0, j = 0; i < len; i++) {
  163. const byte = byteArray[i]
  164. hexCodes[j++] = chars[byte >> 4]
  165. hexCodes[j++] = chars[byte & 0x0F]
  166. }
  167. return hexCodes.join('')
  168. }
  169.  
  170. async function digestMessage(message) {
  171. const encoder = new TextEncoder("utf-8")
  172. const msgUint8 = encoder.encode(message)
  173. const hashBuffer = await crypto.subtle.digest('SHA-1', msgUint8)
  174. return bufferToHex(hashBuffer)
  175. }
  176.  
  177. async function fetchHTML(href) {
  178. let response = await fetch(href, {
  179. method: "GET",
  180. mode: "same-origin",
  181. cache: "force-cache",
  182. credentials: "same-origin",
  183. redirect: "follow",
  184. referrerPolicy: "no-referrer",
  185. })
  186.  
  187. return response.text()
  188. }
  189.  
  190. async function addSectionsToNav() {
  191. let presetup = preSetup()
  192. if (!presetup) return
  193. const { pos } = presetup
  194.  
  195. let plink = document.querySelector('.user-profile-link')
  196. if (!plink) return
  197. let href = plink.querySelector('a[href*="/users/"]').href
  198. if (href.includes('/users/sign')) return
  199.  
  200. let dm = await digestMessage(href)
  201. const stKey = `gf_user_page_${dm}`
  202.  
  203. for (let trialN = 8; trialN--;) {
  204. let s = sessionStorage.getItem(stKey)
  205. let d = typeof s === 'string' ? parseInt(s) : 0
  206. if (d > 9 && Date.now() - d < 8000) await new Promise(r => setTimeout(r, 320))
  207. else break
  208. }
  209.  
  210. const userPageHTML = await fetchHTML(href)
  211. if (!userPageHTML || typeof userPageHTML !== 'string') return
  212.  
  213. sessionStorage.setItem(stKey, userPageHTML)
  214.  
  215. let template = document.createElement('template')
  216. template.innerHTML = userPageHTML
  217. const content = template.content
  218.  
  219.  
  220.  
  221. sections.forEach(({ id, name }) => {
  222. let section = content.querySelector(id)
  223. if (section) {
  224. const kc = setup({ cpmRoot: section, pos }, name)
  225. if (kc) {
  226. pos.parentNode.insertBefore(kc, pos.nextSibling)
  227. }
  228. }
  229. })
  230. }
  231.  
  232. if (!document.querySelector('.sign-out-link') || document.querySelector('.sign-in-link')) return
  233.  
  234. await addSectionsToNav()
  235. })()