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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mobiloud/ml-css-injector

v1.1.3

Published

MobiLoud CSS Injector

Downloads

10

Readme

Version Static Badge

MobiLoud CSS Injector

CSS injector with regex functionality

Features

CSS Injector features:

  • Inject CSS in your site globally selectively for your pages with regex
  • os method available: its a function that can be called to get the current browser OS, useful for triggering external functions'. It returns a string containing "android" | "ios" | "windows" | "desktop"
  • isMobile, isCanvas exposed for filtering
  • Code written in Typescript and minified/bundled with Vite

📖 How to use

CSS Injector can be used importing the JS code via CDN or as a module using NPM

🚀 With CDN

<script src="https://cdn.jsdelivr.net/npm/@mobiloud/ml-css-injector/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>

Configuration options:


// accepts any styles as a string

let style = `
a{
  color: green;
  background-color: yellow
} 
.className {
  font-size: 2rem
}
`
// accepts regex enclosed within slashes
let regex = /.*/

// accepts string
let name = "Style name"

//boolean --> Prints logs in console for debugging

addStyle({css: string, regex: string, name: string, logs: boolean});
addStyle({css: `color: red !important`}) // if no regex passed, the styles applies to every page

Recipe for multiple styles:


// accepts any styles as a string

let styles = [
  {
    css: `
          a{
            color: green;
            background-color: yellow
          } 
          `,
    regex: /.*/,
    name: "Global Styles"
  },
  {
    css: `
          .cart{
            color: green;
            background-color: yellow
          } 
          `,
    regex: /.*\/cart/,
    name: "Cart page"
  },
  {
    css: "div.login{display: none}",
    regex: /.*\/login/,
    name: "Login page"
  }
]
// accepts regex enclosed within slashes

styles.forEach(e => { 
    addStyle({
      css: e.css,
      regex: e.regex,
      name: e.name,
      logs: true
    })
} )

Methods

deviceData.os // returns current os "android" | "ios" | "windows" | "desktop"
deviceData.isCanvas // returns true or false
deviceData.isMobile // returns true or false

Development

  • npm run build produces a production version into /dist folder
  • npm run dev runs dev version and starts a dev server

Testing the Injector

You will definitely want to test the CSS Injector once you deploy them to your website, to make sure that everything works and looks as you want.

Running these tests on real mobile devices can get overwhelming, so we recommend that you run your tests on your desktop browser.

To do this, you will need to emulate a mobile device by adjusting your browser’s user agent. We recommend using the following Chrome extension to do this: User Agent Switcher and Manager

Once you have installed the extension, set it up as follows:

Step 1

Select “Chrome” as the browser and “Android” as the platform if you want to test the Android version of the Button, or “Safari” and “iOS” in case you want to test the iOS version:

annotely_image (61).png

Step 2

Select one of the options that will appear, any will work:

annotely_image (62).png

Step 3

Click “Apply” to make sure the user agent is properly set up on your browser:

annotely_image (63).png

Step 4

You can now press “F5” while viewing your website to refresh the browser window with the updated user agent.

Reset

If you want to revert the changes to the user agent, as some websites might start behaving differently after doing so, you can click the “Reset” button:

annotely_image (64).png

License

Copyright (c) MobiLoud