Skip to content

Instantly share code, notes, and snippets.

@xhalo32
Last active January 9, 2026 05:28
Show Gist options
  • Select an option

  • Save xhalo32/3866899ef7bdff53ccebd5365d81c9c6 to your computer and use it in GitHub Desktop.

Select an option

Save xhalo32/3866899ef7bdff53ccebd5365d81c9c6 to your computer and use it in GitHub Desktop.
Firefox invert PDF home-manager

Firefox invert PDF home-manager

Approch overview:

  • By default PDF viewer will be inverted with hue-rotate(180deg) to retain colors.
  • A JavaScript bookmarklet lets you invert back to light mode.

Put these lines in your config:

programs.firefox.your-profile = {
  userContent = ''
    #viewerContainer > #viewer.pdfViewer > .page {
      filter: invert(100%) hue-rotate(180deg);
    }
  '';

  bookmarks.settings = [{
    name = "Invert PDF";
    url = ''javascript:/*PDF%20-%20filter%20invert*/(function(){var%20L='style_PDFI',S='#viewerContainer>#viewer.pdfViewer>.page{filter:unset!important}',SS,E=document.querySelector('style[id="'+L+'"]');if(E){SS=E.disabled;E.disabled=(SS==true)?false:true}else{SS=document.createElement('style');SS.setAttribute('type','text/css');SS.id=L;SS.innerHTML=S;document.querySelector('head').appendChild(SS);}})()'';
  }];
}

Rebuild and restart firefox. Open any PDF in the browser, for example try this paper that I had open while writing this tutorial. To invert back to light mode click the Invert PDF bookmark.

Credits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment