Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sagarishere/d60ad61bde18dd4ad85acc06f0f361bd to your computer and use it in GitHub Desktop.
Save sagarishere/d60ad61bde18dd4ad85acc06f0f361bd to your computer and use it in GitHub Desktop.
Replace Class Values in Article at Nextjs website
// ==UserScript==
// @name Replace Class Values in Article at Nextjs website
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Replace min-w-0 with min-w-10xl and max-w-6xl with max-w-12xl in article tags
// @author Sagar Yadav
// @match https://nextjs.org/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to replace class values
function replaceClassValues() {
// Get all article elements
let articles = document.querySelectorAll('article');
// Iterate over each article element
articles.forEach(article => {
// Get the current class attribute value
let classValue = article.getAttribute('class');
// Replace min-w-0 with min-w-10xl and max-w-6xl with max-w-12xl
if (classValue) {
classValue = classValue.replace('min-w-0', 'min-w-10xl').replace('max-w-6xl', 'max-w-12xl');
// Update the class attribute with the new value
article.setAttribute('class', classValue);
}
});
}
// Run the function to replace class values when the document is fully loaded
window.addEventListener('load', replaceClassValues);
})();
@sagarishere
Copy link
Author

In Next.js Docs, article width is too less so the horizontal scroll appears.

The script makes the article have enough width to actually read the code and prevent horizontal scroll, when not necessary.

This increases user-experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment