javascript:(function(){ /* Configuration variables. */ var instructionAlert = 1; /* <-- CONFIGURATION - 1 is on (alert), 0 is off (no alert) */ var useRunningFix = 1; /* <-- CONFIGURATION - 1 is on (find and replace), 0 is off */ var replaceAllRunFix = 1; /* <-- CONFIGURATION - 1 is on (replace all), 0 is off */ /* Optional variables. */ var pageTitle = "ChatGPT Bookmark"; /* <-- OPTIONAL - change title */ var pageHead = "ChatGPT Response"; /* <-- OPTIONAL - change head */ var buttonTextChatGPTPasteReadyBookmark = "Bookmarklet"; /* <-- OPTIONAL - button text */ /* DOM variables. */ /* Copy button that starts the bookmark, matched from the clicked element. */ var copyButtonSelector = /* HOT-GLUE - select copy button by attribute */ "[aria-label=\"Copy\"], [aria-label=\"Copy response\"], " + "[data-testid=\"copy-turn-action-button\"]"; /* Copy buttons inside these are skipped - code block and prompt copy buttons. */ var skipCopySelector = /* HOT-GLUE - likely to change */ "pre, .markdown, [data-response-body], [data-turn=\"user\"], " + "[data-code-block], [data-chatgpt-copy-code], [data-user-message-bubble], " + "[data-paste-ready-bookmark]"; /* Conversation turn holding one response and its button row. */ var turnSelector = /* HOT-GLUE - likely to change */ "[data-virtualized-turn], [data-turn-key], article, [data-turn], " + "[data-testid^=\"conversation-turn\"], [data-content-search-turn-key]"; /* Row of buttons under a response - the bookmark button is added at its end. */ var buttonRowSelectorChatGPTPasteReadyBookmark = /* HOT-GLUE - likely to change */ "[class*=\"turn-action-controls\"] > div, [class*=\"turn-action-controls\"], " + "[data-testid*=\"turn-action\"]"; /* Marks the bookmark button, and the window key holding a run's state. */ var markAttributeChatGPTPasteReadyBookmark = "data-paste-ready-bookmark"; var stateKeyChatGPTPasteReadyBookmark = "pasteReady--__-unlikely_-_name-__--PasteReadyBookmarkResponse"; /* Answer area in the turn - first selector with a match is used. */ var answerAreaSelector = [ /* HOT-GLUE - likely to change */ "[data-response-body]", "[data-markdown-text-style]", "[data-message-author-role=\"assistant\"] .markdown", ".markdown", "[data-message-author-role=\"assistant\"]" ]; /* Whole code of a block, kept by the page for its own copy button. */ var codeKeptAttributeChatGPTPasteReadyBookmark = /* HOT-GLUE */ "data-chatgpt-copy-code"; /* Code block marked by the page, such as code with a Run button. */ var codeBlockSelector = /* HOT-GLUE - likely to change */ "[" + codeKeptAttributeChatGPTPasteReadyBookmark + "], " + "[data-code-block], [data-markdown-copy=\"code-block\"]"; /* Code text in a block - code editor lines first, then code, then pre. */ var codeTextSelector = [".cm-content", "code", "pre"]; /* HOT-GLUE */ /* Code block - parents climbed from code to the whole block with its toolbar. */ var codeBlockClimbTags = ["DIV", "PRE", "SPAN"]; /* HOT-GLUE - likely to change */ var codeBlockToolbarLimit = 60; /* most characters of toolbar text in a block */ /* Parts of the answer that are the page's own controls, or not shown. */ var leaveOutSelectorChatGPTPasteReadyBookmark = /* HOT-GLUE */ "button, svg, [hidden], [data-markdown-copy=\"exclude\"]"; /* Attributes the answer keeps - any other is the page's own, and stays there. */ var keepAttributesChatGPTPasteReadyBookmark = ["href", "alt", "dir", "start", "colspan", "rowspan"]; /* Switch variables. */ var onOffPasteReadyBookmarkResponse = 1; /* 1 (default) on, 0 is off */ /********************************************************************************** NOTE - 'HOT-GLUE' comments for fast; ok this works, and/or good enough patch, or DOM element that changes frequently. NOTE - use embedded object 'RUNNING_FIX', following syntax as illustrated below. RUNNING_FIX ILLUSTRATION: ************************* NOTE - this is mainly intended for code examples given by chatGPT. NOTE - if config is 1 (on), and no value or object undefined, bookmarklet still works. For items that transcripted unexpectedly in code boxes. TO USE - Follow pattern: "1": {one: "replace what", two: "with this"}, "2": {one: "replace what", two: "with this"}, etc... For each numeric nested object; property one is replaced with property two. Object is utilized in support funciton "runningFixChatGPTPasteReadyBookmark()". ***********************************************************************************/ /*********** RUNNING_FIX EXAMPLE: ******************** Best to keep a running object of this. Based upon answer where code for C++ was written as ` #include using namespace std;int main() { ` after being bookmarked using bookmarklet. Here a question was asked were several code examples in several languages were given, but for some reason C++ did not transpose correctly, NOTE - code blocks are now copied as plain text and skip RUNNING_FIX, so the C++ items are gone; add items here for text outside of code blocks. ***********/ var RUNNING_FIX = { "1": { one: "\\", /* IMPORTANT - this needs to stay */ two: "\" /* IMPORTANT - this needs to stay */ } }; /* Style the bookmarked page. The page follows the reader's colour scheme: the color-scheme meta names both schemes, and the 3% background on the body propagates to the canvas, so what is painted is rgb(249,250,250) in light and rgb(19,20,20) in dark, with the headings, the body text, the table cells and the inline code taking their colour from the scheme. The dark rules below are that page's own, and the focus ring carries a colour per surface: #0969da reads 4.97:1 on the light canvas and 3.55:1 on the dark, #58a6ff 2.42:1 on the light and 7.31:1 on the dark, against the 3:1 WCAG 1.4.11 asks of a focus indicator. Until the meta arrived on 11.25.2026 the page was painted near-white whatever the reader asked for, which is why one outline-color served both from 11.22.2026 until now. The dark block carries two more surfaces for the same reason, both found on 11.26.2026. The table's grid, left at #d9d9e3 by every rule above it, read 1.34:1 on the light canvas and 13.17:1 on the dark, so it was the one near-white box on a near-black page; it now takes the #3d444d the code block's own edge carries, 1.87:1 against the dark canvas, so the two boxes are ruled at one weight. And the corner badge's 2px border, black on a black surface, read 20.08:1 against the light canvas and 1.14:1 against the dark, which took the block's outline and its rounded corner with it; #6e7681 is 4.02:1 there, past the 3:1 WCAG 1.4.11 asks of a shape a reader has to make out, and the #000 surface is kept. The heading's own hr is the third, found on 11.28.2026: the sheet declared nothing for it, so the browser painted its 1px inset border, rgb(154,154,154) in light and rgb(238,238,238) in dark, 2.69:1 and 15.91:1 against the two canvases and 8.49:1 against the grid that had just been quieted - the one near-white rule left on a near-black page. It is now a 1px block with a colour per scheme, #afb8c1 at 1.92:1 on the light canvas and #484f58 at 2.23:1 on the dark, a step above the grid in each and under the 3:1 that keeps a line a rule rather than a highlight. The corner badge is a share of the page, so its label is sized as one too: at a phone width a fixed 12pt label left the black shape it is written on and was painted over the heading beside it. The padding keeps the label clear of the rounded corner, and the overflow clips anything that still is not. The overflow clips along the padding box, whose bottom-right radius is the 80px asked for less the 2px border, so the label's own padding-right is what holds its line off that curve. A line that only just fits on one line ends about 61px above the padding box's bottom edge, where the curve has already come 1.8px in, and took the end of the final k off at 840px to 849px and 1191px to 1199px of page width. 8px is the least reserve that is not the binding figure at any width from 320px up: past it the longest word in the label is what ends the line, and it leaves 6px of clearance at the closest approach. A wider label or a wider radius is read again. */ { var bookmarkPageStyle = ` `; } /******************************** SUPPORT FUNCTIONS ********************************/ /* Add click event to document, running bookmark when a response copy button is clicked. */ const docEventChatGPTPasteReadyBookmark = () => { /* add a click event listener to the document */ document.addEventListener('click', function(event) { /* ensure bookmarklet is on and an error was not found */ if (onOffPasteReadyBookmarkResponse != 1) return; /* defined at top */ /* clicked element can be the button, its svg, or the svg path */ let clickedItem = event.target; if (!clickedItem || !clickedItem.closest) return; /* not an element */ /* select the copy button holding the clicked element */ let copyButton = clickedItem.closest(copyButtonSelector); /* run if copy button is not a code block or prompt copy button */ if (copyButton && !copyButton.closest(skipCopySelector)) { /* call main function */ pasteReadyBookmarkResponse(copyButton, 0); } }, true); /* capture - runs before the page's own handlers can stop the click */ }; /* Write text to the clipboard, else through a selected text box and the copy command. */ const writeClipboardChatGPTPasteReadyBookmark = (curText, onDone) => { let copyCommand = () => { let curBox = document.createElement("textarea"); curBox.value = curText; curBox.setAttribute("readonly", ""); curBox.style.setProperty("position", "fixed"); curBox.style.setProperty("top", "0"); curBox.style.setProperty("left", "0"); curBox.style.setProperty("opacity", "0"); document.body.appendChild(curBox); curBox.select(); let curCopied = false; try { curCopied = document.execCommand("copy"); } catch (err) { curCopied = false; } curBox.remove(); return curCopied; }; if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(curText).then( () => onDone(true), () => onDone(copyCommand()) ); } else { onDone(copyCommand()); } }; /* Row of buttons under a response, found from its copy button. */ const findButtonRowChatGPTPasteReadyBookmark = (copyButton) => copyButton.closest(buttonRowSelectorChatGPTPasteReadyBookmark) || copyButton.parentElement; /* Bookmark button, drawn like the page's copy button beside it. */ const makeButtonChatGPTPasteReadyBookmark = (copyButton) => { let curButton = document.createElement("button"); curButton.type = "button"; curButton.className = copyButton.className; /* the page's own look for its row */ curButton.setAttribute(markAttributeChatGPTPasteReadyBookmark, "button"); curButton.setAttribute("aria-label", "Copy as bookmarklet"); curButton.title = "Copy as bookmarklet"; curButton.style.setProperty("display", "inline-flex"); curButton.style.setProperty("align-items", "center"); curButton.style.setProperty("gap", "4px"); curButton.style.setProperty("width", "auto"); curButton.style.setProperty("padding", "2px 8px"); curButton.style.setProperty("font-size", "13px"); /* bookmark icon */ let svgSpace = "http://www.w3.org/2000/svg"; let curIcon = document.createElementNS(svgSpace, "svg"); curIcon.setAttribute("width", "16"); curIcon.setAttribute("height", "16"); curIcon.setAttribute("viewBox", "0 0 24 24"); curIcon.setAttribute("fill", "none"); curIcon.setAttribute("stroke", "currentColor"); curIcon.setAttribute("stroke-width", "2"); curIcon.setAttribute("aria-hidden", "true"); let curPath = document.createElementNS(svgSpace, "path"); curPath.setAttribute("d", "M6 3h12v18l-6-4-6 4z"); curIcon.appendChild(curPath); curButton.appendChild(curIcon); curButton.appendChild(document.createTextNode(buttonTextChatGPTPasteReadyBookmark)); /* copy at once - no page copy to wait for, and the click still counts as the reader's */ curButton.addEventListener("click", function(event) { event.preventDefault(); event.stopPropagation(); /* the row's own handlers never see this click */ pasteReadyBookmarkResponse(curButton, 1); }); return curButton; }; /* Add the bookmark button to each response's button row that lacks one. */ const addButtonsChatGPTPasteReadyBookmark = () => { document.querySelectorAll(copyButtonSelector).forEach((copyButton) => { if (copyButton.closest(skipCopySelector)) return; /* code block or prompt copy button */ let curRow = findButtonRowChatGPTPasteReadyBookmark(copyButton); if (!curRow) return; if (curRow.querySelector("[" + markAttributeChatGPTPasteReadyBookmark + "]")) return; curRow.appendChild(makeButtonChatGPTPasteReadyBookmark(copyButton)); }); }; /* Watch for rows the page draws later - new answers, and turns drawn again on scroll. */ const watchRowsChatGPTPasteReadyBookmark = () => { let curTimer = 0; let curWatch = new MutationObserver(function() { if (curTimer) return; curTimer = setTimeout(function() { curTimer = 0; addButtonsChatGPTPasteReadyBookmark(); }, 400); }); curWatch.observe(document.body, {childList: true, subtree: true}); addButtonsChatGPTPasteReadyBookmark(); }; /* Find and replace items in object "RUNNING_FIX". */ const runningFixChatGPTPasteReadyBookmark = (curContent) => { /* ensure that syntax of object is followed */ let followingSyntax = 0; /* turns on if first is good, assumes remaining syntax */ if (RUNNING_FIX && /* if object is declared */ /* and is defined */ (RUNNING_FIX != undefined) || (RUNNING_FIX != null) ) { for (i in RUNNING_FIX) { /* check if first nested object follows syntax */ if (i == 1) { followingSyntax = 1; break; } else { /* end after one */ break; } } /* if syntax passed, continue; assuming remaining nested objects pass */ if (followingSyntax == 1) { for (i in RUNNING_FIX) { /* use a marking value with an unlikely string for an answer */ let unlikelyValue = "unlikely_v_a_l_u_e_for_a_random_book_m-a-r-k-l-e-t_RUNNING_FIX_un_like_ly"; /* check if replace all is turned on */ if (replaceAllRunFix == 1) { let gotAll = 0; /* variable 0 until all marked for replacement */ while (gotAll == 0) { /* while items found to be replace, mark with unlikely value */ if (curContent.indexOf(RUNNING_FIX[i].one) > -1) { curContent = curContent.replace(RUNNING_FIX[i].one, unlikelyValue); } else { /* marked all to be replaced */ gotAll = 1; } } gotAll = 0; /* variable 0 until all marked for replacement */ while (gotAll == 0) { /* while items marked with unlikely value, replace them */ if (curContent.indexOf(unlikelyValue) > -1) { curContent = curContent.replace(unlikelyValue, RUNNING_FIX[i].two); } else { /* replaced all marked values */ gotAll = 1; } } } else { /* replace first occurence */ curContent = curContent.replace(RUNNING_FIX[i].one, RUNNING_FIX[i].two); } } } return curContent; } }; /* Find the answer area for the copy button that was clicked. */ const findAnswerAreaChatGPTPasteReadyBookmark = (copyButton) => { /* conversation turn holding the copy button */ let curTurn = copyButton.closest(turnSelector); /* use first answer area selector with a match in the turn */ if (curTurn) { for (let i = 0; i < answerAreaSelector.length; i++) { let curAnswer = curTurn.querySelectorAll(answerAreaSelector[i]); if (curAnswer.length > 0) { return Array.from(curAnswer); /* response can have more than one part */ } } } /* fallback - check the element before each parent of the copy button */ let buttonRow = copyButton.parentElement; for (let i = 0; i < 20 && buttonRow && buttonRow != curTurn; i++) { /* safety limit */ let answerRow = buttonRow.previousElementSibling; if (answerRow && answerRow.innerText.trim().length >= 100) { /* probably match */ return [answerRow]; } buttonRow = buttonRow.parentElement; /* check next top-level element */ } /* answer area not found */ return []; }; /* Plain text of code, as the page keeps it, else from its code editor. */ const codeTextChatGPTPasteReadyBookmark = (curCode) => { let curText = ""; let curKept = curCode.closest("[" + codeKeptAttributeChatGPTPasteReadyBookmark + "]"); if (curKept && curKept.getAttribute(codeKeptAttributeChatGPTPasteReadyBookmark)) { curText = curKept.getAttribute(codeKeptAttributeChatGPTPasteReadyBookmark); } else if (curCode.classList.contains("cm-content")) { /* whole document from the editor, as long code may only draw lines in view */ let curRef = curCode.cmView || curCode.cmTile; let curView = curRef && (curRef.view || (curRef.rootView && curRef.rootView.view) || (curRef.root && curRef.root.view)); if (curView && curView.state && curView.state.doc) { curText = curView.state.doc.toString(); } else { /* one editor line per element */ curText = Array.from(curCode.querySelectorAll(".cm-line")) .map((curLine) => curLine.textContent).join("\n"); } } else { /* line breaks and indents as shown on the page */ curText = curCode.innerText || curCode.textContent; } /* no-break spaces to spaces, and no trailing line breaks */ return curText.split(String.fromCharCode(160)).join(" ").replace(/\n+$/, ""); }; /* Mark each code block in the answer, saving its language and plain text. */ const markCodeBlocksChatGPTPasteReadyBookmark = (curArea, codeBlocks) => { /* mark block so its copy is swapped for a token */ let markBlock = (curBlock, curCode) => { /* language from toolbar text, else from the code's language attribute or class */ let curLang = ""; let curWalker = document.createTreeWalker(curBlock, NodeFilter.SHOW_TEXT); while (!curLang && curWalker.nextNode()) { let curNode = curWalker.currentNode; if (curCode.contains(curNode) || curNode.parentElement.closest("button")) continue; curLang = curNode.textContent.trim().slice(0, 30); } if (!curLang) { let langMatch = /language-([\w#+.-]+)/.exec(curCode.className); curLang = curCode.getAttribute("data-language") || (langMatch ? langMatch[1] : ""); } curBlock.setAttribute("data-paste-ready-code", codeBlocks.length); codeBlocks.push({lang: curLang, text: codeTextChatGPTPasteReadyBookmark(curCode)}); }; /* blocks the page marks as code blocks, such as code with a Run button */ curArea.querySelectorAll(codeBlockSelector).forEach((curBlock) => { if (curBlock.closest("[data-paste-ready-code]")) return; /* already in a block */ let curCode = null; for (let i = 0; i < codeTextSelector.length && !curCode; i++) { curCode = curBlock.querySelector(codeTextSelector[i]); } if (curCode) markBlock(curBlock, curCode); }); /* count of code and pre elements, including the element */ let codeCount = (curEl) => curEl.querySelectorAll("code, pre").length + (curEl.matches("code, pre") ? 1 : 0); /* other code that is a block - in a pre, has a language, or more than one line */ let curCodes = Array.from(curArea.querySelectorAll("pre, code")).filter((curCode) => (curCode.tagName == "PRE" && !curCode.querySelector("code")) || (curCode.tagName == "CODE" && (curCode.closest("pre") || /language-/.test(curCode.className) || curCode.textContent.indexOf("\n") > -1)) ); curCodes.forEach((curCode) => { if (curCode.closest("[data-paste-ready-code]")) return; /* already in a block */ let codeLength = curCode.textContent.length; /* climb to the parent holding only this code and its toolbar */ let curBlock = curCode.closest("pre") || curCode; let curPar = curBlock.parentElement; while (curPar && curPar != curArea && codeBlockClimbTags.indexOf(curPar.tagName) > -1 && curPar.querySelectorAll("code, pre").length == codeCount(curBlock) && curPar.textContent.length - codeLength <= codeBlockToolbarLimit) { curBlock = curPar; curPar = curBlock.parentElement; } markBlock(curBlock, curCode); }); }; /* Write a code block as html, safe in the bookmarklet string and the URL field. */ const codeBlockHTMLChatGPTPasteReadyBookmark = (curBlock) => { let encode = (curText) => curText .replace(/&/g, "&").replace(//g, ">") .replace(/"/g, """).replace(/'/g, "'").replace(/\\/g, "\") .replace(/`/g, "`").replace(/%/g, "%").replace(/\t/g, " ") .replace(/\r/g, "").replace(/\n/g, "
"); return "
" + (curBlock.lang ? "
" + encode(curBlock.lang) + "
" : "") + "
" + encode(curBlock.text) + "
"; }; /*********************************************************************************** MAIN FUNCTION ***********************************************************************************/ function pasteReadyBookmarkResponse(aWhat, ownButton) { /* select the answer area for the button that was clicked */ let answerArea = findAnswerAreaChatGPTPasteReadyBookmark(aWhat); /* dry alert - repair needed */ let dryAlert = () => { alert("REPAIR NEEDED:\n\n" + " Please report issue on GitHub repo\n" + " https://github.com/isocialPractice/bookmarklets" ); /* turn off bookmarklet */ onOffPasteReadyBookmarkResponse = 0; }; /* define function variables */ let copiedContent, codeBlocks = []; /* ensure that answer area has been found */ if (answerArea.length == 0) { /* answer area not found */ console.log(aWhat); /* alert repair is needed */ dryAlert(); /* exit function */ return; } else { /* found from function findAnswerAreaChatGPTPasteReadyBookmark */ /* now the answer's div elements should be extracted, code blocks as tokens */ copiedContent = answerArea.map((curArea) => { markCodeBlocksChatGPTPasteReadyBookmark(curArea, codeBlocks); let curClone = curArea.cloneNode(true); curClone.querySelectorAll("[data-paste-ready-code]").forEach((curBlock) => { curBlock.replaceWith( "codeblock_paste_ready_" + curBlock.getAttribute("data-paste-ready-code") + "_end" ); }); /* the page's controls and attributes stay on the page */ curClone.querySelectorAll(leaveOutSelectorChatGPTPasteReadyBookmark).forEach((curEl) => { curEl.remove(); }); curClone.querySelectorAll("*").forEach((curEl) => { Array.from(curEl.attributes).forEach((curAttr) => { let curKeep = keepAttributesChatGPTPasteReadyBookmark.indexOf(curAttr.name) > -1; /* an address is kept only where it opens a page or an email */ if (curAttr.name == "href" && !/^(https?:|mailto:)/i.test(curAttr.value)) curKeep = false; if (!curKeep) curEl.removeAttribute(curAttr.name); }); }); /* each table in a scrolling box of its own, so a wide table scrolls and the page does not */ curClone.querySelectorAll("table").forEach((curTable) => { if (!curTable.parentNode) { return; } let curTableBox = document.createElement("div"); curTableBox.className = "tableScrollPasteReady"; curTable.parentNode.insertBefore(curTableBox, curTable); curTableBox.appendChild(curTable); }); return curClone.innerHTML; }).join(""); /* remove code block marks from the page */ document.querySelectorAll("[data-paste-ready-code]").forEach((curBlock) => { curBlock.removeAttribute("data-paste-ready-code"); }); } /* attributes in single quotes, as the bookmarklet's string is in double quotes */ copiedContent = copiedContent.replace(/<[a-z](?:"[^"]*"|[^"<>])*>/gi, (curTag) => curTag.replace(/="([^"]*)"/g, (curAttr, curValue) => "='" + curValue.replace(/'/g, "'") + "'" ) ); /* clean up a bit */ copiedContent = copiedContent.replace(/%/g, "%"); /* a URL field reads a percent sign as an escape */ copiedContent = copiedContent.replace(/\n/g, "--new-line_unlikely_line-new--"); /* new line marker replaced later */ copiedContent = copiedContent.replace(/\"/g, '\"'); /* use html encoding for escaped double quotes */ copiedContent = copiedContent.replace(/"/g, '\"'); /* keep double quotes as needed for inline html */ copiedContent = copiedContent.replace(/\'/g, "\''"); /* use html encoding for escaped single quotes */ copiedContent = copiedContent.replace(/'/g, "'"); /* keep single quotes as needed for inline html */ /* utilize "RUNNING_FIX" to correctly write unexpected outputs */ copiedContent = runningFixChatGPTPasteReadyBookmark(copiedContent); /* swap code block tokens for plain text code blocks */ copiedContent = copiedContent.replace(/codeblock_paste_ready_(\d+)_end/g, (curToken, curIndex) => codeBlockHTMLChatGPTPasteReadyBookmark(codeBlocks[curIndex]) ); /* HOT-GLUE - replace new line characters only in pre tags with
*/ /* remove unlikely new line marker in remaining html */ var pageScript = ` `; /* store new bookmarklet to be written to clipboard */ var bookmarklet = 'javascript:(function() {document.write("' + /* write html head content */ "" + "" + pageTitle + "" + /* style a bit */ bookmarkPageStyle + /* add page body and div */ "
" + "

" + pageHead + "


" + /* sidebarlink to original answer */ "
" + "ChatGPT" + '

ChatGPT Bookmark

' + /* cleaned copied content */ copiedContent + /* close page div and add pageScript */ "
" + pageScript + /* close html */ "" + /* close bookmarklet */ '");})()'; /* HOT-GLUE - remove unwanted escaped double quotes - HOT-GLUE */ bookmarklet = bookmarklet.replace(/\"/g, """); /* HOT-GLUE - remove unwanted escaped single quotes - HOT-GLUE */ bookmarklet = bookmarklet.replace(/\'/g, ""); /* HOT-GLUE - remove bactic as probably md styling - HOT-GLUE */ bookmarklet = bookmarklet.replace(/`/g, ""); /* the clipboard did not take it - say so, rather than leave the answer's text there */ let failedAlert = () => { alert("COPY FAILED:\n\n" + " The bookmarklet did not reach the clipboard.\n" + " Click the page once, then click \"" + buttonTextChatGPTPasteReadyBookmark + "\" under the answer again." ); }; if (ownButton == 1) { /* bookmark button - copy now, while the click still counts as the reader's */ writeClipboardChatGPTPasteReadyBookmark(bookmarklet, (curCopied) => { if (!curCopied) { failedAlert(); return; } alert( "Copied as a bookmarklet. \n\n" + "Open the bookmark manager, make a new bookmark, and paste into its URL field." ); }); } else { /* page copy button - wait, so the bookmarklet is copied after the answer's text */ alert( "Wait 2 seconds for content to generate as bookmarklet on clipboard. \n" + "Then open bookmark manager and make new bookmark by pasting into url field. \n\n" + "The \"" + buttonTextChatGPTPasteReadyBookmark + "\" button under the answer " + "copies it without the wait." ); setTimeout(function () { writeClipboardChatGPTPasteReadyBookmark(bookmarklet, (curCopied) => { if (!curCopied) failedAlert(); }); }, 2000); } } /* A second run reuses the first run's click handler and row watcher, turning it back on and adding any missing buttons, rather than stacking a second copy of either. */ var runStateChatGPTPasteReadyBookmark = window[stateKeyChatGPTPasteReadyBookmark]; if (runStateChatGPTPasteReadyBookmark) { runStateChatGPTPasteReadyBookmark.turnOn(); runStateChatGPTPasteReadyBookmark.addButtons(); } else { /* run function that checks whenever a click event fires on page */ docEventChatGPTPasteReadyBookmark(); /* add the bookmark button under each response, now and as the page draws more */ watchRowsChatGPTPasteReadyBookmark(); window[stateKeyChatGPTPasteReadyBookmark] = { turnOn: function() { onOffPasteReadyBookmarkResponse = 1; }, addButtons: addButtonsChatGPTPasteReadyBookmark }; } /* If instruction alert is on. */ if (instructionAlert == 1) { alert( "INSTRUCTIONS: \n" + "**************** \n" + "IMPORTANT - use the \"" + buttonTextChatGPTPasteReadyBookmark + "\" button in the row of buttons below an answer. \n\n" + "1. Run bookmarklet. \n" + "2. Click \"" + buttonTextChatGPTPasteReadyBookmark + "\" below the answer. \n" + " The answer's own copy button works too, after a 2 second wait. \n" + "3. Create a new bookmark, pasting contents of clipboard in the URL box."); } } )();