Mycorrhiza Create Page Button

Adds a button create a page to your mycorrhiza header links

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Mycorrhiza Create Page Button
// @namespace    https://mycorrhiza.wiki
// @version      1.0
// @description  Adds a button create a page to your mycorrhiza header links
// @author       You
// @icon         https://em-content.zobj.net/source/microsoft/407/mushroom_1f344.png
//               NOTE: change this to your mycorrhiza instance.
// @match        https://mycorrhiza.wiki/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function addToHeader() {
        const ul = document.querySelector('.top-bar__highlights');
        if (!ul) return;

        const li = document.createElement('li');
        li.className = 'top-bar__highlight';

        const a = document.createElement('a');
        a.href = '#';
        a.className = 'top-bar__highlight-link';
        a.textContent = 'New hypha';
        a.addEventListener('click', function(event) {
            event.preventDefault();
            // TODO: I want to make this part of the UI instead of a prompt
            const hyphaName = prompt("New hypha name:");
            if (hyphaName) {
                window.location.href = `/edit/${encodeHyphaName(hyphaName)}`;
            }
        });

        li.appendChild(a);
        // INFO: replace prepend with appendChild if you want the button at the end of the list
        ul.prepend(li);
    }

    function encodeHyphaName(hyphaName) {
      let encodedHyphaName = hyphaName.replace(' ', '_')
      return encodedHyphaName
    }

    addToHeader();
})();