Skip to content

Instantly share code, notes, and snippets.

@deecewan
Created October 11, 2019 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deecewan/f668239bf86d4505d028d9b7bfb3d54f to your computer and use it in GitHub Desktop.
Save deecewan/f668239bf86d4505d028d9b7bfb3d54f to your computer and use it in GitHub Desktop.
A Tampermonkey script to default to the rich diff for files in a PR if/when they exist
// ==UserScript==
// @name Prefer Rich Diffs
// @namespace http://deecewan.com/
// @version 0.1
// @description default to rich diffs when they exist for a given filetype
// @author You
// @match https://github.com/*
// ==/UserScript==
(function() {
'use strict';
function updatePage() {
if (!window.location.pathname.match(/ferocia\/up\/pull\/\d+\/files/i)) {
return;
}
let mounted = true;
const unmount = () => {
// if we're going to slyly navigate away from this page;
mounted = false;
}
document.addEventListener('pjax:click', unmount);
Array.from(document.querySelectorAll('[aria-label="Display the rich diff"]')).forEach(el => el.click());
}
document.addEventListener('pjax:end', updatePage);
window.addEventListener('load', updatePage);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment