Make a new bookmark in your browser. Set the name to Close all PR files
(or something else you like) and set the URL to:
javascript:void((function(d){d.querySelectorAll('div:not(.Details--on) > div.file-header > div.file-actions > button').forEach(function(x){x.click()});})(document));
Click the bookmark to close all files in your PR.
Based on ideas from @yardensachs and @benjamincharity.
As of 2020, @aejay-rs solutions worked for me while the original on this gist did not.