Skip to content

Instantly share code, notes, and snippets.

@littletsu
Created December 31, 2023 00:49
Show Gist options
  • Save littletsu/caff579c4c4867a5fc80fcddd8cea0f0 to your computer and use it in GitHub Desktop.
Save littletsu/caff579c4c4867a5fc80fcddd8cea0f0 to your computer and use it in GitHub Desktop.
Better titles for FFmpeg doxygen
// ==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