1var __defProp = Object.defineProperty; 2var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 }); 3class UNLQa { 4 static { 5 __name(this, "UNLQa"); 6 } 7 /** 8 * @type { HTMLElement|null } 9 */ 10 qaLink = null; 11 webauditQueryUrl = "https://webaudit.unl.edu/registry/closest/?format=json&query="; 12 constructor() { 13 this.qaLink = document.getElementById("qa-test"), this.qaLink !== null && (this.#appendLinkWithLocation(), this.#appendLinkWithStar()), this.qaLink.dispatchEvent(new CustomEvent(UNLQa.events("qaReady"), { 14 detail: { 15 classInstance: this 16 } 17 })), window.UNL = window.UNL || {}, window.UNL.classes = window.UNL.classes || {}, window.UNL.classes["qa-test"] = this, this.qaLink.dispatchEvent(new Event("UNLClassReady")); 18 } 19 // The names of the events to be used easily 20 static events(name) { 21 const events = { 22 qaReady: "qaReady" 23 }; 24 return Object.freeze(events), name in events ? events[name] : void 0; 25 } 26 #appendLinkWithLocation() { 27 let pathname = document.location.pathname; 28 !pathname.match(/\..*$/) && !pathname.match(/\/$/) && (pathname += "/"); 29 const currentHref = this.qaLink.getAttribute("href"); 30 this.qaLink.setAttribute("href", `${currentHref}?url=${encodeURI(document.location.origin + pathname)}`); 31 } 32 async #appendLinkWithStar() { 33 const gpa = await this.#fetchScore(); 34 if (gpa !== null) { 35 if (gpa === 100) { 36 const starIcon = document.createElement("span"); 37 starIcon.setAttribute("aria-hidden", "true"), starIcon.innerHTML = " ★"; 38 const starText = document.createElement("span"); 39 starText.classList.add("dcf-sr-only"), starText.innerText = "100% (gold star)", this.qaLink.after(starIcon, starText); 40 } else if (gpa >= 90) { 41 const starIcon = document.createElement("span"); 42 starIcon.setAttribute("aria-hidden", "true"), starIcon.innerHTML = " ☆"; 43 const starText = document.createElement("span"); 44 starText.classList.add("dcf-sr-only"), starText.innerText = `${gpa}% (silver star)`, this.qaLink.after(starIcon, starText); 45 } 46 } 47 } 48 #getBaseUrl() { 49 const baseTag = document.querySelector("base"); 50 let baseUrl = window.location; 51 if (baseTag !== null) { 52 const baseTagHref = baseTag.getAttribute("href"); 53 if (baseTagHref.length > 1 && baseTagHref !== null) 54 try { 55 baseUrl = new URL(baseTagHref).toString(); 56 } catch { 57 } 58 } 59 return baseUrl; 60 } 61 /** 62 * 63 * @returns { Promise<Number|null> } 64 */ 65 async #fetchScore() { 66 try { 67 const baseURIEncoded = encodeURIComponent(this.#getBaseUrl()), response = await fetch(`${this.webauditQueryUrl}${baseURIEncoded}`); 68 if (!response.ok) 69 return null; 70 const jsonData = await response.json(); 71 return "gpa" in jsonData ? parseFloat(jsonData.gpa) : null; 72 } catch (err) { 73 return console.error(err), null; 74 } 75 } 76} 77export { 78 UNLQa as default 79}; 80//# sourceMappingURL=component.qa.js.map
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.