element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Feedback and Support
  • Community Hub
  • More
Feedback and Support
Site Update Blog Customising Website Fonts with CSS Overrides using TamperMonkey
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Actions
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Matt
  • Date Created: 10 Jun 2024 12:13 PM Date Created
  • Views 454 views
  • Likes 0 likes
  • Comments 0 comments
Blog Details
Related
Recommended

Customising Website Fonts with CSS Overrides using TamperMonkey

Matt
Matt
10 Jun 2024

I've been a long-time user of a browser extension called TamperMonkey (and before that used GreaseMonkey on Firefox). 

If you haven't heard of it before, TamperMonkey is a powerful browser extension that allows users to customise and enhance their web browsing experience by running custom scripts on websites. These scripts, known as userscripts, can be used to add new features or modify existing ones on web pages. For example, you can use TamperMonkey to change the font properties of a website to improve readability, remove ads, declutter the interface, or add custom buttons and keyboard shortcuts.

It's available for popular browsers like Chrome, Firefox, Edge, Safari, and Opera.

Installing TamperMonkey

Before we start writing our custom script, we need to install TamperMonkey. Follow these steps to install TamperMonkey on your browser:

  1. For Chrome: Visit the Chrome Web Store and search for "TamperMonkey". Click "Add to Chrome" to install the extension.
  2. For Firefox: Go to Firefox Add-Ons and search for "TamperMonkey". Click "Add to Firefox" to install the extension.
  3. For other browsers: Visit the TamperMonkey homepage and follow the instructions for your specific browser.

Practical Example

Let's say you want to change the font style of a specific class on a website from a cursive style to a sans-serif style. Here’s how you can do it:

1. Identify the Class: Inspect the website's HTML to find the class of the element you want to change. For example, if the HTML is:

<div class="text">Ask more leading questions</div>

The class is "text".

2. Create the Script:

    a. Open TamperMonkey Dashboard: Click on the TamperMonkey icon in your browser's toolbar and select "Dashboard".

    b. Create a New Script: Click on the "+" button or "Create a new script" to open the script editor.

    c. Edit the Script Metadata: Replace the default metadata with the following:

// ==UserScript==
// @name         Change Font Style
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Change the font style of a specific class on a website
// @match        https://example.com/*
// @grant        GM_addStyle
// ==/UserScript==

Replace https://example.com/* with the URL of the website you want to customise.

    d. Add Custom CSS: Below the metadata, add the following JavaScript code to inject custom CSS into the website:

(function() {
    'use strict';

    // Add custom CSS to change the font style of elements with class "text"
    GM_addStyle(`
        .text {
            font-family: Helvetica, sans-serif !important;
        }
    `);
})();

This script uses the GM_addStyle function to add custom CSS that changes the font family of elements with the class "text" to Helvetica, sans-serif.

    e. Save the Script: Click "File" and then "Save" to save your script.

3. Test the Script: Visit the website and check if the font style has changed. If everything is set up correctly, the text should now be displayed in Helvetica, sans-serif.

Customising element14 Community (Safely)

If you want to change how element14 Community displays content, then I'd recommend prefixing all your CSS rules with .content-fragment-content .content

This targets the content, and won't end up breaking the menus or anything critical to the functioning of the site. Even if you do break something, you can just turn the script off in TamperMonkey.

Here's an example script which will increase the font sizes for content;

// ==UserScript==
// @name         element14 Community UI Changes
// @namespace    http://tampermonkey.net/
// @version      2024-06-10
// @description  Change the default Community font size
// @match        https://community.element14.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=element14.com
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // Custom CSS to change the font styles of body content.
    // By prefixing rules with '.content-fragment-content .content' you can safely change the content CSS without accidently changing the rest of the website.
    // Try a different font if you like, or delete those lines if you just want to adjust the sizes

    GM_addStyle(`
        .content-fragment-content .content p {
            font-family: Helvetica,Arial,'Segoe UI',sans-serif;
            font-size: 1.1em !important;
        }

        .content-fragment-content .content h2 {
            font-family: Helvetica,Arial,'Segoe UI',sans-serif;
            font-size: 24px;
            font-weight: bold;
        }

        .content-fragment-content .content ol li {
            font-family: Helvetica,Arial,'Segoe UI',sans-serif;
            font-size: 1.1em;
        }
    `);
})();

I've left placeholders for the font-family, so you can specify a different font if you want to.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube