Skip to content

Full Toolkit for Next-Level Domain Analysis

Add safeguards for bookmarklet 🛟

Felix Wotschofskyf6132fb0d474
diff --git a/app/page.tsx b/app/page.tsx
index f27eaac..a6604a1 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -20,7 +20,7 @@ const Home = () => {
<Card className="mx-auto my-16 max-w-lg p-6">
<h2 className="mb-5 text-center text-xl font-semibold tracking-tight sm:text-2xl">
- Quickly inspect any Website
+ Quick Inspect Bookmarklet
</h2>
<p className="mb-5 mt-2 text-center text-sm text-muted-foreground">
diff --git a/components/BookmarkletLink.tsx b/components/BookmarkletLink.tsx
index 70b610d..e56aefa 100644
--- a/components/BookmarkletLink.tsx
+++ b/components/BookmarkletLink.tsx
@@ -1,9 +1,25 @@
'use client';
-import { useEffect, useState } from 'react';
+import {
+ type MouseEventHandler,
+ useCallback,
+ useEffect,
+ useState,
+} from 'react';
+
+import {
+ AlertDialog,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from '@/components/ui/alert-dialog';
const BookmarkletLink = () => {
const [target, setTarget] = useState('');
+ const [isOpen, setOpen] = useState(false);
useEffect(() => {
const rawScript = `
@@ -23,16 +39,42 @@ const BookmarkletLink = () => {
setTarget(`javascript:${minifiedScript}`);
}, []);
+ const clickHandler = useCallback<MouseEventHandler<HTMLAnchorElement>>(
+ (event) => {
+ event.preventDefault();
+ setOpen(true);
+ },
+ [setOpen]
+ );
+
return (
- <div className="flex justify-center">
- {target ? (
- <a className="text-center" href={target}>
- Inspect Domain
- </a>
- ) : (
- <span className="text-center">Loading...</span>
- )}
- </div>
+ <>
+ <div className="flex justify-center">
+ {target ? (
+ <a className="text-center" href={target} onClick={clickHandler}>
+ Inspect Domain
+ </a>
+ ) : (
+ <span className="text-center">Loading...</span>
+ )}
+ </div>
+
+ <AlertDialog open={isOpen} onOpenChange={setOpen}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Installation required</AlertDialogTitle>
+ <AlertDialogDescription>
+ This link is a bookmarklet intended to be dragged into your
+ browser&apos;s bookmark bar. It can be clicked from anywhere to
+ open the results page for the site you are currently on.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Ok</AlertDialogCancel>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </>
);
};
diff --git a/components/ui/alert-dialog.tsx b/components/ui/alert-dialog.tsx
new file mode 100644
index 0000000..239da40
--- /dev/null
+++ b/components/ui/alert-dialog.tsx
@@ -0,0 +1,146 @@
+'use client';
+
+import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
+import * as React from 'react';
+
+import { buttonVariants } from '@/components/ui/button';
+
+import { cn } from '@/lib/utils';
+
+const AlertDialog = AlertDialogPrimitive.Root;
+
+const AlertDialogTrigger = AlertDialogPrimitive.Trigger;
+
+const AlertDialogPortal = ({
+ className,
+ ...props
+}: AlertDialogPrimitive.AlertDialogPortalProps) => (
+ <AlertDialogPrimitive.Portal className={cn(className)} {...props} />
+);
+AlertDialogPortal.displayName = AlertDialogPrimitive.Portal.displayName;
+
+const AlertDialogOverlay = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
+>(({ className, children, ...props }, ref) => (
+ <AlertDialogPrimitive.Overlay
+ className={cn(
+ 'fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
+ className
+ )}
+ {...props}
+ ref={ref}
+ />
+));
+AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;
+
+const AlertDialogContent = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPortal>
+ <AlertDialogOverlay />
+ <AlertDialogPrimitive.Content
+ ref={ref}
+ className={cn(
+ 'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg md:w-full',
+ className
+ )}
+ {...props}
+ />
+ </AlertDialogPortal>
+));
+AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;
+
+const AlertDialogHeader = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn(
+ 'flex flex-col space-y-2 text-center sm:text-left',
+ className
+ )}
+ {...props}
+ />
+);
+AlertDialogHeader.displayName = 'AlertDialogHeader';
+
+const AlertDialogFooter = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn(
+ 'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2',
+ className
+ )}
+ {...props}
+ />
+);
+AlertDialogFooter.displayName = 'AlertDialogFooter';
+
+const AlertDialogTitle = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Title>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Title
+ ref={ref}
+ className={cn('text-lg font-semibold', className)}
+ {...props}
+ />
+));
+AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;
+
+const AlertDialogDescription = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Description>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Description
+ ref={ref}
+ className={cn('text-sm text-muted-foreground', className)}
+ {...props}
+ />
+));
+AlertDialogDescription.displayName =
+ AlertDialogPrimitive.Description.displayName;
+
+const AlertDialogAction = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Action>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Action
+ ref={ref}
+ className={cn(buttonVariants(), className)}
+ {...props}
+ />
+));
+AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;
+
+const AlertDialogCancel = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Cancel
+ ref={ref}
+ className={cn(
+ buttonVariants({ variant: 'outline' }),
+ 'mt-2 sm:mt-0',
+ className
+ )}
+ {...props}
+ />
+));
+AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;
+
+export {
+ AlertDialog,
+ AlertDialogTrigger,
+ AlertDialogContent,
+ AlertDialogHeader,
+ AlertDialogFooter,
+ AlertDialogTitle,
+ AlertDialogDescription,
+ AlertDialogAction,
+ AlertDialogCancel,
+};
diff --git a/package.json b/package.json
index f37cf5b..2da5704 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"format": "yarn prettier --write \"**/*.{js,jsx,ts,tsx,json,css,scss,md,mdx}\""
},
"dependencies": {
+ "@radix-ui/react-alert-dialog": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.3",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-slot": "^1.0.1",
diff --git a/yarn.lock b/yarn.lock
index 71fde86..0f64130 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -393,6 +393,19 @@
dependencies:
"@babel/runtime" "^7.13.10"
+"@radix-ui/react-alert-dialog@^1.0.4":
+ version "1.0.4"
+ resolved "https://registry.yarnpkg.com/@radix-ui/react-alert-dialog/-/react-alert-dialog-1.0.4.tgz#709d7625efadac503c6276d9e92d3449184f5e68"
+ integrity sha512-jbfBCRlKYlhbitueOAv7z74PXYeIQmWpKwm3jllsdkw7fGWNkxqP3v0nY9WmOzcPqpQuoorNtvViBgL46n5gVg==
+ dependencies:
+ "@babel/runtime" "^7.13.10"
+ "@radix-ui/primitive" "1.0.1"
+ "@radix-ui/react-compose-refs" "1.0.1"
+ "@radix-ui/react-context" "1.0.1"
+ "@radix-ui/react-dialog" "1.0.4"
+ "@radix-ui/react-primitive" "1.0.3"
+ "@radix-ui/react-slot" "1.0.2"
+
"@radix-ui/[email protected]":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@radix-ui/react-arrow/-/react-arrow-1.0.2.tgz#93b0ff95f65e2264a05b14ef1031ec798243dd6f"
@@ -459,6 +472,27 @@
dependencies:
"@babel/runtime" "^7.13.10"
+"@radix-ui/[email protected]":
+ version "1.0.4"
+ resolved "https://registry.yarnpkg.com/@radix-ui/react-dialog/-/react-dialog-1.0.4.tgz#06bce6c16bb93eb36d7a8589e665a20f4c1c52c1"
+ integrity sha512-hJtRy/jPULGQZceSAP2Re6/4NpKo8im6V8P2hUqZsdFiSL8l35kYsw3qbRI6Ay5mQd2+wlLqje770eq+RJ3yZg==
+ dependencies:
+ "@babel/runtime" "^7.13.10"
+ "@radix-ui/primitive" "1.0.1"
+ "@radix-ui/react-compose-refs" "1.0.1"
+ "@radix-ui/react-context" "1.0.1"
+ "@radix-ui/react-dismissable-layer" "1.0.4"
+ "@radix-ui/react-focus-guards" "1.0.1"
+ "@radix-ui/react-focus-scope" "1.0.3"
+ "@radix-ui/react-id" "1.0.1"
+ "@radix-ui/react-portal" "1.0.3"
+ "@radix-ui/react-presence" "1.0.1"
+ "@radix-ui/react-primitive" "1.0.3"
+ "@radix-ui/react-slot" "1.0.2"
+ "@radix-ui/react-use-controllable-state" "1.0.1"
+ aria-hidden "^1.1.1"
+ react-remove-scroll "2.5.5"
+
"@radix-ui/react-dialog@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@radix-ui/react-dialog/-/react-dialog-1.0.3.tgz#a715bf30f35fcd80476c0a07fcc073c1968e6d3e"