Created
December 31, 2023 00:49
-
-
Save littletsu/caff579c4c4867a5fc80fcddd8cea0f0 to your computer and use it in GitHub Desktop.
Better titles for FFmpeg doxygen
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 Better titles for FFmpeg doxygen | |
// @namespace Violentmonkey Scripts | |
// @match https://ffmpeg.org/doxygen/* | |
// @grant none | |
// @version 1.0 | |
// @author - | |
// @description 12/30/2023, 2:32:16 AM | |
// ==/UserScript== | |
(() => { | |
let title = document.querySelector("title"); | |
let newTitle = title.innerHTML.slice("FFmpeg: ".length); | |
const getTitleFromHash = () => { | |
try { | |
return document.querySelector(`a[href="${window.location.hash}"]`).parentNode.parentNode.innerText.slice(2); | |
} catch(err) { | |
console.log(`error capturing title from hash: `, err) | |
} | |
return newTitle; | |
} | |
const updateTitleFromHash = () => { | |
title.innerHTML = getTitleFromHash(); | |
} | |
if(window.location.hash.length !== 0) { | |
newTitle = getTitleFromHash(); | |
} | |
window.addEventListener("hashchange", updateTitleFromHash); | |
const headings = document.querySelectorAll('h2 span a[href^="#"]'); | |
document.addEventListener('scroll', (e) => { | |
headings.forEach(ha => { | |
const rect = ha.getBoundingClientRect(); | |
if(rect.top > 0 && rect.top < 150) { | |
const location = window.location.toString().split('#')[0]; | |
history.replaceState(null, null, ha.href); | |
updateTitleFromHash(); | |
} | |
}); | |
}); | |
title.innerHTML = newTitle; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment