PageSourceSearch

https://www.intrenion.com/assets/copy-doctrine.js

js intrenion.com collected 2026-09-29 04:32:09 UTC 3,104 bytes, 169 lines download raw bytes

1const intrenionUrl = "https://www.intrenion.com";
2
3async function extractPageHtml(url, startPrefixes) {
4
5  const response = await fetch(url, {
6    cache: "no-store"
7  });
8
9  if (!response.ok) {
10    throw new Error(`Failed to fetch ${url}`);
11  }
12
13  const html = await response.text();
14
15  const parser = new DOMParser();
16  const doc = parser.parseFromString(html, "text/html");
17
18  const start = [...doc.querySelectorAll("h1,h2,h3,h4,h5,h6")].find(h => {
19    const text = (h.textContent || "").trim();
20
21    return startPrefixes.some(prefix => text.startsWith(prefix));
22  });
23
24  if (!start) {
25    throw new Error(`Could not find start heading on ${url}`);
26  }
27
28  let htmlContent = "";
29
30  let node =
31    startPrefixes.includes("Prompt") ||
32    startPrefixes.includes("Instructions")
33      ? start.nextElementSibling
34      : start;
35
36  while (node) {
37
38    if (node.tagName === "SCRIPT") {
39      break;
40    }
41
42    htmlContent += node.outerHTML;
43    node = node.nextElementSibling;
44
45  }
46
47  return htmlContent;
48}
49
50function createCopyDoctrineComponent() {
51
52  const target = document.getElementById("copy-doctrine-widget");
53
54  if (!target) {
55    return false;
56  }
57
58  target.classList.add("copy-doctrine");
59
60  target.innerHTML = `
61    <div id="copy-doctrine-instructions"></div>
62    <p>
63      <button type="button" id="copy-doctrine-button">Copy Doctrine</button>
64    </p>
65  `;
66
67  document
68    .getElementById("copy-doctrine-button")
69    .addEventListener("click", copyDoctrine);
70
71  return true;
72}
73
74async function loadCopyDoctrineInstructions() {
75
76  const target = document.getElementById(
77    "copy-doctrine-instructions"
78  );
79
80  if (!target) {
81    return;
82  }
83
84  try {
85
86    target.innerHTML = await extractPageHtml(
87      `${intrenionUrl}/doctrine/copy-doctrine-instructions/`,
88      ["Instructions"]
89    );
90
91  } catch (error) {
92
93    console.error(error);
94
95  }
96
97}
98
99async function copyDoctrine() {
100
101  try {
102
103    const turndownService = new TurndownService({
104      headingStyle: "atx",
105      bulletListMarker: "-"
106    });
107
108    const promptHtml = await extractPageHtml(
109      `${intrenionUrl}/doctrine/learning-prompt/`,
110      ["Prompt"]
111    );
112
113    const doctrineHtml = await extractPageHtml(
114      window.location.href,
115      [
116        "Introduction",
117        "Overview",
118        "Source",
119        "Title",
120        "Practice 1",
121        "Section 1",
122        "Subsection 1"
123      ]
124    );
125
126    const prompt = turndownService
127      .turndown(promptHtml)
128      .trim();
129
130    const doctrine = turndownService
131      .turndown(doctrineHtml)
132      .trim();
133
134    const text =
135`${prompt}
136
137--------------------------------------------------
138
139${doctrine}`
140      .replace(/^- {3}/gm, "- ");
141
142    await navigator.clipboard.writeText(text);
143
144    alert("Doctrine copied to clipboard.");
145
146  } catch (error) {
147
148    console.error(error);
149
150    alert(
151      "Failed to copy doctrine.\n\n" +
152      error.message
153    );
154
155  }
156
157}
158
159document.addEventListener("DOMContentLoaded", async () => {
160
161  const componentCreated = createCopyDoctrineComponent();
162
163  if (!componentCreated) {
164    return;
165  }
166
167  await loadCopyDoctrineInstructions();
168
169});

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.