Skip to content

github-inactive-dev-warning.user.js - Styling & Close Button #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 115 additions & 40 deletions github-inactive-dev-warning.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @description display big banner if project's last commit over 6 months ago and giant banner if over 1 year ago
// @copyright 2019-2025, Zach Hardesty (https://zachhardesty.com/)
// @license GPL-3.0-only; http://www.gnu.org/licenses/gpl-3.0.txt
// @version 1.3.2
// @version 1.4.0

// @homepageURL https://github.com/zachhardesty7/tamper-monkey-scripts-collection/raw/master/github-inactive-dev-warning.user.js
// @homepage https://github.com/zachhardesty7/tamper-monkey-scripts-collection/raw/master/github-inactive-dev-warning.user.js
Expand All @@ -26,68 +26,143 @@ onElementReady(
"[data-testid='latest-commit-details'] relative-time",
{ findOnce: false },
(el) => {
if (document.querySelector("#zh-banner-warning")) {
return
}
if (document.querySelector("#zh-inactive-dev-warning")) return;

const date = new Date(el.getAttribute("datetime") || "")
const daysSinceLastCommit = (Date.now() - date.getTime()) / 1000 / 60 / 60 / 24
const date = new Date(el.getAttribute("datetime") || "");
const daysSinceLastCommit = (Date.now() - date.getTime()) / 1000 / 60 / 60 / 24;
if (daysSinceLastCommit > 365) {
renderWarning()
renderWarning();
} else if (daysSinceLastCommit > 182.5) {
renderCaution()
} else {
/* noop */
renderCaution();
}
},
)
}
);

/** @param {HTMLElement} el - target */
function displayMessage(el) {
document
.querySelector("#js-repo-pjax-container")
?.insertAdjacentElement("beforebegin", el)
const container = document.querySelector("#js-repo-pjax-container");
if (container) {
const existingBanner = document.querySelector("#zh-inactive-dev-warning");
if (existingBanner) existingBanner.remove();
container.insertAdjacentElement("beforebegin", el);
}
}

function getThemeSettings() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: does this work for all combinations of light/dark system prefs and github themes?

I didn't test all of the themes and/or system light/dark modes (prefers-...), but it looks great on my system's dark mode. How are the light themes (system or GH)? What about other GH themes than plain dark?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time I checked, all themes do work. Although having just double checked now there seems to be some mess ups with the beta themes which I'll have to look into. Perhaps this could be solved as you say by using GitHub's own CSS variables.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge deal if the beta themes don't work, but it would be nice!

const colorMode = document.documentElement.getAttribute('data-color-mode');
const darkTheme = document.documentElement.getAttribute('data-dark-theme');
const isLight = colorMode === 'light' ||
(colorMode === 'auto' && !window.matchMedia('(prefers-color-scheme: dark)').matches);

if (isLight) {
return {
bg: '#fef7c5',
text: '#1e2227',
border: '#edd789',
warningColor: '#996606' // Light theme warning color
};
} else if (darkTheme === 'dark') {
return {
bg: '#262014',
text: '#f0f0f0',
border: '#614612',
warningColor: '#d19826' // Dark theme warning color
};
} else { // soft_dark or default
return {
bg: '#36342c',
text: '#f0f0f0',
border: '#665122',
warningColor: '#c58f29' // Soft dark theme warning color
};
}
}

function createWarningIcon(theme) {
const icon = document.createElement("div");
icon.innerHTML = `
<svg width="16" height="16" viewBox="0 0 16 16" fill="${theme.warningColor}" style="vertical-align: middle;">
<path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path>
</svg>
`;
return icon;
}

function renderWarning() {
const banner = document.createElement("div")
banner.id = "zh-banner-warning"
banner.setAttribute(
"style",
`
background-color: red;
height: 100px;
const theme = getThemeSettings();
const banner = document.createElement("div");
banner.id = "zh-inactive-dev-warning";
banner.setAttribute("style", `
background-color: ${theme.bg};
color: ${theme.text};
height: 50px;
margin-bottom: 20px;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-size: 36px;
`,
)
font-size: 18px;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can we reference some CSS variable from their code for this?

It would be really nice to not hardcode this to the specific px value and instead reference whatever theme / CSS variable system GitHub created. I know I wasn't doing that before, so if that's not reasonable, that's okay, just wanted to check!

border-top: 1px solid ${theme.border};
border-bottom: 1px solid ${theme.border};
padding: 0 16px;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can we reference some CSS variable from their code for this?

It would be really nice to not hardcode this to the specific px value and instead reference whatever theme / CSS variable system GitHub created. I know I wasn't doing that before, so if that's not reasonable, that's okay, just wanted to check!

position: relative;
`);

const message = document.createElement("div");
message.style.flex = "1";
message.style.textAlign = "center";
message.style.display = "flex";
message.style.alignItems = "center";
message.style.justifyContent = "center";
message.style.gap = "8px";

banner.textContent = "WARNING: repo hasn't received an update in 1+ year(s)"
message.appendChild(createWarningIcon(theme));

displayMessage(banner)
const text = document.createElement("span");
text.textContent = "repo hasn't been updated in 1+ year(s)";
message.appendChild(text);

message.appendChild(createWarningIcon(theme));

banner.appendChild(message);

displayMessage(banner);
}

function renderCaution() {
const banner = document.createElement("div")
banner.id = "zh-banner-warning"
banner.setAttribute(
"style",
`
background-color: yellow;
const theme = getThemeSettings();
const banner = document.createElement("div");
banner.id = "zh-inactive-dev-warning";
banner.setAttribute("style", `
background-color: ${theme.bg};
color: ${theme.text};
height: 50px;
margin-bottom: 20px;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
`,
)
font-size: 18px;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can we reference some CSS variable from their code for this?

It would be really nice to not hardcode this to the specific px value and instead reference whatever theme / CSS variable system GitHub created. I know I wasn't doing that before, so if that's not reasonable, that's okay, just wanted to check!

border-top: 1px solid ${theme.border};
border-bottom: 1px solid ${theme.border};
padding: 0 16px;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can we reference some CSS variable from their code for this?

It would be really nice to not hardcode this to the specific px value and instead reference whatever theme / CSS variable system GitHub created. I know I wasn't doing that before, so if that's not reasonable, that's okay, just wanted to check!

position: relative;
`);

const message = document.createElement("div");
message.style.flex = "1";
message.style.textAlign = "center";
message.style.display = "flex";
message.style.alignItems = "center";
message.style.justifyContent = "center";
message.style.gap = "8px";

message.appendChild(createWarningIcon(theme));

const text = document.createElement("span");
text.textContent = "repo hasn't been updated in 6+ months";
message.appendChild(text);

message.appendChild(createWarningIcon(theme));

banner.textContent = "Caution: repo hasn't received an update in 6+ months"
banner.appendChild(message);

displayMessage(banner)
displayMessage(banner);
}