npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mobiloud/ml-css-injector

v1.2.1

Published

MobiLoud CSS Injector

Readme

Version Static Badge

CSS INJECTION TOOL

Introduction

The Web-App Style Injector is a lightweight JavaScript library that simplifies the process of tailoring your website for web and app versions. By adding a few lines of code, you can apply distinct styles to elements visible only on the app version or hidden entirely on it. No advanced technical knowledge is required; it’s as simple as copy-pasting two script tags!

Key Features

  1. Effortless Integration: Just copy and paste the provided script tags to get started.
  2. Dynamic Styling: Automatically adds a is-app class to the <body>, enabling custom styles for app and web versions.
  3. App-Specific Classes:
    • app-hide: Hides elements exclusively on the app version.
    • app-exclusive: Displays elements only on the app version.
  4. Customizable Options: Use optional parameters for further flexibility, such as hiding predefined sections or disabling logs.
  5. Helper Logs: By default, helpful console logs guide you during setup and usage.
  6. Advanced Classes Injection: A developer-oriented feature that allows regex-based CSS injection for specific pages.

How to Use It

1. Basic Implementation

For the simplest setup, follow these steps:

Copy the following code and paste it right before the closing tag of your document

<script src="cdn.com/script.js" defer></script>
<script>
(function(){
    styleTemplate();
})();
</script>

With this setup, your website will Automatically add a is-app class to the when the site is navigated through the app, and enables custom styles for app and web versions.

It also add some useful style rules to the document:

The app-hide and app-exclusive classes provide simple ways to control the visibility of elements in the app version:

  • .app-hide: Hides certain elements in the app version of the site.
  • .app-exclusive: Displays certain elements only in the app version of the site.

Here’s an example of how to use these classes in your HTML:

<div class="app-hide">❌ Element not visible in app ❌</div>
<div class="app-exclusive">📱 Element only visible in app 📱</div>

Define styles in your stylesheet as you would normally do, like this:

.elementClass {
    color: blue; /* Default for web */
}
body.is-app .elementClass {
    color: red; /* For app */
}

In this example, text will appear blue on the web version but red in the app version.

2. Optional Parameters

The library supports optional settings to enhance its functionality:

  • Logs: Enable or disable helper console logs.
  • Predefined Stylesheets: Automatically hide common sections in the app version (e.g., footers, banners, popups).

Example of using optional parameters:

<script>
(function(){
    styleTemplate({
        hideSections: ["hide-footers", "hide-banners"],
        logs: false
    });
})();
</script>

Available Predefined Stylesheets:

  • hide-footers: This hides the site's footer
  • hide-wp-adminbar: Hides Wordpress adminbar, this usually shows after users sign in in a Wordpress site
  • hide-back-to-top: This hides some floating back to top arrows/buttons
  • hide-popups-and-consents: This includes: cookie consent in bottom drawers, promotional popups, and enables overflow in the body, sometimes popups locks page scroll
  • hide-banners: This hides some promotional bars / banners that are above the site's header
  • hide-fabs: This hides Floating buttons (a lot of them added with plugins, so we include some common plugin selectors), this also hide some floating captcha elements

By customizing the parameters, you can fine-tune the appearance of your app version with minimal effort.

3. Advanced Classes Injection

For developers, the library provides a powerful feature to inject CSS globally or selectively based on URL patterns using regular expressions. This allows precise control over styles for specific pages.

Example implementation:

<script src="https://cdn.jsdelivr.net/npm/@mobiloud/ml-css-injector@latest/dist/ml-css-injector.min.js"></script>
<script>
(function(){
    addStyle({css: `a{color: red !important}`});
    addStyle({css: `a{color: yellow !important}`, regex: /\/?param$/});
    addStyle({css: `a{color: green !important}`, regex: /.*/, name: "Global Styles"});
    addStyle({css: `a{color: green !important}`, regex: /.*/, name: "Global Styles", logs: true});
})();
</script>

You can define styles and target specific pages by passing a regex pattern. Here are some examples of how to use the configuration options:

// Define styles as a string
let style = `
  a {
    color: green;
    background-color: yellow;
  }
  .className {
    font-size: 2rem;
  }
`;

// Use regex to target specific pages
let regex = /.*\/login/;

// Name the style block (optional)
let name = "Login Styles";

// Enable logs for debugging (optional)
addStyle({css: style, regex: regex, name: name, logs: true});

// Apply global styles without regex
addStyle({css: `color: red !important`});
  • css: The CSS rules as a string.
  • regex: A regular expression to target specific pages.
  • name: A name for the style block (optional).
  • logs: Enable or disable logs for debugging (optional).

Device-Specific Methods

  • deviceData.os: Returns the current OS ("android", "ios", "windows", "desktop").
  • deviceData.isCanvas: Returns true or false.
  • deviceData.isMobile: Returns true or false.

By combining these advanced features, you can achieve highly customized styling for specific scenarios.

Mixing Methods

The library allows you to combine the styleTemplate and addStyle methods for even greater flexibility. For example, you can use styleTemplate to apply predefined styles globally and then customize specific pages with addStyle:

<script>
(function(){
    styleTemplate({hideSections: ["hide-footer"]});
    // Custom styles applied in canvas/app only
  if(deviceData.isCanvas){
    addStyle({css: ".customClass{color: red}", regex: /.*login/});
    addStyle({css: `a{color: yellow !important}`, regex: /\/?param$/});
    }
})();
</script>

This approach ensures a consistent base styling while allowing for precise page-level customizations.