From 02ac1ba4318cd205856d388f95545378322c3610 Mon Sep 17 00:00:00 2001 From: Paul Maddern Date: Fri, 28 Jun 2024 11:19:36 +0100 Subject: [PATCH] Fix twitter javascript When you hate twitter/ X after how awful it's got since Musk bought it, the code will throw a fatal error as `twitterIconElement` is `NULL` when unused - so `setAttribute()` isn't callable. --- layouts/partials/user-profile.html | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/layouts/partials/user-profile.html b/layouts/partials/user-profile.html index 0d6d80c..173133f 100644 --- a/layouts/partials/user-profile.html +++ b/layouts/partials/user-profile.html @@ -208,13 +208,15 @@ var style = localStorage.getItem('data-color-mode'); iconElement = document.getElementById('github-icon'); twitterIconElement = document.getElementById('twitter-icon'); if (style == 'light') { - iconElement.setAttribute('fill', '#24292e'); - twitterIconElement.setAttribute("fill","black") + if (iconElement) iconElement.setAttribute('fill', '#24292e'); + if (twitterIconElement) twitterIconElement.setAttribute("fill","black") } else { - iconElement.removeAttribute('fill'); - iconElement.setAttribute('class', 'octicon'); - iconElement.setAttribute('color', '#f0f6fc'); - twitterIconElement.setAttribute("fill","white") + if (iconElement) { + iconElement.removeAttribute('fill'); + iconElement.setAttribute('class', 'octicon'); + iconElement.setAttribute('color', '#f0f6fc'); + } + if (twitterIconElement) twitterIconElement.setAttribute("fill","white") }