expand-link-script
code:mod.js
var link = document.createElement('link');
link.rel = "stylesheet";
link.href = css;
link.type = "text/css";
document.head.appendChild(link)
const expand = (pattern) => {
const generator = new Generator(pattern);
try {
// " "はワイルドカード
return [
...new Set(
generator.filter(" ").flatMap((pairs) =>
),
),
];
} catch (e) {
// TypeErrorがでたpatternは無視する
if (e instanceof TypeError) return [];
throw e;
}
};
const condition = /^\s*\[([^\n]+)\]/
const processLine = (line) => {
const match = line.match(condition)
if (match === null) {
return line
} else {
return \`[${match[1]}]\ ${expand(match1.replace(/[\\]/g, "")) .flatMap((description) => description !== "" ? [[, [(${description})]]] : [])
.join(" ")}`
}
}
scrapbox.PopupMenu.addButton({
title: (text) => text.split("\n").some(
(line) => condition.test(line.trim())
) ? "正規表現を展開" : "",
onClick: (text) =>
text.split("\n").map(processLine).join("\n"),
});
code:script.js
var St=Reflect.get,At=Reflect.set;var j=(n=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(n,{get:(r,a)=>(typeof require!="undefined"?require:r)a}):n)(function(n){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+n+'" is not supported')});var ht=Object.create,Y=Object.defineProperty,ut=Object.getOwnPropertyDescriptor,ct=Object.getOwnPropertyNames,lt=Object.getPrototypeOf,ft=Object.prototype.hasOwnProperty,dt=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports),gt=(n,r,a,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let p of ct(r))!ft.call(n,p)&&p!==a&&Y(n,p,{get:()=>rp,enumerable:!(l=ut(r,p))||l.enumerable});return n},mt=(n,r,a)=>(a=n!=null?ht(lt(n)):{},gt(r||!n||!n.__esModule?Y(a,"default",{value:n,enumerable:!0}):a,n)),yt=dt((n,r)=>{(function(){var a;a=function(){var l,p,f;l=2147483648,f=256,p=l,0,0,0,u.prototype.isupper=function(e){return e>=65&&e<=90},u.prototype.islower=function(e){return e>=97&&e<=122},u.prototype.tolower=function(e){return this.isupper(e)?e+32:e},u.prototype.toupper=function(e){return this.islower(e)?e-32:e};function u(e){var s,i,t,o,h,c;for(this.source=e,this.shiftpat=[],this.epsilon=0,this.acceptpat=0,i=l,s=t=0;0<=f?t<f:t>f;s=0<=f?++t:--t)this.shiftpats=0;for(c=this.unpack(this.source),o=0,h=c.length;o<h;o++)s=co,s===32?this.epsilon|=i:(this.shiftpats|=i,this.shiftpatthis.toupper(s)|=i,this.shiftpatthis.tolower(s)|=i,i>>>=1);return this.acceptpat=i,this}return u.prototype.state=function(e,s){var i,t,o,h,c,d,y,g,m;for(e==null&&(e=p),s==null&&(s=""),t=e0,o=e1,h=e2,c=e3,m=this.unpack(s),y=0,g=m.length;y<g;y++)i=my,d=this.shiftpati,c=c&this.epsilon|(c&d)>>>1|h>>>1|h,h=h&this.epsilon|(h&d)>>>1|o>>>1|o,o=o&this.epsilon|(o&d)>>>1|t>>>1|t,t=t&this.epsilon|(t&d)>>>1,o|=t>>>1,h|=o>>>1,c|=h>>>1;returnt,o,h,c},u.prototype.match=function(e,s){var i;return s==null&&(s=0),i=this.state(p,e),s<p.length||(s=p.length-1),(is&this.acceptpat)!=0},u.prototype.unpack=function(e){var s,i,t,o,h,c;for(s=[],c=e.split(""),o=0,h=c.length;o<h;o++)i=co,t=i.charCodeAt(0),t>255&&s.push((t&65280)>>>8),s.push(t&255);return s},u}(),typeof r<"u"&&r!==null&&r.exports!=null?r.exports=a:typeof window<"u"&&window!==null&&(window.Asearch=a)}).call(n)}),vt=mt(yt()),{default:tt,...xt}=vt,et=tt!==void 0?tt:xt;var wt=Object.create,rt=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,jt=Object.getOwnPropertyNames,kt=Object.getPrototypeOf,Ot=Object.prototype.hasOwnProperty,Ft=(n=>typeof j<"u"?j:typeof Proxy<"u"?new Proxy(n,{get:(r,a)=>(typeof j<"u"?j:r)a}):n)(function(n){if(typeof j<"u")return j.apply(this,arguments);throw new Error('Dynamic require of "'+n+'" is not supported')}),L=(n,r)=>()=>(r||n((r={exports:{}}).exports,r),r.exports),Tt=(n,r,a,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let p of jt(r))!Ot.call(n,p)&&p!==a&&rt(n,p,{get:()=>rp,enumerable:!(l=bt(r,p))||l.enumerable});return n},Pt=(n,r,a)=>(a=n!=null?wt(kt(n)):{},Tt(r||!n||!n.__esModule?rt(a,"default",{value:n,enumerable:!0}):a,n)),st=L((n,r)=>{var a;a=function(){function l(p){this.s=p,this.a=p.split(""),this.p=0,this.t="",this.u=""}return l.prototype.gettoken=function(){if(this.u!=="")return this.t=this.u,this.u="",this.t;if(this.p>=this.a.length)return this.t="","";if(this.t=this.athis.p,this.t.match(/^[\(\|\)\*\+\?\\]$/))return this.p+=1,this.t;if(this.t==="\\")return this.t=this.a++this.p,this.t==="n"&&(this.t=` ),this.t==="t"&&(this.t=" "),this.p+=1,this.t;for(this.p+=1;this.p<this.a.length&&!this.a[this.p].match(/^[\(\|\)\*\+\?\[\]\\]$/);)this.t+=this.a[this.p++];return this.t},l.prototype.ungettoken=function(){return this.u===""?this.u=this.t:console.log("Can't ungettoken()")},l.prototype.nexttoken=function(){return this.t},l}(),r.exports=a}),nt=L((n,r)=>{var a,l;l=function(){function p(f,u){this.pat=f,this.dest=u}return p.prototype.str=function(){return this.pat.split(/\t/)[0]},p.prototype.arg=function(){var f;return f=this.pat.match(/^(.*)\t(.*)$/),f?f[2]:this.pat},p}(),a=function(){p.id=1,p.nodes={};function p(){this.id=p.id,this.accept=null,this.trans=[],p.nodes[p.id++]=this,this.pars=[]}return p.prototype.addTrans=function(f,u){var e;return e=new l(f,u),this.trans.push(e)},p.node=function(f){return p.nodes[f]},p}(),r.exports=a}),_t=L((n,r)=>{var a,l,p;a=nt(),p=st(),l=function(){function f(){}return f.prototype.regexp=function(u,e){var s,i,t,o,h,c;for(e==null&&(e=!1),c=new a,s=new a,e&&(this.pars=[],this.parno=0,this.ruleid=0),c.pars=this.pars,s.pars=this.pars,o=this.regcat(u),i=o[0],t=o[1],c.addTrans("",i),e&&(t.accept=this.ruleid),t.addTrans("",s);u.gettoken()==="|"&&u.nexttoken()!=="";)e&&(this.pars=[],this.parno=0,this.ruleid+=1),h=this.regcat(u),i=h[0],t=h[1],c.addTrans("",i),e&&(t.accept=this.ruleid),t.addTrans("",s);return u.ungettoken(),[c,s]},f.prototype.regcat=function(u){var e,s,i,t,o,h;for(t=this.regfactor(u),h=t[0],e=t[1];!u.gettoken().match(/^[\)\]\|]$/)&&u.nexttoken()!=="";)u.ungettoken(),o=this.regfactor(u),s=o[0],i=o[1],e.addTrans("",s),e=i;return u.ungettoken(),[h,e]},f.prototype.regfactor=function(u){var e,s,i,t,o;return i=this.regterm(u),t=i[0],e=i[1],o=u.gettoken(),o.match(/^[\?]$/)?t.addTrans("",e):o.match(/^[\+]$/)?e.addTrans("",t):o.match(/^[\*]$/)?(s=new a,t.addTrans("",e),e.addTrans("",s),s.addTrans("",t)):u.ungettoken(),[t,e]},f.prototype.regterm=function(u){var e,s,i,t,o,h;return h=u.gettoken(),h==="("?(this.parno+=1,this.pars.push(this.parno),t=this.regexp(u),s=t[0],i=t[1],s.pars=this.pars.slice(0),h=u.gettoken(),h===")"?(this.pars.pop(),i.pars=this.pars.slice(0),[s,i]):(console.log("missing )"),null)):(o=new a,o.pars=this.pars.slice(0),e=new a,e.pars=this.pars.slice(0),o.addTrans(h,e),[o,e])},f}(),r.exports=l}),$t=L((n,r)=>{var a,l,p,f,u,e;e=st(),u=_t(),f=nt(),a=et,l=function(){function s(i,t,o,h,c){this.id=i,this.state=t??[],this.s=o??"",this.substrings=h??[],this.accept=c??!1}return s}(),p=function(){function s(i,t){i==null&&(i=""),t==null&&(t=""),this.s=[i],this.commands=[t],this.par=0}return s.prototype.add=function(i,t){return this.s[0]===""?this.s=[i]:this.s.push(i),this.commands[0]===""?this.commands=[t]:this.commands.push(t)},s.prototype.delete=function(){return this.s.pop,this.commands.pop},s.prototype.filter=function(i,t,o){var h,c,d,y,g,m,w,F,C,M,W,X,Z,G,b,I,E,N,z,S,A,H,T,P,at,_,J,K,Q,$,q,k,x,D,v,R,V,O;for(t==null&&(t=null),this.maxambig=o??2,k=[[],[],[]],at=i.split("").map(function(pt){return pt.toLowerCase()}),this.asearch=new a(i),this.regexp=new u,this.scanner=new e(this.s.join("|")),J=this.regexp.regexp(this.scanner,!0),V=J[0],y=J[1],E=[],I=[{},{},{}],m={},b=[],b[0]=new l(V.id,this.asearch.state()),E[0]=b,G=F=0;F<=1e4;G=++F){for(b=E[G],A=[],C=0,W=b.length;C<W;C++)if(g=b[C],D=f.node(g.id),b.length*D.trans.length<1e5)for(K=D.trans,M=0,X=K.length;M<X;M++){for(O=K[M],v=g.substrings.slice(0),Q=D.pars,S=0,Z=Q.length;S<Z;S++)w=Q[S],typeof v[w-1]>"u"&&(v[w-1]=""),v[w-1]=v[w-1]+O.arg();if(H=this.asearch.state(g.state,O.str()),x=g.s+O.str(),h=O.dest.accept,A.push(new l(O.dest.id,H,x,v,h)),h!==null){for(c=T=0,$=this.maxambig;0<=$?T<=$:T>=$;c=0<=$?++T:--T)if((t&&!m[x]||!t&&!I[c][x])&&H[c]&this.asearch.acceptpat){if(I[c][x]=!0,m[x]=!0,R=v.length,z=[],R>0){for(P=[],w=_=0,q=R;0<=q?_<q:_>q;w=0<=q?++_:--_)P.push("(.*)");P=P.join(" "),z=v.join(" ").match(P)}for(d=this.commands[h],d||(d="");N=d.match(/^(.*)(\$(\d+))(.*)$/);)d=""+N[1]+z[N[3]]+N[4];t?t([x].concat(v),d):k[c].push([x,d])}}}if(A.length===0||(E.push(A),k[0].length>100))break}return[k[0],k[1],k[2]]},s}(),String.prototype.expand=function(s,i,t){var o,h,c,d,y,g,m;if(s==null&&(s=" "),i==null&&(i=null),t==null&&(t=0),o=new p,o.add(this,""),m=[],i)return o.filter(s,i);for(d=o.filter(s),y=d[0].length>0?d[0]:d[1].length>0?d[1]:d[2],h=0,c=y.length;h<c;h++)g=y[h],m.push(g[0]);return m},r.exports=p}),qt=Pt($t()),{default:it,...Ct}=qt,U=it!==void 0?it:Ct;var Mt="https://scrapbox.io/api/code/yuyasurarin/javascriptでCSSを読み込む/style.css",B=document.createElement("link");B.rel="stylesheet";B.href=Mt;B.type="text/css";document.head.appendChild(B);var Et=n=>{let r=new U(n);try{return[...new Set(r.filter(" ").flatMap(a=>a.map(([l])=>l)))]}catch(a){if(a instanceof TypeError)return[];throw a}},ot=/^\s*\[(^\n+)\]/,Nt=n=>{let r=n.match(ot);return r===null?n:\[${r[1]}]\` ${Et(r[1].replace(/[\[\]]/g,"")).flatMap(a=>a!==""?[(${a})]:[]).join(" ")}};scrapbox.PopupMenu.addButton({title:n=>n.split(` ).some(r=>ot.test(r.trim()))?"正規表現を展開":"",onClick:n=>n.split(
).map(Nt).join(
`)});