Mycorrhiza Create Page Button

Adds a button create a page to your mycorrhiza header links

  1. // ==UserScript==
  2. // @name Mycorrhiza Create Page Button
  3. // @namespace https://mycorrhiza.wiki
  4. // @version 1.0
  5. // @description Adds a button create a page to your mycorrhiza header links
  6. // @author You
  7. // @icon https://em-content.zobj.net/source/microsoft/407/mushroom_1f344.png
  8. // NOTE: change this to your mycorrhiza instance.
  9. // @match https://mycorrhiza.wiki/*
  10. // @grant none
  11. // @license AGPL-3.0-or-later
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. function addToHeader() {
  18. const ul = document.querySelector('.top-bar__highlights');
  19. if (!ul) return;
  20.  
  21. const li = document.createElement('li');
  22. li.className = 'top-bar__highlight';
  23.  
  24. const a = document.createElement('a');
  25. a.href = '#';
  26. a.className = 'top-bar__highlight-link';
  27. a.textContent = 'New hypha';
  28. a.addEventListener('click', function(event) {
  29. event.preventDefault();
  30. // TODO: I want to make this part of the UI instead of a prompt
  31. const hyphaName = prompt("New hypha name:");
  32. if (hyphaName) {
  33. window.location.href = `/edit/${encodeHyphaName(hyphaName)}`;
  34. }
  35. });
  36.  
  37. li.appendChild(a);
  38. // INFO: replace prepend with appendChild if you want the button at the end of the list
  39. ul.prepend(li);
  40. }
  41.  
  42. function encodeHyphaName(hyphaName) {
  43. let encodedHyphaName = hyphaName.replace(' ', '_')
  44. return encodedHyphaName
  45. }
  46.  
  47. addToHeader();
  48. })();
  49.  

QingJ © 2025

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