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

@linkorb/tweakjs

v0.1.1

Published

This simple javascript library allows you to tweak the DOM of your pages simply by passing it an array of tweaks.

Downloads

2

Readme

tweak.js

This simple javascript library allows you to tweak the DOM of your pages simply by passing it an array of tweaks.

Use-cases:

tweak.js can be used to quickly implement:

  • A/B Testing
  • Text corrections
  • Replace images, styles, etc

Anybody can change tweaks:

  • Without changes to the underlying application
  • Without developer support
  • Without delay

Installation

npm install @linkorb/tweakjs

Demo

Check the demo/ directory for an demonstration + example on how to use tweak.js

How to use

To support tweak.js in your application, you'll need to include two tags in the <head /> of your application:

<script type="text/javascript" src="../tweak.js"></script>

tweak.js is responsible for parsing and executing the tweaks. Tweaks are JavaScript objects which describes how to tweak. Here is an example of an array of tweaks:

var tweaks = [
    {
        "description": "Set custom header text",
        "action": "setInnerText",
        "selector": "h1:first-of-type",
        "value": "This is a my custom header text",
    },
    {
        "description": "Change background color",
        "action": "setStyleAttribute",
        "selector": "body",
        "attribute": "background-color",
        "value": "#c0d0e0",
    }
];

The tweaks shall be loaded separately.

Loading tweaks

There are 3 ways to load tweaks

  1. Load tweaks from global variable - It should simply define a variable called tweaks that contains an array of tweak instructions. This array should be loaded before tweak.js
<script type="text/javascript" src="https://my.host/path/to/my/tweaks.js"></script>
<script type="text/javascript" src="../tweak.js"></script>
  1. Load tweaks in the document - A variable tweakjs is exposed to the global scope. Therefore, after the tweak.js gets loaded, you can still add tweaks like this in your HTML:
<script>
tweakjs.loader.load(
  [
    {
        "description": "Set div text to bold",
        "action": "setInnerText",
        "selector": ".post-load>div",
        "value": "This text is replaced after pageload.",
    },
    {
        "description": "Set custom inner HTML",
        "action": "setInnerHtml",
        "selector": ".post-load>span",
        "value": "<i>Italic</i>",
    }
  ]
)
</script>
  1. Load tweaks from external resource - Add a URL query parameter tweaksUrl to specify an external js file.
http://localhost:8080/demo?tweaksUrl=https://my.host/path/to/my/tweaks.js

Supported actions

  • setInnerText
  • setInnerHtml
  • setAttribute
  • setStyleAttribute
  • addClass
  • hide
  • show
  • removeClass
  • remove
  • addStyle
  • addScript
  • execute

You can find demo's of all the actions in the demo/ directory.

Build from source

To change the source file and build, simply use webpack.

# generates dist/tweak.js
webpack -d
# generates dist/tweak.min.js
webpack -p

Advanced usage

  • In A/B testing scenarios, you could have a server generate tweaks.js based on visitor properties
  • You could have your app generate the tweaks variable server-side and include it in the script tag's body (instead of the src attribute)

License

MIT (see LICENSE)

Brought to you by the LinkORB Engineering team

Check out our other projects at linkorb.com/engineering.

Btw, we're hiring!