PageSourceSearch

https://ublockdns.com/assets/CustomRules-BSlib_w8.js

js ublockdns.com collected 2026-10-08 23:42:31 UTC 7,412 bytes, 10 lines download raw bytes

1import{j as e,r}from"./react-vendor-x00L2m6Q.js";import{X as Y,Z,I as E,B as d,D as M,Y as q,a as G,V as J}from"./index-BM2DonU4.js";import{M as C}from"./constants-CNVO5n9V.js";import{c as Q,p as y,e as ee,f as R}from"./filterListGroups-CLJxf0DV.js";import{l as F,r as L,t as se,U as te,e as ae,h as ne}from"./icons-Bp1JXQ6z.js";import"./tw-utils-DZiiT1zZ.js";function ie({className:a,...l}){return e.jsx("textarea",{"data-slot":"textarea",className:Y("border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-sm border bg-transparent px-3 py-2 text-base font-mono transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",a),...l})}function le({rule:a,onToggle:l,onRemove:z}){return e.jsxs("div",{className:"flex min-w-0 items-center gap-2 px-2 py-2 sm:py-1",children:[e.jsx(q,{domain:a.domain,className:"size-5"}),e.jsx("span",{className:"flex-1 min-w-0 truncate font-mono text-xs",children:a.domain}),e.jsx("button",{onClick:l,className:`shrink-0 cursor-pointer ${G}`,children:e.jsx(J,{variant:a.type==="block"?"destructive":"secondary",className:"cursor-pointer hover:opacity-80 transition-opacity",children:a.type==="block"?"Blocked":"Allowed"})}),e.jsx(M,{size:"default",onClick:z,"aria-label":`Remove ${a.domain}`,className:"-m-1 text-muted-foreground/40"})]})}function ue({value:a,onChange:l,mode:z="simple"}){const{copied:A,copy:U}=Z(),[c,D]=r.useState(""),[m,O]=r.useState(""),[I,b]=r.useState(!1),[x,h]=r.useState(""),[T,S]=r.useState(""),[g,v]=r.useState(""),j=Q(a),N=j>=C,f=y(a);r.useEffect(()=>{if(!g)return;const s=setTimeout(()=>v(""),6e3);return()=>clearTimeout(s)},[g]);const u=(s,t)=>{const o=s.map(ee).filter(n=>n.length>0);if(o.length===0)return;const i=y(a),X=new Set(i.map(n=>n.domain)),k=[];for(const n of o)if(X.has(n)){const B=i.findIndex(_=>_.domain===n);B!==-1&&(i[B]={domain:n,type:t,raw:t==="allow"?`@@||${n}^`:`||${n}^`})}else k.push({domain:n,type:t,raw:t==="allow"?`@@||${n}^`:`||${n}^`});const $=k.slice(0,Math.max(0,C-i.length));$.length<k.length?S(`Added ${$.length} of ${k.length} new domains (limit: ${C})`):S(""),l(R([...i,...$])),D(""),v("Saved. Changes take effect within ~30-90s.")},P=s=>{const t=y(a);t.splice(s,1),l(R(t)),v("Saved. Changes take effect within ~30-90s.")},V=s=>{const t=y(a),o=t[s],i=o.type==="block"?"allow":"block";t[s]={domain:o.domain,type:i,raw:i==="allow"?`@@||${o.domain}^`:`||${o.domain}^`},l(R(t)),v("Saved. Changes take effect within ~30-90s.")},H=s=>{s.key==="Enter"&&(s.preventDefault(),u(c.split(`
2`),"block"))},K=s=>{const t=s.clipboardData.getData("text");t.includes(`
3`)&&(s.preventDefault(),u(t.split(`
4`),"block"))},p=z==="advanced",W=p?"divide-y divide-border/50 overflow-x-hidden":"divide-y divide-border/50 max-h-[240px] overflow-y-auto overflow-x-hidden",w=p&&m?f.map((s,t)=>({rule:s,i:t})).filter(({rule:s})=>s.domain.includes(m.toLowerCase())):f.map((s,t)=>({rule:s,i:t}));return e.jsxs("div",{children:[e.jsxs("div",{className:"flex gap-1.5 mb-3",children:[e.jsx(E,{id:"add-domain",name:"add-domain","aria-label":"Add domain",className:"flex-1 text-base md:text-xs h-9 sm:h-8",value:c,onChange:s=>D(s.target.value),onKeyDown:H,onPaste:K,placeholder:"Add domain...",disabled:N,spellCheck:!1,autoCapitalize:"none",autoCorrect:"off"}),e.jsxs(d,{variant:"destructive",size:"sm",className:"h-9 sm:h-8 px-2.5 text-[11px] shrink-0",disabled:!c.trim()||N,onClick:()=>u(c.split(`
5`),"block"),children:[e.jsx(F,{className:"size-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Block"})]}),e.jsxs(d,{variant:"outline",size:"sm",className:"h-9 sm:h-8 px-2.5 text-[11px] shrink-0",disabled:!c.trim()||N,onClick:()=>u(c.split(`
6`),"allow"),children:[e.jsx(L,{className:"size-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Allow"})]})]}),I&&e.jsxs("div",{className:"border border-border rounded-sm p-2.5 mb-1.5 space-y-2 bg-muted/30",children:[e.jsx(ie,{id:"import-domains",name:"import-domains","aria-label":"Import domains",className:"font-mono text-base md:text-xs min-h-[100px]",value:x,onChange:s=>h(s.target.value),placeholder:"Paste domains, one per line...",spellCheck:!1,autoFocus:!0,autoCapitalize:"none",autoCorrect:"off"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-2xs text-muted-foreground font-mono",children:[x.split(`
7`).filter(s=>s.trim()).length," domains"]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(d,{variant:"ghost",size:"sm",className:"h-9 sm:h-7 px-2.5 text-[11px]",onClick:()=>{b(!1),h("")},children:"Cancel"}),e.jsxs(d,{variant:"destructive",size:"sm",className:"h-9 sm:h-7 px-2.5 text-[11px]",disabled:!x.trim(),onClick:()=>{u(x.split(`
8`),"block"),b(!1),h("")},children:[e.jsx(F,{className:"size-3.5"}),"Block All"]}),e.jsxs(d,{variant:"outline",size:"sm",className:"h-9 sm:h-7 px-2.5 text-[11px]",disabled:!x.trim(),onClick:()=>{u(x.split(`
9`),"allow"),b(!1),h("")},children:[e.jsx(L,{className:"size-3.5"}),"Allow All"]})]})]})]}),T&&e.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1.5 mb-1.5 rounded-sm bg-warning/10 border border-warning/20",children:[e.jsx("span",{className:"text-[11px] text-warning",children:T}),e.jsx(M,{size:"default",onClick:()=>S(""),className:"-m-1.5 text-warning hover:text-warning"})]}),p&&f.length>0&&e.jsxs("div",{className:"relative mb-1.5",children:[e.jsx(se,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 size-3 text-muted-foreground pointer-events-none"}),e.jsx(E,{id:"filter-rules",name:"filter-rules","aria-label":"Filter rules",className:"text-base md:text-xs h-7 pl-7",value:m,onChange:s=>O(s.target.value),placeholder:"Filter...",spellCheck:!1})]}),w.length>0?e.jsx("div",{className:W,children:(p?w:w.slice(-5)).map(({rule:s,i:t})=>e.jsx(le,{rule:s,onToggle:()=>V(t),onRemove:()=>P(t)},`${s.domain}-${t}`))}):f.length>0&&m?e.jsxs("div",{className:"text-xs text-muted-foreground text-center py-6 border border-border rounded-sm border-dashed",children:["No rules matching “",m,"”"]}):e.jsx("div",{className:"text-xs text-muted-foreground text-center py-6 border border-border rounded-sm border-dashed",children:"No custom rules yet"}),e.jsxs("div",{className:"flex items-center justify-between mt-1.5",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Custom rules override filter lists."}),j>0&&e.jsxs("span",{className:`text-2xs font-mono tabular-nums shrink-0 ml-2 ${N?"text-destructive font-medium":"text-muted-foreground"}`,children:[p&&m?`${w.length} of `:"",j,"/",C]})]}),g&&e.jsx("div",{role:"status","aria-live":"polite",className:"mt-1 bg-muted rounded-sm px-3 py-2",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:g})}),p&&e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsxs(d,{variant:"outline",size:"sm",className:"flex-1 justify-center",onClick:()=>{b(!I),h("")},children:[e.jsx(te,{className:"size-3.5"}),"Import"]}),e.jsxs(d,{variant:"outline",size:"sm",className:"flex-1 justify-center",disabled:j===0,onClick:()=>{const s=f.map(t=>t.raw).join(`
10`);U(s)},children:[A?e.jsx(ae,{className:"size-3.5"}):e.jsx(ne,{className:"size-3.5"}),A?"Copied":"Copy All"]})]})]})}export{ue as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.