Created
March 5, 2024 17:53
-
-
Save bits0rcerer/e27ae1f6066fbc6cc9afa71fd8c084d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name rustdoc htmxify | |
// @version 0.1 | |
// @description enhance rustdoc with a little bit of htmx | |
// @author bits0rcerer | |
// @match http://*/* | |
// @match https://*/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const boostable = ["constant", "fn", "type"]; | |
const wrapper = document.querySelector("#rustdoc_body_wrapper") || document.body; | |
if (!wrapper.className.includes("rustdoc")) return; | |
let doc_type = null; | |
for (const t of boostable) { | |
if (wrapper.classList.contains(t)) { | |
doc_type = t; | |
break; | |
} | |
} | |
if (!doc_type) return; | |
const sidebar_list = document.querySelector(".sidebar-elems ." + doc_type); | |
sidebar_list.setAttribute("hx-boost", "true"); | |
sidebar_list.setAttribute("hx-select", "main"); | |
sidebar_list.setAttribute("hx-target", "main"); | |
fetch("https://unpkg.com/htmx.org").then(r => r.text()).then(code => { | |
const htmx = document.createElement("script"); | |
htmx.innerText = code; | |
document.head.appendChild(htmx); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment