Created
March 2, 2021 03:39
-
-
Save instinctive/3270793fcab213341094054651b61104 to your computer and use it in GitHub Desktop.
Userscript to reorg the package contents pages on Hackage
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 hackage | |
// @namespace https://github.com/instinctive/ | |
// @description Reorganize package contents pages on Hackage. | |
// @include /^https?://hackage\.haskell\.org/package/[^/]*$/ | |
// ==/UserScript== | |
(function() { | |
function getStyleSmall(elt) { | |
for (child of elt.children) { | |
if (child.hasAttribute("style") && | |
child.getAttribute("style") == "font-size: small") | |
{ | |
return child; | |
} | |
} | |
return null; | |
} | |
let content = document.getElementById("content"); | |
let modules = document.getElementById("modules"); | |
let header = document.getElementById("page-header"); | |
let footer = document.getElementById("footer"); | |
let props = document.getElementById("properties"); | |
let descr = document.getElementById("description"); | |
let maint = document.getElementById("maintainer-corner"); | |
// TODO guard these expressions. | |
let h1 = content.children[0]; | |
let pkg = h1.children[0]; | |
let ttl = h1.children[1]; | |
content.removeChild(h1); | |
let tags = getStyleSmall(content); | |
let jmps = getStyleSmall(modules); | |
if (header && footer) { | |
header.parentNode.removeChild(header); | |
footer.parentNode.insertBefore(header,footer); | |
footer.setAttribute("style","margin-top: 0em"); | |
} | |
// Reorganize properties section to be the metadata section. | |
if (props) { | |
let deets = document.createElement("details"); | |
let summy = document.createElement("summary"); | |
let title = document.createElement("h2"); | |
let hrule = document.createElement("hr"); | |
let bold = document.createElement("p"); | |
// TODO guard these expressions. | |
title.appendChild(pkg); | |
bold.setAttribute("style","font-weight: bold"); | |
bold.innerHTML = ttl.innerHTML; | |
descr.insertBefore(bold,descr.children[0]); | |
if (jmps) { | |
while (jmps.childNodes.length > 1) { | |
let child = jmps.childNodes[0] | |
if (child.tagName != "A") { | |
child.textContent = " / "; | |
} | |
title.appendChild(child); | |
} | |
jmps.parentNode.removeChild(jmps); | |
} | |
title.setAttribute("style","display: inline"); | |
summy.appendChild(title); | |
deets.appendChild(summy); | |
if (tags) { | |
tags.parentNode.removeChild(tags); | |
deets.appendChild(tags); | |
} | |
while (props.childNodes.length > 0) { | |
deets.appendChild(props.childNodes[0]); | |
} | |
if (maint) { | |
maint.parentNode.removeChild(maint); | |
deets.appendChild(maint); | |
} | |
deets.appendChild(hrule); | |
props.setAttribute("style","padding-top: 1em"); | |
props.setAttribute("id","metadata"); | |
props.appendChild(deets); | |
} | |
if (descr) { | |
props.parentNode.removeChild(props); | |
descr.parentNode.insertBefore(props,descr); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment