|
| 1 | +import clsx from 'clsx'; |
| 2 | +import { Megaphone, X, Copy, Check } from 'lucide-react'; |
| 3 | +import { useEffect, useState } from 'react'; |
| 4 | +import { createPortal } from 'react-dom'; |
| 5 | +import { useOptions } from '../utils/optionsContext'; |
| 6 | + |
| 7 | +const DisableAds = ({ isOpen, onClose }) => { |
| 8 | + const { options } = useOptions(); |
| 9 | + const [anim, setAnim] = useState(false); |
| 10 | + const [render, setRender] = useState(false); |
| 11 | + const [copied, setCopied] = useState(false); |
| 12 | + const dUrl = 'https://discord.gg/ZBef7HnAeg'; |
| 13 | + |
| 14 | + useEffect(() => { |
| 15 | + if (isOpen) { |
| 16 | + setRender(true); |
| 17 | + setCopied(false); |
| 18 | + setTimeout(() => setAnim(true), 10); |
| 19 | + } else { |
| 20 | + setAnim(false); |
| 21 | + setTimeout(() => setRender(false), 200); |
| 22 | + } |
| 23 | + }, [isOpen]); |
| 24 | + |
| 25 | + const copyDiscordUrl = async () => { |
| 26 | + try { |
| 27 | + await navigator.clipboard.writeText(dUrl); |
| 28 | + setCopied(true); |
| 29 | + } catch { |
| 30 | + setCopied(false); |
| 31 | + } |
| 32 | + }; |
| 33 | + |
| 34 | + if (!render) return null; |
| 35 | + |
| 36 | + const light = options.type === 'light'; |
| 37 | + const cardBg = options.settingsPanelItemBackgroundColor || (light ? '#f3f4f6' : '#ffffff0c'); |
| 38 | + const cardBorder = options.paginationBorderColor || (light ? '#d1d5db' : '#374151'); |
| 39 | + const mutedText = options.paginationTextColor || (light ? '#4b5563' : '#9ca3af'); |
| 40 | + const actionColor = options.siteTextColor || '#a0b0c8'; |
| 41 | + const badgeText = light ? '#111827' : '#ffffff'; |
| 42 | + const badgeBg = actionColor; |
| 43 | + |
| 44 | + return createPortal( |
| 45 | + <div |
| 46 | + className={clsx( |
| 47 | + 'fixed inset-0 z-9999 flex items-center justify-center p-4 transition-opacity', |
| 48 | + anim ? 'opacity-100' : 'opacity-0', |
| 49 | + )} |
| 50 | + > |
| 51 | + <div className="fixed inset-0 bg-black/50" onClick={onClose} /> |
| 52 | + |
| 53 | + <div |
| 54 | + className={clsx( |
| 55 | + 'relative w-full max-w-2xl max-h-[80vh] rounded-lg border shadow-lg overflow-hidden transition-all', |
| 56 | + anim ? 'scale-100 opacity-100' : 'scale-95 opacity-0', |
| 57 | + )} |
| 58 | + style={{ backgroundColor: options.menuColor || '#1a252f' }} |
| 59 | + > |
| 60 | + <div |
| 61 | + className="flex items-center justify-between px-4 py-3 border-b" |
| 62 | + style={{ borderColor: light ? '#e5e7eb' : '#374151' }} |
| 63 | + > |
| 64 | + <div className="flex items-center gap-2"> |
| 65 | + <Megaphone size={18} /> |
| 66 | + <h2 className="text-lg font-medium">Disable Ads</h2> |
| 67 | + </div> |
| 68 | + <button |
| 69 | + onClick={onClose} |
| 70 | + className={clsx('p-1 rounded-md', light ? 'hover:bg-gray-100' : 'hover:bg-[#ffffff0c]')} |
| 71 | + > |
| 72 | + <X size={20} /> |
| 73 | + </button> |
| 74 | + </div> |
| 75 | + |
| 76 | + <div className="p-4 overflow-y-auto max-h-[calc(80vh-4rem)]"> |
| 77 | + <div className="space-y-3"> |
| 78 | + <p className="text-sm" style={{ color: mutedText }}> |
| 79 | + Follow these steps to disable ads: |
| 80 | + </p> |
| 81 | + |
| 82 | + <div |
| 83 | + className="rounded-md border p-3 flex items-start gap-3" |
| 84 | + style={{ backgroundColor: cardBg, borderColor: cardBorder }} |
| 85 | + > |
| 86 | + <div |
| 87 | + className="w-6 h-6 rounded-full flex items-center justify-center text-xs font-semibold" |
| 88 | + style={{ backgroundColor: badgeBg, color: badgeText }} |
| 89 | + > |
| 90 | + 1 |
| 91 | + </div> |
| 92 | + <div className="min-w-0 text-sm"> |
| 93 | + <div className="font-medium">Join our Discord</div> |
| 94 | + <div className="mt-1 flex items-center gap-2"> |
| 95 | + <a |
| 96 | + href={dUrl} |
| 97 | + target="_blank" |
| 98 | + rel="noopener noreferrer" |
| 99 | + className="text-xs px-2 py-1 rounded border break-all" |
| 100 | + style={{ |
| 101 | + color: actionColor, |
| 102 | + borderColor: cardBorder, |
| 103 | + backgroundColor: options.paginationBgColor || cardBg, |
| 104 | + }} |
| 105 | + > |
| 106 | + {dUrl} |
| 107 | + </a> |
| 108 | + <button |
| 109 | + onClick={copyDiscordUrl} |
| 110 | + className="text-xs px-2 py-1 rounded border inline-flex items-center gap-1" |
| 111 | + style={{ |
| 112 | + color: actionColor, |
| 113 | + borderColor: cardBorder, |
| 114 | + backgroundColor: options.paginationBgColor || cardBg, |
| 115 | + }} |
| 116 | + > |
| 117 | + {copied ? <Check size={13} /> : <Copy size={13} />} |
| 118 | + {copied ? 'Copied' : 'Copy'} |
| 119 | + </button> |
| 120 | + </div> |
| 121 | + </div> |
| 122 | + </div> |
| 123 | + |
| 124 | + <div |
| 125 | + className="rounded-md border p-3 flex items-start gap-3" |
| 126 | + style={{ backgroundColor: cardBg, borderColor: cardBorder }} |
| 127 | + > |
| 128 | + <div |
| 129 | + className="w-6 h-6 rounded-full flex items-center justify-center text-xs font-semibold" |
| 130 | + style={{ backgroundColor: badgeBg, color: badgeText }} |
| 131 | + > |
| 132 | + 2 |
| 133 | + </div> |
| 134 | + <div className="text-sm"> |
| 135 | + <div className="font-medium">Obtain an ad key</div> |
| 136 | + <div className="mt-1" style={{ color: mutedText }}> |
| 137 | + Ask in Discord and copy your ad key |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + </div> |
| 141 | + |
| 142 | + <div |
| 143 | + className="rounded-md border p-3 flex items-start gap-3" |
| 144 | + style={{ backgroundColor: cardBg, borderColor: cardBorder }} |
| 145 | + > |
| 146 | + <div |
| 147 | + className="w-6 h-6 rounded-full flex items-center justify-center text-xs font-semibold" |
| 148 | + style={{ backgroundColor: badgeBg, color: badgeText }} |
| 149 | + > |
| 150 | + 3 |
| 151 | + </div> |
| 152 | + <div className="text-sm"> |
| 153 | + <div className="font-medium">Add key in Settings</div> |
| 154 | + <div className="mt-1" style={{ color: mutedText }}> |
| 155 | + Go to Settings > Advanced and paste your ad key to disable ads. |
| 156 | + </div> |
| 157 | + </div> |
| 158 | + </div> |
| 159 | + </div> |
| 160 | + </div> |
| 161 | + </div> |
| 162 | + </div>, |
| 163 | + document.body, |
| 164 | + ); |
| 165 | +}; |
| 166 | + |
| 167 | +export default DisableAds; |
0 commit comments