From ec240bb13ea5d236a17a7b061a326b87587f819d Mon Sep 17 00:00:00 2001 From: Eric de Saint Denis Date: Mon, 22 Jun 2026 18:36:57 +0200 Subject: [PATCH] Add 'Show diff only' option to hide unchanged lines --- lib/sitediff/files/sitediff.css | 14 ++++++ lib/sitediff/files/sitediff.js | 79 +++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/lib/sitediff/files/sitediff.css b/lib/sitediff/files/sitediff.css index 0e4039a..3f564b5 100644 --- a/lib/sitediff/files/sitediff.css +++ b/lib/sitediff/files/sitediff.css @@ -247,6 +247,10 @@ table .status-col { width: 100%; } +body.show-diff-only .diff li.unchanged { + display: none; +} + /*** Overlay */ .overlay { background-color: rgba(0, 0, 0, 0.25); @@ -309,6 +313,16 @@ table .status-col { color: #9b9db8; cursor: not-allowed; } +.overlay header .diff-only { + padding: 1em; + white-space: nowrap; +} +.overlay header .diff-only label { + cursor: pointer; +} +.overlay header .diff-only input { + margin-right: 0.25em; +} .overlay header .path { flex-grow: 1; padding: 1em; diff --git a/lib/sitediff/files/sitediff.js b/lib/sitediff/files/sitediff.js index fab397a..dc7910a 100644 --- a/lib/sitediff/files/sitediff.js +++ b/lib/sitediff/files/sitediff.js @@ -79,6 +79,47 @@ SiteDiff.scrollToElement = function (el, options) { } }; +/** + * Gets the value of a cookie. + * + * @param name + * The cookie name. + * + * @returns + * The cookie value, or null if not found. + */ +SiteDiff.getCookie = function (name) { + var nameEq = name + '='; + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = cookies[i].trim(); + if (cookie.indexOf(nameEq) === 0) { + return cookie.substring(nameEq.length); + } + } + return null; +}; + +/** + * Sets a cookie. + * + * @param name + * The cookie name. + * @param value + * The cookie value. + * @param days + * Number of days until the cookie expires. + */ +SiteDiff.setCookie = function (name, value, days) { + var expires = ''; + if (days) { + var date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + expires = '; expires=' + date.toUTCString(); + } + document.cookie = name + '=' + value + expires + '; path=/'; +}; + /** * Initialize behaviors. */ @@ -90,6 +131,9 @@ SiteDiff.init = function () { break; case 'diff': + if (SiteDiff.getCookie('sitediffDiffOnly') === '1') { + $(document.body).addClass('show-diff-only'); + } SiteDiff.jumpToFirstDiff(); break; } @@ -193,6 +237,7 @@ SiteDiff.initOverlay = function () { $('body').append($( '