rick-n-roll
v1.0.0
Published
A library that adds surprise redirects to website links
Downloads
6
Maintainers
Readme
Rick Roll Redirect
A lightweight library that adds surprise redirects to your website links.
Installation
npm install rick-n-rollQuick Setup
As a Script Tag
<script src="path/to/rick-n-roll.js"></script>
<script>
// Automatically enables on all links with default settings
surpriseAllLinks;
// Or with custom configuration
surpriseAllLinks({
probability: 0.95,
redirectUrl: "https://www.youtube.com/embed/dQw4w9WgXcQ",
showNotice: true,
noticeText: "This link might surprise you!",
excludeSelector: "[data-no-surprise]", // Elements to exclude
beNice: true,
});
</script>As an NPM Module
import { surpriseAllLinks, SurpriseRedirect } from 'rick-n-roll';
// Quick setup - automatically enables on all links
surpriseAllLinks;
// Or with custom configuration
const surprise = new SurpriseRedirect({
probability: 0.95,
redirectUrl: 'https://www.youtube.com/embed/dQw4w9WgXcQ',
showNotice: true,
noticeText: 'This link might surprise you!',
excludeSelector: '[data-no-surprise]'
beNice: true,
});
surprise.init();
surprise.enableAll(); // Enable on all links
// OR
surprise.enable('.fun-link'); // Enable on specific linksExcluding Links
Add the data-no-surprise attribute to any links you want to exclude:
<a href="/important" data-no-surprise>Important Link</a>Configuration Options
probability(number): Chance of redirect occurring (0-1, default: 0.95)redirectUrl(string): URL to redirect toenabledClass(string): CSS class for enabled linksshowNotice(boolean): Show hover noticenoticeText(string): Text to show in hover noticeexcludeSelector(string): CSS selector for links to exclude
Methods
init(): Initialize the libraryenable(element): Enable surprise redirects on element(s)disable(element): Disable surprise redirects on element(s)enableAll(): Enable surprise redirects on all non-excluded links
