Created
December 1, 2023 16:08
-
-
Save noaione/aebc21094dbc93824b6793b7c800932b to your computer and use it in GitHub Desktop.
Script to quickly get metadata from the HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Anchira - Meta Fetch | |
// @namespace anchira-meta-fetcher | |
// @match https://anchira.to/* | |
// @grant none | |
// @version 1.1.0 | |
// @author noaione | |
// @description Quick script to add button to scrape the metadata | |
// ==/UserScript== | |
(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const r of i)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const r={};return i.integrity&&(r.integrity=i.integrity),i.referrerPolicy&&(r.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?r.credentials="include":i.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function s(i){if(i.ep)return;i.ep=!0;const r=n(i);fetch(i.href,r)}})();const Me=Symbol.for("yaml.alias"),Le=Symbol.for("yaml.document"),F=Symbol.for("yaml.map"),tt=Symbol.for("yaml.pair"),he=Symbol.for("yaml.scalar"),G=Symbol.for("yaml.seq"),B=Symbol.for("yaml.node.type"),H=t=>!!t&&typeof t=="object"&&t[B]===Me,ye=t=>!!t&&typeof t=="object"&&t[B]===Le,se=t=>!!t&&typeof t=="object"&&t[B]===F,I=t=>!!t&&typeof t=="object"&&t[B]===tt,$=t=>!!t&&typeof t=="object"&&t[B]===he,ie=t=>!!t&&typeof t=="object"&&t[B]===G;function A(t){if(t&&typeof t=="object")switch(t[B]){case F:case G:return!0}return!1}function j(t){if(t&&typeof t=="object")switch(t[B]){case Me:case F:case he:case G:return!0}return!1}const jt=t=>($(t)||A(t))&&!!t.anchor,K=Symbol("break visit"),Lt=Symbol("skip children"),ee=Symbol("remove node");function q(t,e){const n=kt(e);ye(t)?V(null,t.contents,n,Object.freeze([t]))===ee&&(t.contents=null):V(null,t,n,Object.freeze([]))}q.BREAK=K;q.SKIP=Lt;q.REMOVE=ee;function V(t,e,n,s){const i=Tt(t,e,n,s);if(j(i)||I(i))return Bt(t,s,i),V(t,i,n,s);if(typeof i!="symbol"){if(A(e)){s=Object.freeze(s.concat(e));for(let r=0;r<e.items.length;++r){const o=V(r,e.items[r],n,s);if(typeof o=="number")r=o-1;else{if(o===K)return K;o===ee&&(e.items.splice(r,1),r-=1)}}}else if(I(e)){s=Object.freeze(s.concat(e));const r=V("key",e.key,n,s);if(r===K)return K;r===ee&&(e.key=null);const o=V("value",e.value,n,s);if(o===K)return K;o===ee&&(e.value=null)}}return i}function kt(t){return typeof t=="object"&&(t.Collection||t.Node||t.Value)?Object.assign({Alias:t.Node,Map:t.Node,Scalar:t.Node,Seq:t.Node},t.Value&&{Map:t.Value,Scalar:t.Value,Seq:t.Value},t.Collection&&{Map:t.Collection,Seq:t.Collection},t):t}function Tt(t,e,n,s){var i,r,o,l,f;if(typeof n=="function")return n(t,e,s);if(se(e))return(i=n.Map)==null?void 0:i.call(n,t,e,s);if(ie(e))return(r=n.Seq)==null?void 0:r.call(n,t,e,s);if(I(e))return(o=n.Pair)==null?void 0:o.call(n,t,e,s);if($(e))return(l=n.Scalar)==null?void 0:l.call(n,t,e,s);if(H(e))return(f=n.Alias)==null?void 0:f.call(n,t,e,s)}function Bt(t,e,n){const s=e[e.length-1];if(A(s))s.items[t]=n;else if(I(s))t==="key"?s.key=n:s.value=n;else if(ye(s))s.contents=n;else{const i=H(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${i} parent`)}}const Mt={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},Ct=t=>t.replace(/[!,[\]{}]/g,e=>Mt[e]);class L{constructor(e,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},L.defaultYaml,e),this.tags=Object.assign({},L.defaultTags,n)}clone(){const e=new L(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){const e=new L(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:L.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},L.defaultTags);break}return e}add(e,n){this.atNextDocument&&(this.yaml={explicit:L.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},L.defaultTags),this.atNextDocument=!1);const s=e.trim().split(/[ \t]+/),i=s.shift();switch(i){case"%TAG":{if(s.length!==2&&(n(0,"%TAG directive should contain exactly two parts"),s.length<2))return!1;const[r,o]=s;return this.tags[r]=o,!0}case"%YAML":{if(this.yaml.explicit=!0,s.length!==1)return n(0,"%YAML directive should contain exactly one part"),!1;const[r]=s;if(r==="1.1"||r==="1.2")return this.yaml.version=r,!0;{const o=/^\d+\.\d+$/.test(r);return n(6,`Unsupported YAML version ${r}`,o),!1}}default:return n(0,`Unknown directive ${i}`,!0),!1}}tagName(e,n){if(e==="!")return"!";if(e[0]!=="!")return n(`Not a valid tag: ${e}`),null;if(e[1]==="<"){const o=e.slice(2,-1);return o==="!"||o==="!!"?(n(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==">"&&n("Verbatim tags must end with a >"),o)}const[,s,i]=e.match(/^(.*!)([^!]*)$/s);i||n(`The ${e} tag has no suffix`);const r=this.tags[s];if(r)try{return r+decodeURIComponent(i)}catch(o){return n(String(o)),null}return s==="!"?e:(n(`Could not resolve tag: ${e}`),null)}tagString(e){for(const[n,s]of Object.entries(this.tags))if(e.startsWith(s))return n+Ct(e.substring(s.length));return e[0]==="!"?e:`!<${e}>`}toString(e){const n=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],s=Object.entries(this.tags);let i;if(e&&s.length>0&&j(e.contents)){const r={};q(e.contents,(o,l)=>{j(l)&&l.tag&&(r[l.tag]=!0)}),i=Object.keys(r)}else i=[];for(const[r,o]of s)r==="!!"&&o==="tag:yaml.org,2002:"||(!e||i.some(l=>l.startsWith(o)))&&n.push(`%TAG ${r} ${o}`);return n.join(` | |
`)}}L.defaultYaml={explicit:!1,version:"1.2"};L.defaultTags={"!!":"tag:yaml.org,2002:"};function nt(t){if(/[\x00-\x19\s,[\]{}]/.test(t)){const n=`Anchor must not contain whitespace or control characters: ${JSON.stringify(t)}`;throw new Error(n)}return!0}function st(t){const e=new Set;return q(t,{Value(n,s){s.anchor&&e.add(s.anchor)}}),e}function it(t,e){for(let n=1;;++n){const s=`${t}${n}`;if(!e.has(s))return s}}function Pt(t,e){const n=[],s=new Map;let i=null;return{onAnchor:r=>{n.push(r),i||(i=st(t));const o=it(e,i);return i.add(o),o},setAnchors:()=>{for(const r of n){const o=s.get(r);if(typeof o=="object"&&o.anchor&&($(o.node)||A(o.node)))o.node.anchor=o.anchor;else{const l=new Error("Failed to resolve repeated object (this should not happen)");throw l.source=r,l}}},sourceObjects:s}}function Y(t,e,n,s){if(s&&typeof s=="object")if(Array.isArray(s))for(let i=0,r=s.length;i<r;++i){const o=s[i],l=Y(t,s,String(i),o);l===void 0?delete s[i]:l!==o&&(s[i]=l)}else if(s instanceof Map)for(const i of Array.from(s.keys())){const r=s.get(i),o=Y(t,s,i,r);o===void 0?s.delete(i):o!==r&&s.set(i,o)}else if(s instanceof Set)for(const i of Array.from(s)){const r=Y(t,s,i,i);r===void 0?s.delete(i):r!==i&&(s.delete(i),s.add(r))}else for(const[i,r]of Object.entries(s)){const o=Y(t,s,i,r);o===void 0?delete s[i]:o!==r&&(s[i]=o)}return t.call(e,n,s)}function k(t,e,n){if(Array.isArray(t))return t.map((s,i)=>k(s,String(i),n));if(t&&typeof t.toJSON=="function"){if(!n||!jt(t))return t.toJSON(e,n);const s={aliasCount:0,count:1,res:void 0};n.anchors.set(t,s),n.onCreate=r=>{s.res=r,delete n.onCreate};const i=t.toJSON(e,n);return n.onCreate&&n.onCreate(i),i}return typeof t=="bigint"&&!(n!=null&&n.keep)?Number(t):t}class Ce{constructor(e){Object.defineProperty(this,B,{value:e})}clone(){const e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:n,maxAliasCount:s,onAnchor:i,reviver:r}={}){if(!ye(e))throw new TypeError("A document argument is required");const o={anchors:new Map,doc:e,keep:!0,mapAsMap:n===!0,mapKeyWarned:!1,maxAliasCount:typeof s=="number"?s:100},l=k(this,"",o);if(typeof i=="function")for(const{count:f,res:a}of o.anchors.values())i(a,f);return typeof r=="function"?Y(r,{"":l},"",l):l}}class rt extends Ce{constructor(e){super(Me),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e){let n;return q(e,{Node:(s,i)=>{if(i===this)return q.BREAK;i.anchor===this.source&&(n=i)}}),n}toJSON(e,n){if(!n)return{source:this.source};const{anchors:s,doc:i,maxAliasCount:r}=n,o=this.resolve(i);if(!o){const f=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(f)}let l=s.get(o);if(l||(k(o,null,n),l=s.get(o)),!l||l.res===void 0){const f="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(f)}if(r>=0&&(l.count+=1,l.aliasCount===0&&(l.aliasCount=fe(i,o,s)),l.count*l.aliasCount>r)){const f="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(f)}return l.res}toString(e,n,s){const i=`*${this.source}`;if(e){if(nt(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){const r=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(r)}if(e.implicitKey)return`${i} `}return i}}function fe(t,e,n){if(H(e)){const s=e.resolve(t),i=n&&s&&n.get(s);return i?i.count*i.aliasCount:0}else if(A(e)){let s=0;for(const i of e.items){const r=fe(t,i,n);r>s&&(s=r)}return s}else if(I(e)){const s=fe(t,e.key,n),i=fe(t,e.value,n);return Math.max(s,i)}return 1}const ot=t=>!t||typeof t!="function"&&typeof t!="object";class w extends Ce{constructor(e){super(he),this.value=e}toJSON(e,n){return n!=null&&n.keep?this.value:k(this.value,e,n)}toString(){return String(this.value)}}w.BLOCK_FOLDED="BLOCK_FOLDED";w.BLOCK_LITERAL="BLOCK_LITERAL";w.PLAIN="PLAIN";w.QUOTE_DOUBLE="QUOTE_DOUBLE";w.QUOTE_SINGLE="QUOTE_SINGLE";const _t="tag:yaml.org,2002:";function Ft(t,e,n){if(e){const s=n.filter(r=>r.tag===e),i=s.find(r=>!r.format)??s[0];if(!i)throw new Error(`Tag ${e} not found`);return i}return n.find(s=>{var i;return((i=s.identify)==null?void 0:i.call(s,t))&&!s.format})}function ne(t,e,n){var u,d,c;if(ye(t)&&(t=t.contents),j(t))return t;if(I(t)){const p=(d=(u=n.schema[F]).createNode)==null?void 0:d.call(u,n.schema,null,n);return p.items.push(t),p}(t instanceof String||t instanceof Number||t instanceof Boolean||typeof BigInt<"u"&&t instanceof BigInt)&&(t=t.valueOf());const{aliasDuplicateObjects:s,onAnchor:i,onTagObj:r,schema:o,sourceObjects:l}=n;let f;if(s&&t&&typeof t=="object"){if(f=l.get(t),f)return f.anchor||(f.anchor=i(t)),new rt(f.anchor);f={anchor:null,node:null},l.set(t,f)}e!=null&&e.startsWith("!!")&&(e=_t+e.slice(2));let a=Ft(t,e,o.tags);if(!a){if(t&&typeof t.toJSON=="function"&&(t=t.toJSON()),!t||typeof t!="object"){const p=new w(t);return f&&(f.node=p),p}a=t instanceof Map?o[F]:Symbol.iterator in Object(t)?o[G]:o[F]}r&&(r(a),delete n.onTagObj);const y=a!=null&&a.createNode?a.createNode(n.schema,t,n):typeof((c=a==null?void 0:a.nodeClass)==null?void 0:c.from)=="function"?a.nodeClass.from(n.schema,t,n):new w(t);return e?y.tag=e:a.default||(y.tag=a.tag),f&&(f.node=y),y}function ue(t,e,n){let s=n;for(let i=e.length-1;i>=0;--i){const r=e[i];if(typeof r=="number"&&Number.isInteger(r)&&r>=0){const o=[];o[r]=s,s=o}else s=new Map([[r,s]])}return ne(s,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:t,sourceObjects:new Map})}const x=t=>t==null||typeof t=="object"&&!!t[Symbol.iterator]().next().done;class me extends Ce{constructor(e,n){super(e),Object.defineProperty(this,"schema",{value:n,configurable:!0,enumerable:!1,writable:!0})}clone(e){const n=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(n.schema=e),n.items=n.items.map(s=>j(s)||I(s)?s.clone(e):s),this.range&&(n.range=this.range.slice()),n}addIn(e,n){if(x(e))this.add(n);else{const[s,...i]=e,r=this.get(s,!0);if(A(r))r.addIn(i,n);else if(r===void 0&&this.schema)this.set(s,ue(this.schema,i,n));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${i}`)}}deleteIn(e){const[n,...s]=e;if(s.length===0)return this.delete(n);const i=this.get(n,!0);if(A(i))return i.deleteIn(s);throw new Error(`Expected YAML collection at ${n}. Remaining path: ${s}`)}getIn(e,n){const[s,...i]=e,r=this.get(s,!0);return i.length===0?!n&&$(r)?r.value:r:A(r)?r.getIn(i,n):void 0}hasAllNullValues(e){return this.items.every(n=>{if(!I(n))return!1;const s=n.value;return s==null||e&&$(s)&&s.value==null&&!s.commentBefore&&!s.comment&&!s.tag})}hasIn(e){const[n,...s]=e;if(s.length===0)return this.has(n);const i=this.get(n,!0);return A(i)?i.hasIn(s):!1}setIn(e,n){const[s,...i]=e;if(i.length===0)this.set(s,n);else{const r=this.get(s,!0);if(A(r))r.setIn(i,n);else if(r===void 0&&this.schema)this.set(s,ue(this.schema,i,n));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${i}`)}}}me.maxFlowStringSingleLineLength=60;const Dt=t=>t.replace(/^(?!$)(?: $)?/gm,"#");function C(t,e){return/^\n+$/.test(t)?t.substring(1):e?t.replace(/^(?! *$)/gm,e):t}const _=(t,e,n)=>t.endsWith(` | |
`)?C(n,e):n.includes(` | |
`)?` | |
`+C(n,e):(t.endsWith(" ")?"":" ")+n,lt="flow",ke="block",ae="quoted";function pe(t,e,n="flow",{indentAtStart:s,lineWidth:i=80,minContentWidth:r=20,onFold:o,onOverflow:l}={}){if(!i||i<0)return t;const f=Math.max(1+r,1+i-e.length);if(t.length<=f)return t;const a=[],y={};let u=i-e.length;typeof s=="number"&&(s>i-Math.max(2,r)?a.push(0):u=i-s);let d,c,p=!1,g=-1,h=-1,S=-1;n===ke&&(g=ze(t,g),g!==-1&&(u=g+f));for(let O;O=t[g+=1];){if(n===ae&&O==="\\"){switch(h=g,t[g+1]){case"x":g+=3;break;case"u":g+=5;break;case"U":g+=9;break;default:g+=1}S=g}if(O===` | |
`)n===ke&&(g=ze(t,g)),u=g+f,d=void 0;else{if(O===" "&&c&&c!==" "&&c!==` | |
`&&c!==" "){const b=t[g+1];b&&b!==" "&&b!==` | |
`&&b!==" "&&(d=g)}if(g>=u)if(d)a.push(d),u=d+f,d=void 0;else if(n===ae){for(;c===" "||c===" ";)c=O,O=t[g+=1],p=!0;const b=g>S+1?g-2:h-1;if(y[b])return t;a.push(b),y[b]=!0,u=b+f,d=void 0}else p=!0}c=O}if(p&&l&&l(),a.length===0)return t;o&&o();let m=t.slice(0,a[0]);for(let O=0;O<a.length;++O){const b=a[O],N=a[O+1]||t.length;b===0?m=` | |
${e}${t.slice(0,N)}`:(n===ae&&y[b]&&(m+=`${t[b]}\\`),m+=` | |
${e}${t.slice(b+1,N)}`)}return m}function ze(t,e){let n=t[e+1];for(;n===" "||n===" ";){do n=t[e+=1];while(n&&n!==` | |
`);n=t[e+1]}return e}const be=(t,e)=>({indentAtStart:e?t.indent.length:t.indentAtStart,lineWidth:t.options.lineWidth,minContentWidth:t.options.minContentWidth}),we=t=>/^(%|---|\.\.\.)/m.test(t);function Jt(t,e,n){if(!e||e<0)return!1;const s=e-n,i=t.length;if(i<=s)return!1;for(let r=0,o=0;r<i;++r)if(t[r]===` | |
`){if(r-o>s)return!0;if(o=r+1,i-o<=s)return!1}return!0}function te(t,e){const n=JSON.stringify(t);if(e.options.doubleQuotedAsJSON)return n;const{implicitKey:s}=e,i=e.options.doubleQuotedMinMultiLineLength,r=e.indent||(we(t)?" ":"");let o="",l=0;for(let f=0,a=n[f];a;a=n[++f])if(a===" "&&n[f+1]==="\\"&&n[f+2]==="n"&&(o+=n.slice(l,f)+"\\ ",f+=1,l=f,a="\\"),a==="\\")switch(n[f+1]){case"u":{o+=n.slice(l,f);const y=n.substr(f+2,4);switch(y){case"0000":o+="\\0";break;case"0007":o+="\\a";break;case"000b":o+="\\v";break;case"001b":o+="\\e";break;case"0085":o+="\\N";break;case"00a0":o+="\\_";break;case"2028":o+="\\L";break;case"2029":o+="\\P";break;default:y.substr(0,2)==="00"?o+="\\x"+y.substr(2):o+=n.substr(f,6)}f+=5,l=f+1}break;case"n":if(s||n[f+2]==='"'||n.length<i)f+=1;else{for(o+=n.slice(l,f)+` | |
`;n[f+2]==="\\"&&n[f+3]==="n"&&n[f+4]!=='"';)o+=` | |
`,f+=2;o+=r,n[f+2]===" "&&(o+="\\"),f+=1,l=f+1}break;default:f+=1}return o=l?o+n.slice(l):n,s?o:pe(o,r,ae,be(e,!1))}function Te(t,e){if(e.options.singleQuote===!1||e.implicitKey&&t.includes(` | |
`)||/[ \t]\n|\n[ \t]/.test(t))return te(t,e);const n=e.indent||(we(t)?" ":""),s="'"+t.replace(/'/g,"''").replace(/\n+/g,`$& | |
${n}`)+"'";return e.implicitKey?s:pe(s,n,lt,be(e,!1))}function Q(t,e){const{singleQuote:n}=e.options;let s;if(n===!1)s=te;else{const i=t.includes('"'),r=t.includes("'");i&&!r?s=Te:r&&!i?s=te:s=n?Te:te}return s(t,e)}let Be;try{Be=new RegExp(`(^|(?<! | |
)) | |
+(?! | |
|$)`,"g")}catch{Be=/\n+(?!\n|$)/g}function ce({comment:t,type:e,value:n},s,i,r){const{blockQuote:o,commentString:l,lineWidth:f}=s.options;if(!o||/\n[\t ]+$/.test(n)||/^\s*$/.test(n))return Q(n,s);const a=s.indent||(s.forceBlockIndent||we(n)?" ":""),y=o==="literal"?!0:o==="folded"||e===w.BLOCK_FOLDED?!1:e===w.BLOCK_LITERAL?!0:!Jt(n,f,a.length);if(!n)return y?`| | |
`:`> | |
`;let u,d;for(d=n.length;d>0;--d){const E=n[d-1];if(E!==` | |
`&&E!==" "&&E!==" ")break}let c=n.substring(d);const p=c.indexOf(` | |
`);p===-1?u="-":n===c||p!==c.length-1?(u="+",r&&r()):u="",c&&(n=n.slice(0,-c.length),c[c.length-1]===` | |
`&&(c=c.slice(0,-1)),c=c.replace(Be,`$&${a}`));let g=!1,h,S=-1;for(h=0;h<n.length;++h){const E=n[h];if(E===" ")g=!0;else if(E===` | |
`)S=h;else break}let m=n.substring(0,S<h?S+1:h);m&&(n=n.substring(m.length),m=m.replace(/\n+/g,`$&${a}`));let b=(y?"|":">")+(g?a?"2":"1":"")+u;if(t&&(b+=" "+l(t.replace(/ ?[\r\n]+/g," ")),i&&i()),y)return n=n.replace(/\n+/g,`$&${a}`),`${b} | |
${a}${m}${n}${c}`;n=n.replace(/\n+/g,` | |
$&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,"$1$2").replace(/\n+/g,`$&${a}`);const N=pe(`${m}${n}${c}`,a,ke,be(s,!0));return`${b} | |
${a}${N}`}function Kt(t,e,n,s){const{type:i,value:r}=t,{actualString:o,implicitKey:l,indent:f,indentStep:a,inFlow:y}=e;if(l&&r.includes(` | |
`)||y&&/[[\]{},]/.test(r))return Q(r,e);if(!r||/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(r))return l||y||!r.includes(` | |
`)?Q(r,e):ce(t,e,n,s);if(!l&&!y&&i!==w.PLAIN&&r.includes(` | |
`))return ce(t,e,n,s);if(we(r)){if(f==="")return e.forceBlockIndent=!0,ce(t,e,n,s);if(l&&f===a)return Q(r,e)}const u=r.replace(/\n+/g,`$& | |
${f}`);if(o){const d=g=>{var h;return g.default&&g.tag!=="tag:yaml.org,2002:str"&&((h=g.test)==null?void 0:h.test(u))},{compat:c,tags:p}=e.doc.schema;if(p.some(d)||c!=null&&c.some(d))return Q(r,e)}return l?u:pe(u,f,lt,be(e,!1))}function Pe(t,e,n,s){const{implicitKey:i,inFlow:r}=e,o=typeof t.value=="string"?t:Object.assign({},t,{value:String(t.value)});let{type:l}=t;l!==w.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(o.value)&&(l=w.QUOTE_DOUBLE);const f=y=>{switch(y){case w.BLOCK_FOLDED:case w.BLOCK_LITERAL:return i||r?Q(o.value,e):ce(o,e,n,s);case w.QUOTE_DOUBLE:return te(o.value,e);case w.QUOTE_SINGLE:return Te(o.value,e);case w.PLAIN:return Kt(o,e,n,s);default:return null}};let a=f(l);if(a===null){const{defaultKeyType:y,defaultStringType:u}=e.options,d=i&&y||u;if(a=f(d),a===null)throw new Error(`Unsupported default string type ${d}`)}return a}function ft(t,e){const n=Object.assign({blockQuote:!0,commentString:Dt,defaultKeyType:null,defaultStringType:"PLAIN",directives:null,doubleQuotedAsJSON:!1,doubleQuotedMinMultiLineLength:40,falseStr:"false",flowCollectionPadding:!0,indentSeq:!0,lineWidth:80,minContentWidth:20,nullStr:"null",simpleKeys:!1,singleQuote:null,trueStr:"true",verifyAliasOrder:!0},t.schema.toStringOptions,e);let s;switch(n.collectionStyle){case"block":s=!1;break;case"flow":s=!0;break;default:s=null}return{anchors:new Set,doc:t,flowCollectionPadding:n.flowCollectionPadding?" ":"",indent:"",indentStep:typeof n.indent=="number"?" ".repeat(n.indent):" ",inFlow:s,options:n}}function Ut(t,e){var i;if(e.tag){const r=t.filter(o=>o.tag===e.tag);if(r.length>0)return r.find(o=>o.format===e.format)??r[0]}let n,s;if($(e)){s=e.value;const r=t.filter(o=>{var l;return(l=o.identify)==null?void 0:l.call(o,s)});n=r.find(o=>o.format===e.format)??r.find(o=>!o.format)}else s=e,n=t.find(r=>r.nodeClass&&s instanceof r.nodeClass);if(!n){const r=((i=s==null?void 0:s.constructor)==null?void 0:i.name)??typeof s;throw new Error(`Tag not resolved for ${r} value`)}return n}function qt(t,e,{anchors:n,doc:s}){if(!s.directives)return"";const i=[],r=($(t)||A(t))&&t.anchor;r&&nt(r)&&(n.add(r),i.push(`&${r}`));const o=t.tag?t.tag:e.default?null:e.tag;return o&&i.push(s.directives.tagString(o)),i.join(" ")}function z(t,e,n,s){var f;if(I(t))return t.toString(e,n,s);if(H(t)){if(e.doc.directives)return t.toString(e);if((f=e.resolvedAliases)!=null&&f.has(t))throw new TypeError("Cannot stringify circular structure without alias nodes");e.resolvedAliases?e.resolvedAliases.add(t):e.resolvedAliases=new Set([t]),t=t.resolve(e.doc)}let i;const r=j(t)?t:e.doc.createNode(t,{onTagObj:a=>i=a});i||(i=Ut(e.doc.schema.tags,r));const o=qt(r,i,e);o.length>0&&(e.indentAtStart=(e.indentAtStart??0)+o.length+1);const l=typeof i.stringify=="function"?i.stringify(r,e,n,s):$(r)?Pe(r,e,n,s):r.toString(e,n,s);return o?$(r)||l[0]==="{"||l[0]==="["?`${o} ${l}`:`${o} | |
${e.indent}${l}`:l}function Rt({key:t,value:e},n,s,i){const{allNullValues:r,doc:o,indent:l,indentStep:f,options:{commentString:a,indentSeq:y,simpleKeys:u}}=n;let d=j(t)&&t.comment||null;if(u){if(d)throw new Error("With simple keys, key nodes cannot have comments");if(A(t)){const D="With simple keys, collection cannot be used as a key value";throw new Error(D)}}let c=!u&&(!t||d&&e==null&&!n.inFlow||A(t)||($(t)?t.type===w.BLOCK_FOLDED||t.type===w.BLOCK_LITERAL:typeof t=="object"));n=Object.assign({},n,{allNullValues:!1,implicitKey:!c&&(u||!r),indent:l+f});let p=!1,g=!1,h=z(t,n,()=>p=!0,()=>g=!0);if(!c&&!n.inFlow&&h.length>1024){if(u)throw new Error("With simple keys, single line scalar must not span more than 1024 characters");c=!0}if(n.inFlow){if(r||e==null)return p&&s&&s(),h===""?"?":c?`? ${h}`:h}else if(r&&!u||e==null&&c)return h=`? ${h}`,d&&!p?h+=_(h,n.indent,a(d)):g&&i&&i(),h;p&&(d=null),c?(d&&(h+=_(h,n.indent,a(d))),h=`? ${h} | |
${l}:`):(h=`${h}:`,d&&(h+=_(h,n.indent,a(d))));let S,m,O;j(e)?(S=!!e.spaceBefore,m=e.commentBefore,O=e.comment):(S=!1,m=null,O=null,e&&typeof e=="object"&&(e=o.createNode(e))),n.implicitKey=!1,!c&&!d&&$(e)&&(n.indentAtStart=h.length+1),g=!1,!y&&f.length>=2&&!n.inFlow&&!c&&ie(e)&&!e.flow&&!e.tag&&!e.anchor&&(n.indent=n.indent.substring(2));let b=!1;const N=z(e,n,()=>b=!0,()=>g=!0);let E=" ";if(d||S||m){if(E=S?` | |
`:"",m){const D=a(m);E+=` | |
${C(D,n.indent)}`}N===""&&!n.inFlow?E===` | |
`&&(E=` | |
`):E+=` | |
${n.indent}`}else if(!c&&A(e)){const D=N[0],Ae=N.indexOf(` | |
`),We=Ae!==-1,It=n.inFlow??e.flow??e.items.length===0;if(We||!It){let ve=!1;if(We&&(D==="&"||D==="!")){let J=N.indexOf(" ");D==="&"&&J!==-1&&J<Ae&&N[J+1]==="!"&&(J=N.indexOf(" ",J+1)),(J===-1||Ae<J)&&(ve=!0)}ve||(E=` | |
${n.indent}`)}}else(N===""||N[0]===` | |
`)&&(E="");return h+=E+N,n.inFlow?b&&s&&s():O&&!b?h+=_(h,n.indent,a(O)):g&&i&&i(),h}function Vt(t,e){(t==="debug"||t==="warn")&&(typeof process<"u"&&process.emitWarning?process.emitWarning(e):console.warn(e))}const Ge="<<";function at(t,e,{key:n,value:s}){if(t!=null&&t.doc.schema.merge&&Yt(n))if(s=H(s)?s.resolve(t.doc):s,ie(s))for(const i of s.items)Ie(t,e,i);else if(Array.isArray(s))for(const i of s)Ie(t,e,i);else Ie(t,e,s);else{const i=k(n,"",t);if(e instanceof Map)e.set(i,k(s,i,t));else if(e instanceof Set)e.add(i);else{const r=Qt(n,i,t),o=k(s,r,t);r in e?Object.defineProperty(e,r,{value:o,writable:!0,enumerable:!0,configurable:!0}):e[r]=o}}return e}const Yt=t=>t===Ge||$(t)&&t.value===Ge&&(!t.type||t.type===w.PLAIN);function Ie(t,e,n){const s=t&&H(n)?n.resolve(t.doc):n;if(!se(s))throw new Error("Merge sources must be maps or map aliases");const i=s.toJSON(null,t,Map);for(const[r,o]of i)e instanceof Map?e.has(r)||e.set(r,o):e instanceof Set?e.add(r):Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{value:o,writable:!0,enumerable:!0,configurable:!0});return e}function Qt(t,e,n){if(e===null)return"";if(typeof e!="object")return String(e);if(j(t)&&(n!=null&&n.doc)){const s=ft(n.doc,{});s.anchors=new Set;for(const r of n.anchors.keys())s.anchors.add(r.anchor);s.inFlow=!0,s.inStringifyKey=!0;const i=t.toString(s);if(!n.mapKeyWarned){let r=JSON.stringify(i);r.length>40&&(r=r.substring(0,36)+'..."'),Vt(n.doc.options.logLevel,`Keys with collection values will be stringified due to JS Object restrictions: ${r}. Set mapAsMap: true to use object keys.`),n.mapKeyWarned=!0}return i}return JSON.stringify(e)}function _e(t,e,n){const s=ne(t,void 0,n),i=ne(e,void 0,n);return new T(s,i)}class T{constructor(e,n=null){Object.defineProperty(this,B,{value:tt}),this.key=e,this.value=n}clone(e){let{key:n,value:s}=this;return j(n)&&(n=n.clone(e)),j(s)&&(s=s.clone(e)),new T(n,s)}toJSON(e,n){const s=n!=null&&n.mapAsMap?new Map:{};return at(n,s,this)}toString(e,n,s){return e!=null&&e.doc?Rt(this,e,n,s):JSON.stringify(this)}}function ct(t,e,n){return(e.inFlow??t.flow?vt:Wt)(t,e,n)}function Wt({comment:t,items:e},n,{blockItemPrefix:s,flowChars:i,itemIndent:r,onChompKeep:o,onComment:l}){const{indent:f,options:{commentString:a}}=n,y=Object.assign({},n,{indent:r,type:null});let u=!1;const d=[];for(let p=0;p<e.length;++p){const g=e[p];let h=null;if(j(g))!u&&g.spaceBefore&&d.push(""),ge(n,d,g.commentBefore,u),g.comment&&(h=g.comment);else if(I(g)){const m=j(g.key)?g.key:null;m&&(!u&&m.spaceBefore&&d.push(""),ge(n,d,m.commentBefore,u))}u=!1;let S=z(g,y,()=>h=null,()=>u=!0);h&&(S+=_(S,r,a(h))),u&&h&&(u=!1),d.push(s+S)}let c;if(d.length===0)c=i.start+i.end;else{c=d[0];for(let p=1;p<d.length;++p){const g=d[p];c+=g?` | |
${f}${g}`:` | |
`}}return t?(c+=` | |
`+C(a(t),f),l&&l()):u&&o&&o(),c}function vt({comment:t,items:e},n,{flowChars:s,itemIndent:i,onComment:r}){const{indent:o,indentStep:l,flowCollectionPadding:f,options:{commentString:a}}=n;i+=l;const y=Object.assign({},n,{indent:i,inFlow:!0,type:null});let u=!1,d=0;const c=[];for(let S=0;S<e.length;++S){const m=e[S];let O=null;if(j(m))m.spaceBefore&&c.push(""),ge(n,c,m.commentBefore,!1),m.comment&&(O=m.comment);else if(I(m)){const N=j(m.key)?m.key:null;N&&(N.spaceBefore&&c.push(""),ge(n,c,N.commentBefore,!1),N.comment&&(u=!0));const E=j(m.value)?m.value:null;E?(E.comment&&(O=E.comment),E.commentBefore&&(u=!0)):m.value==null&&(N!=null&&N.comment)&&(O=N.comment)}O&&(u=!0);let b=z(m,y,()=>O=null);S<e.length-1&&(b+=","),O&&(b+=_(b,i,a(O))),!u&&(c.length>d||b.includes(` | |
`))&&(u=!0),c.push(b),d=c.length}let p;const{start:g,end:h}=s;if(c.length===0)p=g+h;else if(u||(u=c.reduce((m,O)=>m+O.length+2,2)>me.maxFlowStringSingleLineLength),u){p=g;for(const S of c)p+=S?` | |
${l}${o}${S}`:` | |
`;p+=` | |
${o}${h}`}else p=`${g}${f}${c.join(" ")}${f}${h}`;return t&&(p+=_(p,o,a(t)),r&&r()),p}function ge({indent:t,options:{commentString:e}},n,s,i){if(s&&i&&(s=s.replace(/^\n+/,"")),s){const r=C(e(s),t);n.push(r.trimStart())}}function U(t,e){const n=$(e)?e.value:e;for(const s of t)if(I(s)&&(s.key===e||s.key===n||$(s.key)&&s.key.value===n))return s}class P extends me{static get tagName(){return"tag:yaml.org,2002:map"}constructor(e){super(F,e),this.items=[]}static from(e,n,s){const{keepUndefined:i,replacer:r}=s,o=new this(e),l=(f,a)=>{if(typeof r=="function")a=r.call(n,f,a);else if(Array.isArray(r)&&!r.includes(f))return;(a!==void 0||i)&&o.items.push(_e(f,a,s))};if(n instanceof Map)for(const[f,a]of n)l(f,a);else if(n&&typeof n=="object")for(const f of Object.keys(n))l(f,n[f]);return typeof e.sortMapEntries=="function"&&o.items.sort(e.sortMapEntries),o}add(e,n){var o;let s;I(e)?s=e:!e||typeof e!="object"||!("key"in e)?s=new T(e,e==null?void 0:e.value):s=new T(e.key,e.value);const i=U(this.items,s.key),r=(o=this.schema)==null?void 0:o.sortMapEntries;if(i){if(!n)throw new Error(`Key ${s.key} already set`);$(i.value)&&ot(s.value)?i.value.value=s.value:i.value=s.value}else if(r){const l=this.items.findIndex(f=>r(s,f)<0);l===-1?this.items.push(s):this.items.splice(l,0,s)}else this.items.push(s)}delete(e){const n=U(this.items,e);return n?this.items.splice(this.items.indexOf(n),1).length>0:!1}get(e,n){const s=U(this.items,e),i=s==null?void 0:s.value;return(!n&&$(i)?i.value:i)??void 0}has(e){return!!U(this.items,e)}set(e,n){this.add(new T(e,n),!0)}toJSON(e,n,s){const i=s?new s:n!=null&&n.mapAsMap?new Map:{};n!=null&&n.onCreate&&n.onCreate(i);for(const r of this.items)at(n,i,r);return i}toString(e,n,s){if(!e)return JSON.stringify(this);for(const i of this.items)if(!I(i))throw new Error(`Map items must all be pairs; found ${JSON.stringify(i)} instead`);return!e.allNullValues&&this.hasAllNullValues(!1)&&(e=Object.assign({},e,{allNullValues:!0})),ct(this,e,{blockItemPrefix:"",flowChars:{start:"{",end:"}"},itemIndent:e.indent||"",onChompKeep:s,onComment:n})}}const X={collection:"map",default:!0,nodeClass:P,tag:"tag:yaml.org,2002:map",resolve(t,e){return se(t)||e("Expected a mapping for this tag"),t},createNode:(t,e,n)=>P.from(t,e,n)};class de extends me{static get tagName(){return"tag:yaml.org,2002:seq"}constructor(e){super(G,e),this.items=[]}add(e){this.items.push(e)}delete(e){const n=oe(e);return typeof n!="number"?!1:this.items.splice(n,1).length>0}get(e,n){const s=oe(e);if(typeof s!="number")return;const i=this.items[s];return!n&&$(i)?i.value:i}has(e){const n=oe(e);return typeof n=="number"&&n<this.items.length}set(e,n){const s=oe(e);if(typeof s!="number")throw new Error(`Expected a valid index, not ${e}.`);const i=this.items[s];$(i)&&ot(n)?i.value=n:this.items[s]=n}toJSON(e,n){const s=[];n!=null&&n.onCreate&&n.onCreate(s);let i=0;for(const r of this.items)s.push(k(r,String(i++),n));return s}toString(e,n,s){return e?ct(this,e,{blockItemPrefix:"- ",flowChars:{start:"[",end:"]"},itemIndent:(e.indent||"")+" ",onChompKeep:s,onComment:n}):JSON.stringify(this)}static from(e,n,s){const{replacer:i}=s,r=new this(e);if(n&&Symbol.iterator in Object(n)){let o=0;for(let l of n){if(typeof i=="function"){const f=n instanceof Set?l:String(o++);l=i.call(n,f,l)}r.items.push(ne(l,void 0,s))}}return r}}function oe(t){let e=$(t)?t.value:t;return e&&typeof e=="string"&&(e=Number(e)),typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null}const Z={collection:"seq",default:!0,nodeClass:de,tag:"tag:yaml.org,2002:seq",resolve(t,e){return ie(t)||e("Expected a sequence for this tag"),t},createNode:(t,e,n)=>de.from(t,e,n)},Se={identify:t=>typeof t=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:t=>t,stringify(t,e,n,s){return e=Object.assign({actualString:!0},e),Pe(t,e,n,s)}},Oe={identify:t=>t==null,createNode:()=>new w(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new w(null),stringify:({source:t},e)=>typeof t=="string"&&Oe.test.test(t)?t:e.options.nullStr},Fe={identify:t=>typeof t=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:t=>new w(t[0]==="t"||t[0]==="T"),stringify({source:t,value:e},n){if(t&&Fe.test.test(t)){const s=t[0]==="t"||t[0]==="T";if(e===s)return t}return e?n.options.trueStr:n.options.falseStr}};function M({format:t,minFractionDigits:e,tag:n,value:s}){if(typeof s=="bigint")return String(s);const i=typeof s=="number"?s:Number(s);if(!isFinite(i))return isNaN(i)?".nan":i<0?"-.inf":".inf";let r=JSON.stringify(s);if(!t&&e&&(!n||n==="tag:yaml.org,2002:float")&&/^\d/.test(r)){let o=r.indexOf(".");o<0&&(o=r.length,r+=".");let l=e-(r.length-o-1);for(;l-- >0;)r+="0"}return r}const ut={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,resolve:t=>t.slice(-3).toLowerCase()==="nan"?NaN:t[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:M},gt={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,resolve:t=>parseFloat(t),stringify(t){const e=Number(t.value);return isFinite(e)?e.toExponential():M(t)}},dt={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,resolve(t){const e=new w(parseFloat(t)),n=t.indexOf(".");return n!==-1&&t[t.length-1]==="0"&&(e.minFractionDigits=t.length-n-1),e},stringify:M},Ne=t=>typeof t=="bigint"||Number.isInteger(t),De=(t,e,n,{intAsBigInt:s})=>s?BigInt(t):parseInt(t.substring(e),n);function ht(t,e,n){const{value:s}=t;return Ne(s)&&s>=0?n+s.toString(e):M(t)}const yt={identify:t=>Ne(t)&&t>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o[0-7]+$/,resolve:(t,e,n)=>De(t,2,8,n),stringify:t=>ht(t,8,"0o")},mt={identify:Ne,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:(t,e,n)=>De(t,0,10,n),stringify:M},pt={identify:t=>Ne(t)&&t>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x[0-9a-fA-F]+$/,resolve:(t,e,n)=>De(t,2,16,n),stringify:t=>ht(t,16,"0x")},zt=[X,Z,Se,Oe,Fe,yt,mt,pt,ut,gt,dt];function He(t){return typeof t=="bigint"||Number.isInteger(t)}const le=({value:t})=>JSON.stringify(t),Gt=[{identify:t=>typeof t=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:t=>t,stringify:le},{identify:t=>t==null,createNode:()=>new w(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^null$/,resolve:()=>null,stringify:le},{identify:t=>typeof t=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^true|false$/,resolve:t=>t==="true",stringify:le},{identify:He,default:!0,tag:"tag:yaml.org,2002:int",test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(t,e,{intAsBigInt:n})=>n?BigInt(t):parseInt(t,10),stringify:({value:t})=>He(t)?t.toString():JSON.stringify(t)},{identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:t=>parseFloat(t),stringify:le}],Ht={default:!0,tag:"",test:/^/,resolve(t,e){return e(`Unresolved plain scalar ${JSON.stringify(t)}`),t}},Xt=[X,Z].concat(Gt,Ht),Je={identify:t=>t instanceof Uint8Array,default:!1,tag:"tag:yaml.org,2002:binary",resolve(t,e){if(typeof Buffer=="function")return Buffer.from(t,"base64");if(typeof atob=="function"){const n=atob(t.replace(/[\n\r]/g,"")),s=new Uint8Array(n.length);for(let i=0;i<n.length;++i)s[i]=n.charCodeAt(i);return s}else return e("This environment does not support reading binary tags; either Buffer or atob is required"),t},stringify({comment:t,type:e,value:n},s,i,r){const o=n;let l;if(typeof Buffer=="function")l=o instanceof Buffer?o.toString("base64"):Buffer.from(o.buffer).toString("base64");else if(typeof btoa=="function"){let f="";for(let a=0;a<o.length;++a)f+=String.fromCharCode(o[a]);l=btoa(f)}else throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");if(e||(e=w.BLOCK_LITERAL),e!==w.QUOTE_DOUBLE){const f=Math.max(s.options.lineWidth-s.indent.length,s.options.minContentWidth),a=Math.ceil(l.length/f),y=new Array(a);for(let u=0,d=0;u<a;++u,d+=f)y[u]=l.substr(d,f);l=y.join(e===w.BLOCK_LITERAL?` | |
`:" ")}return Pe({comment:t,type:e,value:l},s,i,r)}};function bt(t,e){if(ie(t))for(let n=0;n<t.items.length;++n){let s=t.items[n];if(!I(s)){if(se(s)){s.items.length>1&&e("Each pair must have its own sequence indicator");const i=s.items[0]||new T(new w(null));if(s.commentBefore&&(i.key.commentBefore=i.key.commentBefore?`${s.commentBefore} | |
${i.key.commentBefore}`:s.commentBefore),s.comment){const r=i.value??i.key;r.comment=r.comment?`${s.comment} | |
${r.comment}`:s.comment}s=i}t.items[n]=I(s)?s:new T(s)}}else e("Expected a sequence for this tag");return t}function wt(t,e,n){const{replacer:s}=n,i=new de(t);i.tag="tag:yaml.org,2002:pairs";let r=0;if(e&&Symbol.iterator in Object(e))for(let o of e){typeof s=="function"&&(o=s.call(e,String(r++),o));let l,f;if(Array.isArray(o))if(o.length===2)l=o[0],f=o[1];else throw new TypeError(`Expected [key, value] tuple: ${o}`);else if(o&&o instanceof Object){const a=Object.keys(o);if(a.length===1)l=a[0],f=o[l];else throw new TypeError(`Expected tuple with one key, not ${a.length} keys`)}else l=o;i.items.push(_e(l,f,n))}return i}const Ke={collection:"seq",default:!1,tag:"tag:yaml.org,2002:pairs",resolve:bt,createNode:wt};class W extends de{constructor(){super(),this.add=P.prototype.add.bind(this),this.delete=P.prototype.delete.bind(this),this.get=P.prototype.get.bind(this),this.has=P.prototype.has.bind(this),this.set=P.prototype.set.bind(this),this.tag=W.tag}toJSON(e,n){if(!n)return super.toJSON(e);const s=new Map;n!=null&&n.onCreate&&n.onCreate(s);for(const i of this.items){let r,o;if(I(i)?(r=k(i.key,"",n),o=k(i.value,r,n)):r=k(i,"",n),s.has(r))throw new Error("Ordered maps must not include duplicate keys");s.set(r,o)}return s}static from(e,n,s){const i=wt(e,n,s),r=new this;return r.items=i.items,r}}W.tag="tag:yaml.org,2002:omap";const Ue={collection:"seq",identify:t=>t instanceof Map,nodeClass:W,default:!1,tag:"tag:yaml.org,2002:omap",resolve(t,e){const n=bt(t,e),s=[];for(const{key:i}of n.items)$(i)&&(s.includes(i.value)?e(`Ordered maps must not include duplicate keys: ${i.value}`):s.push(i.value));return Object.assign(new W,n)},createNode:(t,e,n)=>W.from(t,e,n)};function St({value:t,source:e},n){return e&&(t?Ot:Nt).test.test(e)?e:t?n.options.trueStr:n.options.falseStr}const Ot={identify:t=>t===!0,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new w(!0),stringify:St},Nt={identify:t=>t===!1,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,resolve:()=>new w(!1),stringify:St},Zt={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/,resolve:t=>t.slice(-3).toLowerCase()==="nan"?NaN:t[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:M},xt={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:t=>parseFloat(t.replace(/_/g,"")),stringify(t){const e=Number(t.value);return isFinite(e)?e.toExponential():M(t)}},en={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(t){const e=new w(parseFloat(t.replace(/_/g,""))),n=t.indexOf(".");if(n!==-1){const s=t.substring(n+1).replace(/_/g,"");s[s.length-1]==="0"&&(e.minFractionDigits=s.length)}return e},stringify:M},re=t=>typeof t=="bigint"||Number.isInteger(t);function $e(t,e,n,{intAsBigInt:s}){const i=t[0];if((i==="-"||i==="+")&&(e+=1),t=t.substring(e).replace(/_/g,""),s){switch(n){case 2:t=`0b${t}`;break;case 8:t=`0o${t}`;break;case 16:t=`0x${t}`;break}const o=BigInt(t);return i==="-"?BigInt(-1)*o:o}const r=parseInt(t,n);return i==="-"?-1*r:r}function qe(t,e,n){const{value:s}=t;if(re(s)){const i=s.toString(e);return s<0?"-"+n+i.substr(1):n+i}return M(t)}const tn={identify:re,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^[-+]?0b[0-1_]+$/,resolve:(t,e,n)=>$e(t,2,2,n),stringify:t=>qe(t,2,"0b")},nn={identify:re,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^[-+]?0[0-7_]+$/,resolve:(t,e,n)=>$e(t,1,8,n),stringify:t=>qe(t,8,"0")},sn={identify:re,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9][0-9_]*$/,resolve:(t,e,n)=>$e(t,0,10,n),stringify:M},rn={identify:re,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(t,e,n)=>$e(t,2,16,n),stringify:t=>qe(t,16,"0x")};class v extends P{constructor(e){super(e),this.tag=v.tag}add(e){let n;I(e)?n=e:e&&typeof e=="object"&&"key"in e&&"value"in e&&e.value===null?n=new T(e.key,null):n=new T(e,null),U(this.items,n.key)||this.items.push(n)}get(e,n){const s=U(this.items,e);return!n&&I(s)?$(s.key)?s.key.value:s.key:s}set(e,n){if(typeof n!="boolean")throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof n}`);const s=U(this.items,e);s&&!n?this.items.splice(this.items.indexOf(s),1):!s&&n&&this.items.push(new T(e))}toJSON(e,n){return super.toJSON(e,n,Set)}toString(e,n,s){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),n,s);throw new Error("Set items must all have null values")}static from(e,n,s){const{replacer:i}=s,r=new this(e);if(n&&Symbol.iterator in Object(n))for(let o of n)typeof i=="function"&&(o=i.call(n,o,o)),r.items.push(_e(o,null,s));return r}}v.tag="tag:yaml.org,2002:set";const Re={collection:"map",identify:t=>t instanceof Set,nodeClass:v,default:!1,tag:"tag:yaml.org,2002:set",createNode:(t,e,n)=>v.from(t,e,n),resolve(t,e){if(se(t)){if(t.hasAllNullValues(!0))return Object.assign(new v,t);e("Set items must all have null values")}else e("Expected a mapping for this tag");return t}};function Ve(t,e){const n=t[0],s=n==="-"||n==="+"?t.substring(1):t,i=o=>e?BigInt(o):Number(o),r=s.replace(/_/g,"").split(":").reduce((o,l)=>o*i(60)+i(l),i(0));return n==="-"?i(-1)*r:r}function $t(t){let{value:e}=t,n=o=>o;if(typeof e=="bigint")n=o=>BigInt(o);else if(isNaN(e)||!isFinite(e))return M(t);let s="";e<0&&(s="-",e*=n(-1));const i=n(60),r=[e%i];return e<60?r.unshift(0):(e=(e-r[0])/i,r.unshift(e%i),e>=60&&(e=(e-r[0])/i,r.unshift(e))),s+r.map(o=>String(o).padStart(2,"0")).join(":").replace(/000000\d*$/,"")}const Et={identify:t=>typeof t=="bigint"||Number.isInteger(t),default:!0,tag:"tag:yaml.org,2002:int",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(t,e,{intAsBigInt:n})=>Ve(t,n),stringify:$t},At={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:t=>Ve(t,!1),stringify:$t},Ee={identify:t=>t instanceof Date,default:!0,tag:"tag:yaml.org,2002:timestamp",test:RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),resolve(t){const e=t.match(Ee.test);if(!e)throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");const[,n,s,i,r,o,l]=e.map(Number),f=e[7]?Number((e[7]+"00").substr(1,3)):0;let a=Date.UTC(n,s-1,i,r||0,o||0,l||0,f);const y=e[8];if(y&&y!=="Z"){let u=Ve(y,!1);Math.abs(u)<30&&(u*=60),a-=6e4*u}return new Date(a)},stringify:({value:t})=>t.toISOString().replace(/((T00:00)?:00)?\.000Z$/,"")},Xe=[X,Z,Se,Oe,Ot,Nt,tn,nn,sn,rn,Zt,xt,en,Je,Ue,Ke,Re,Et,At,Ee],Ze=new Map([["core",zt],["failsafe",[X,Z,Se]],["json",Xt],["yaml11",Xe],["yaml-1.1",Xe]]),xe={binary:Je,bool:Fe,float:dt,floatExp:gt,floatNaN:ut,floatTime:At,int:mt,intHex:pt,intOct:yt,intTime:Et,map:X,null:Oe,omap:Ue,pairs:Ke,seq:Z,set:Re,timestamp:Ee},on={"tag:yaml.org,2002:binary":Je,"tag:yaml.org,2002:omap":Ue,"tag:yaml.org,2002:pairs":Ke,"tag:yaml.org,2002:set":Re,"tag:yaml.org,2002:timestamp":Ee};function je(t,e){let n=Ze.get(e);if(!n)if(Array.isArray(t))n=[];else{const s=Array.from(Ze.keys()).filter(i=>i!=="yaml11").map(i=>JSON.stringify(i)).join(", ");throw new Error(`Unknown schema "${e}"; use one of ${s} or define customTags array`)}if(Array.isArray(t))for(const s of t)n=n.concat(s);else typeof t=="function"&&(n=t(n.slice()));return n.map(s=>{if(typeof s!="string")return s;const i=xe[s];if(i)return i;const r=Object.keys(xe).map(o=>JSON.stringify(o)).join(", ");throw new Error(`Unknown custom tag "${s}"; use one of ${r}`)})}const ln=(t,e)=>t.key<e.key?-1:t.key>e.key?1:0;class Ye{constructor({compat:e,customTags:n,merge:s,resolveKnownTags:i,schema:r,sortMapEntries:o,toStringDefaults:l}){this.compat=Array.isArray(e)?je(e,"compat"):e?je(null,e):null,this.merge=!!s,this.name=typeof r=="string"&&r||"core",this.knownTags=i?on:{},this.tags=je(n,this.name),this.toStringOptions=l??null,Object.defineProperty(this,F,{value:X}),Object.defineProperty(this,he,{value:Se}),Object.defineProperty(this,G,{value:Z}),this.sortMapEntries=typeof o=="function"?o:o===!0?ln:null}clone(){const e=Object.create(Ye.prototype,Object.getOwnPropertyDescriptors(this));return e.tags=this.tags.slice(),e}}function fn(t,e){var f;const n=[];let s=e.directives===!0;if(e.directives!==!1&&t.directives){const a=t.directives.toString(t);a?(n.push(a),s=!0):t.directives.docStart&&(s=!0)}s&&n.push("---");const i=ft(t,e),{commentString:r}=i.options;if(t.commentBefore){n.length!==1&&n.unshift("");const a=r(t.commentBefore);n.unshift(C(a,""))}let o=!1,l=null;if(t.contents){if(j(t.contents)){if(t.contents.spaceBefore&&s&&n.push(""),t.contents.commentBefore){const u=r(t.contents.commentBefore);n.push(C(u,""))}i.forceBlockIndent=!!t.comment,l=t.contents.comment}const a=l?void 0:()=>o=!0;let y=z(t.contents,i,()=>l=null,a);l&&(y+=_(y,"",r(l))),(y[0]==="|"||y[0]===">")&&n[n.length-1]==="---"?n[n.length-1]=`--- ${y}`:n.push(y)}else n.push(z(t.contents,i));if((f=t.directives)!=null&&f.docEnd)if(t.comment){const a=r(t.comment);a.includes(` | |
`)?(n.push("..."),n.push(C(a,""))):n.push(`... ${a}`)}else n.push("...");else{let a=t.comment;a&&o&&(a=a.replace(/^\n+/,"")),a&&((!o||l)&&n[n.length-1]!==""&&n.push(""),n.push(C(r(a),"")))}return n.join(` | |
`)+` | |
`}class Qe{constructor(e,n,s){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,B,{value:Le});let i=null;typeof n=="function"||Array.isArray(n)?i=n:s===void 0&&n&&(s=n,n=void 0);const r=Object.assign({intAsBigInt:!1,keepSourceTokens:!1,logLevel:"warn",prettyErrors:!0,strict:!0,uniqueKeys:!0,version:"1.2"},s);this.options=r;let{version:o}=r;s!=null&&s._directives?(this.directives=s._directives.atDocument(),this.directives.yaml.explicit&&(o=this.directives.yaml.version)):this.directives=new L({version:o}),this.setSchema(o,s),this.contents=e===void 0?null:this.createNode(e,i,s)}clone(){const e=Object.create(Qe.prototype,{[B]:{value:Le}});return e.commentBefore=this.commentBefore,e.comment=this.comment,e.errors=this.errors.slice(),e.warnings=this.warnings.slice(),e.options=Object.assign({},this.options),this.directives&&(e.directives=this.directives.clone()),e.schema=this.schema.clone(),e.contents=j(this.contents)?this.contents.clone(e.schema):this.contents,this.range&&(e.range=this.range.slice()),e}add(e){R(this.contents)&&this.contents.add(e)}addIn(e,n){R(this.contents)&&this.contents.addIn(e,n)}createAlias(e,n){if(!e.anchor){const s=st(this);e.anchor=!n||s.has(n)?it(n||"a",s):n}return new rt(e.anchor)}createNode(e,n,s){let i;if(typeof n=="function")e=n.call({"":e},"",e),i=n;else if(Array.isArray(n)){const h=m=>typeof m=="number"||m instanceof String||m instanceof Number,S=n.filter(h).map(String);S.length>0&&(n=n.concat(S)),i=n}else s===void 0&&n&&(s=n,n=void 0);const{aliasDuplicateObjects:r,anchorPrefix:o,flow:l,keepUndefined:f,onTagObj:a,tag:y}=s??{},{onAnchor:u,setAnchors:d,sourceObjects:c}=Pt(this,o||"a"),p={aliasDuplicateObjects:r??!0,keepUndefined:f??!1,onAnchor:u,onTagObj:a,replacer:i,schema:this.schema,sourceObjects:c},g=ne(e,y,p);return l&&A(g)&&(g.flow=!0),d(),g}createPair(e,n,s={}){const i=this.createNode(e,null,s),r=this.createNode(n,null,s);return new T(i,r)}delete(e){return R(this.contents)?this.contents.delete(e):!1}deleteIn(e){return x(e)?this.contents==null?!1:(this.contents=null,!0):R(this.contents)?this.contents.deleteIn(e):!1}get(e,n){return A(this.contents)?this.contents.get(e,n):void 0}getIn(e,n){return x(e)?!n&&$(this.contents)?this.contents.value:this.contents:A(this.contents)?this.contents.getIn(e,n):void 0}has(e){return A(this.contents)?this.contents.has(e):!1}hasIn(e){return x(e)?this.contents!==void 0:A(this.contents)?this.contents.hasIn(e):!1}set(e,n){this.contents==null?this.contents=ue(this.schema,[e],n):R(this.contents)&&this.contents.set(e,n)}setIn(e,n){x(e)?this.contents=n:this.contents==null?this.contents=ue(this.schema,Array.from(e),n):R(this.contents)&&this.contents.setIn(e,n)}setSchema(e,n={}){typeof e=="number"&&(e=String(e));let s;switch(e){case"1.1":this.directives?this.directives.yaml.version="1.1":this.directives=new L({version:"1.1"}),s={merge:!0,resolveKnownTags:!1,schema:"yaml-1.1"};break;case"1.2":case"next":this.directives?this.directives.yaml.version=e:this.directives=new L({version:e}),s={merge:!1,resolveKnownTags:!0,schema:"core"};break;case null:this.directives&&delete this.directives,s=null;break;default:{const i=JSON.stringify(e);throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${i}`)}}if(n.schema instanceof Object)this.schema=n.schema;else if(s)this.schema=new Ye(Object.assign(s,n));else throw new Error("With a null YAML version, the { schema: Schema } option is required")}toJS({json:e,jsonArg:n,mapAsMap:s,maxAliasCount:i,onAnchor:r,reviver:o}={}){const l={anchors:new Map,doc:this,keep:!e,mapAsMap:s===!0,mapKeyWarned:!1,maxAliasCount:typeof i=="number"?i:100},f=k(this.contents,n??"",l);if(typeof r=="function")for(const{count:a,res:y}of l.anchors.values())r(y,a);return typeof o=="function"?Y(o,{"":f},"",f):f}toJSON(e,n){return this.toJS({json:!0,jsonArg:e,mapAsMap:!1,onAnchor:n})}toString(e={}){if(this.errors.length>0)throw new Error("Document with errors cannot be stringified");if("indent"in e&&(!Number.isInteger(e.indent)||Number(e.indent)<=0)){const n=JSON.stringify(e.indent);throw new Error(`"indent" option must be a positive integer, not ${n}`)}return fn(this,e)}}function R(t){if(A(t))return!0;throw new Error("Expected a YAML collection as document contents")}function an(t,e,n){let s=null;if(typeof e=="function"||Array.isArray(e)?s=e:n===void 0&&e&&(n=e),typeof n=="string"&&(n=n.length),typeof n=="number"){const i=Math.round(n);n=i<1?void 0:i>8?{indent:8}:{indent:i}}if(t===void 0){const{keepUndefined:i}=n??e??{};if(!i)return}return new Qe(t,s,n).toString(n)}function cn(t){const e=[];for(const n of t.querySelectorAll("a")){const i=n.innerText.split(" (",2);e.push(i[0])}return e}function un(){var p,g;const t=document.querySelector("#gallery");if(!t){alert("No gallery found");return}const e=t.querySelector("aside");if(!e){alert("No aside found");return}const n=e.querySelector("#metadata"),s=(p=n==null?void 0:n.querySelector("header > h2"))==null?void 0:p.innerText,i=(g=n==null?void 0:n.querySelector("header > span"))==null?void 0:g.innerText,r=n==null?void 0:n.querySelector("main");if(!r){alert("No main meta found");return}const o=t.querySelector("#previews > main");if(!o){alert("No preview pages found");return}const l=o.children.length,f={Title:s,FileName:i,URL:window.location.href,Artist:[],Circle:[],Parody:[],Magazine:[],Tags:[],Pages:l,Thumbnail:1};console.log("MainMeta",r);for(let h=0;h<r.children.length;h++){const S=r.children[h];if(S.tagName!=="DIV")continue;const m=S.querySelector("strong").textContent,O=S.querySelector(".tags");if(!O)continue;const b=cn(O);switch(m){case"Artists":{f.Artist=b;break}case"Circles":{f.Circle=b;break}case"Parodies":{f.Parody=b;break}case"Magazines":{f.Magazine=b;break}case"Tags":{f.Tags=b;break}}}const a=an(f),y=new Blob([a],{type:"text/yaml"}),u=URL.createObjectURL(y),d=document.createElement("a"),c=window.location.pathname.replace("/g/","").replace("/","-");d.download=`${c}.yaml`,d.href=u,d.click()}function gn(){const t=document.createElement("button");t.innerText="Generate meta",t.addEventListener("click",un),t.style.position="fixed",t.style.bottom="0",t.style.right="0",t.style.zIndex="9999",t.style.padding="10px",t.style.marginRight="10px",t.style.marginBottom="10px",t.style.borderRadius="2px",t.style.border="none",t.style.backgroundColor="#2ecc71",t.style.color="#fff",t.style.cursor="pointer",t.style.fontFamily="sans-serif",t.style.fontSize="16px",t.style.fontWeight="bold",t.style.outline="none",t.style.boxShadow="2px 2px 1px green",t.dataset.generator="1",document.body.appendChild(t)}function et(){document.querySelector("button[data-generator='1']")||gn()}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",et):et(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment