[ { "r": "user", "t": [ [ "This is the latest working scriptlet you've made for me for archiving", "conversation history:" ], [ "javascript:(function(){" ], [ "try {" ], [ "/* Wrap text at word boundaries */" ], [ "function wrapText(t) {" ], [ "return t.split(' ').reduce((l,w)=>(l[l.length-1]+w).length>80?(l.push(w+'", "'),l):(l[l.length-1]+=w+' ',l),['']).map(x=>x.trim()).filter(x=>x);" ], [ "}" ], [], [ "/* Extract messages */" ], [ "var c = [];" ], [ "document.querySelectorAll('div[data-message-author-role]').forEach(function(m) {" ], [ "var r = m.innerText.split('\\n').map(function(x) { return wrapText(x); });" ], [ "c.push({ r: m.getAttribute('data-message-author-role'), t: r });" ], [ "});" ], [], [ "/* JSON output */" ], [ "var j = JSON.stringify(c, null, 2), w = window.open();" ], [ "w.document.body.innerHTML = '
' + j + '
';" ], [], [ "/* Copy to clipboard quietly */" ], [ "navigator.clipboard.writeText(j).catch(e => alert('Copy failed: ' +", "e.message));" ], [], [ "/* Download JSON file */" ], [ "var d = new Date().toISOString().slice(0, 10), b = new Blob([j], { type:", "'application/json' }), a = document.createElement('a');" ], [ "a.href = URL.createObjectURL(b); a.download = 'conv_' + d + '.json.txt';", "a.click();" ], [ "} catch (e) {" ], [ "alert('Error: ' + e.message);" ], [ "}" ], [ "})();" ], [ ". Assistant messages have data-message-author-role=\"assistant\", and user", "messages have this equal to \"user\". However, there are other messages that don't", "have data-message-author-role=\"assistant\", but do have the \"markdown\" class,", "which I would like included. Unfortunately, user messages do not have the", "markdown class (although assistant messages do). Can you update the scriptlet to", "make sure none of the 3 types of present combinations of that stuff are left out", "of the output?" ], [] ] }, { "r": "assistant", "t": [ [ "Here's the updated scriptlet that handles all three combinations (messages with", "data-message-author-role=\"assistant\", data-message-author-role=\"user\", and those", "with the \"markdown\" class but without data-message-author-role). This ensures", "none of them are left out of the output:" ], [], [ "javascript" ], [ "Copy code" ], [ "javascript:(function(){" ], [ "try {" ], [ "/* Wrap text at word boundaries */" ], [ "function wrapText(t) {" ], [ "return t.split(' ').reduce((l,w)=>(l[l.length-1]+w).length>80?(l.push(w+'", "'),l):(l[l.length-1]+=w+' ',l),['']).map(x=>x.trim()).filter(x=>x);" ], [ "}" ], [], [ "/* Extract messages */" ], [ "var c = [];" ], [ "document.querySelectorAll('div[data-message-author-role],", ".markdown').forEach(function(m) {" ], [ "var role = m.getAttribute('data-message-author-role') || 'unknown';" ], [ "var r = m.innerText.split('\\n').map(function(x) { return wrapText(x); });" ], [ "c.push({ r: role, t: r });" ], [ "});" ], [], [ "/* JSON output */" ], [ "var j = JSON.stringify(c, null, 2), w = window.open();" ], [ "w.document.body.innerHTML = '
' + j + '
';" ], [], [ "/* Copy to clipboard quietly */" ], [ "navigator.clipboard.writeText(j).catch(e => alert('Copy failed: ' +", "e.message));" ], [], [ "/* Download JSON file */" ], [ "var d = new Date().toISOString().slice(0, 10), b = new Blob([j], { type:", "'application/json' }), a = document.createElement('a');" ], [ "a.href = URL.createObjectURL(b); a.download = 'conv_' + d + '.json.txt';", "a.click();" ], [ "} catch (e) {" ], [ "alert('Error: ' + e.message);" ], [ "}" ], [ "})();" ], [ "This version checks for both data-message-author-role and the markdown class. If", "data-message-author-role is missing, it sets the role as \"unknown\". This should", "now cover all the message types you mentioned." ], [], [] ] }, { "r": "user", "t": [ [ "ok, but it outputs some content twice because some \"markdown\" nodes are children", "of \"data-message-author-role='assistant'\" nodes. can you use \"markdown\" to", "identify assistant messages, instead of \"data-message-author-role\", and use", "\"data-message-author-role\" for user messages only? i don't think the chatgpt", "interface uses markdown nodes for user messages, am i wrong? be sure to retain", "the correct order of the messages." ], [] ] }, { "r": "assistant", "t": [ [ "Here's the updated scriptlet that ensures only user messages are identified by", "data-message-author-role, and assistant messages are identified by the markdown", "class. This should also avoid duplicating content and maintain the correct", "order:" ], [], [ "javascript" ], [ "Copy code" ], [ "javascript:(function(){" ], [ "try {" ], [ "/* Wrap text at word boundaries */" ], [ "function wrapText(t) {" ], [ "return t.split(' ').reduce((l,w)=>(l[l.length-1]+w).length>80?(l.push(w+'", "'),l):(l[l.length-1]+=w+' ',l),['']).map(x=>x.trim()).filter(x=>x);" ], [ "}" ], [], [ "/* Extract messages */" ], [ "var c = [];" ], [ "document.querySelectorAll('div[data-message-author-role=\"user\"],", ".markdown').forEach(function(m) {" ], [ "var role = m.classList.contains('markdown') ? 'assistant' : 'user';" ], [ "var r = m.innerText.split('\\n').map(function(x) { return wrapText(x); });" ], [ "c.push({ r: role, t: r });" ], [ "});" ], [], [ "/* JSON output */" ], [ "var j = JSON.stringify(c, null, 2), w = window.open();" ], [ "w.document.body.innerHTML = '
' + j + '
';" ], [], [ "/* Copy to clipboard quietly */" ], [ "navigator.clipboard.writeText(j).catch(e => alert('Copy failed: ' +", "e.message));" ], [], [ "/* Download JSON file */" ], [ "var d = new Date().toISOString().slice(0, 10), b = new Blob([j], { type:", "'application/json' }), a = document.createElement('a');" ], [ "a.href = URL.createObjectURL(b); a.download = 'conv_' + d + '.json.txt';", "a.click();" ], [ "} catch (e) {" ], [ "alert('Error: ' + e.message);" ], [ "}" ], [ "})();" ], [ "Now, the scriptlet only uses data-message-author-role=\"user\" to identify user", "messages and markdown for assistant messages. This should ensure no duplication", "of content and preserve the correct order of the messages." ], [], [] ] } ]