Mycorrhiza Create Page Button

Adds a button create a page to your mycorrhiza header links

目前为 2025-03-11 提交的版本,查看 最新版本

  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. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function addToHeader() {
  17. const ul = document.querySelector('.top-bar__highlights');
  18. if (!ul) return;
  19.  
  20. const li = document.createElement('li');
  21. li.className = 'top-bar__highlight';
  22.  
  23. const a = document.createElement('a');
  24. a.href = '#';
  25. a.className = 'top-bar__highlight-link';
  26. a.textContent = 'New hypha';
  27. a.addEventListener('click', function(event) {
  28. event.preventDefault();
  29. // TODO: I want to make this part of the UI instead of a prompt
  30. const hyphaName = prompt("New hypha name:");
  31. if (hyphaName) {
  32. window.location.href = `/edit/${encodeHyphaName(hyphaName)}`;
  33. }
  34. });
  35.  
  36. li.appendChild(a);
  37. // INFO: replace prepend with appendChild if you want the button at the end of the list
  38. ul.prepend(li);
  39. }
  40.  
  41. function encodeHyphaName(hyphaName) {
  42. let encodedHyphaName = hyphaName.replace(' ', '_')
  43. return encodedHyphaName
  44. }
  45.  
  46. addToHeader();
  47. })();