1.0.0 • Published 7 months ago
rick-n-roll v1.0.0
Rick Roll Redirect
A lightweight library that adds surprise redirects to your website links.
Installation
npm install rick-n-roll
Quick 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 links
Excluding 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
1.0.0
7 months ago