|
/* eslint-disable */ |
|
// @ts-nocheck |
|
// ==UserScript== |
|
// @name Copy Note to Markdown |
|
// @namespace https://github.com/volkanunsal |
|
// @version 2026.0328.1054 |
|
// @description Copies the current note content as Markdown to clipboard |
|
// @author Volkan Unsal |
|
// @downloadURL https://gist.githubusercontent.com/volkanunsal/5d67c79c3c117bc81d1301a3a5e3d18e/raw/e345d890d1245f892a45ae6048ece2172e183034/copy-note-to-markdown.user.js |
|
// @updateURL https://gist.githubusercontent.com/volkanunsal/5d67c79c3c117bc81d1301a3a5e3d18e/raw/e345d890d1245f892a45ae6048ece2172e183034/copy-note-to-markdown.user.js |
|
// @match https://notebooklm.google.com/* |
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com |
|
// @grant GM_addStyle |
|
|
|
// ==/UserScript== |
|
|
|
"use strict";(()=>{var F=class{constructor(t={}){this.namespace=t.namespace,this.prefix=[this.namespace,t.prefix].filter(Boolean).join(" "),this.enabled=t.enabled!==!1,this.timestamp=t.timestamp!==!1,this.timestampFormat=t.timestampFormat||"locale"}isVerbose(){try{return!!localStorage.getItem("VERBOSE_LOGGING")}catch{return!1}}getTimestamp(){let t=new Date;return this.timestampFormat==="ISO"?t.toISOString():t.toLocaleString()}formatMessage(t,...r){let n=[this.prefix];return this.timestamp&&n.push(`[${this.getTimestamp()}]`),n.push(`[${t.toUpperCase()}]`),[n.join(" "),...r]}debug(...t){!this.enabled||!this.isVerbose()||console.debug(...this.formatMessage("debug",...t))}info(...t){!this.enabled||!this.isVerbose()||console.info(...this.formatMessage("info",...t))}warn(...t){this.enabled&&console.warn(...this.formatMessage("warn",...t))}error(...t){this.enabled&&console.error(...this.formatMessage("error",...t))}log(...t){!this.enabled||!this.isVerbose()||console.log(...this.formatMessage("log",...t))}custom(t,...r){this.enabled&&console.log(...this.formatMessage(t,...r))}group(t,r){if(!this.enabled)return r();console.group(`${this.prefix} ${t}`);try{r()}finally{console.groupEnd()}}groupCollapsed(t,r){if(!this.enabled)return r();console.groupCollapsed(`${this.prefix} ${t}`);try{r()}finally{console.groupEnd()}}table(t,r){this.enabled&&(this.info("Table data:"),console.table(t,r))}time(t){this.enabled&&console.time(`${this.prefix} ${t}`)}timeEnd(t){this.enabled&&console.timeEnd(`${this.prefix} ${t}`)}timeLog(t){this.enabled&&console.timeLog(`${this.prefix} ${t}`)}enable(){this.enabled=!0}disable(){this.enabled=!1}setPrefix(t){this.prefix=t}};function D(e={}){return new F(e)}function A(e,t){function r(n){return n.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"")}if(window.trustedTypes){let i=window.trustedTypes.createPolicy("myHTMLPolicy",{createHTML:r}).createHTML(t);e.innerHTML=i}else{let n=r(t);e.innerHTML=n}}async function z(e){let{tagName:t,id:r,attributes:n={},parentSelector:i="body",parentElement:a,textContent:l,innerHTML:u,innerElement:c,returnElement:h=!0,checkExisting:k=!0,replaceExisting:L=!1,insertionMethod:N="append",contextElement:y,waitTimeout:I=3e4,persistent:T=!1,autoRemove:x=!0,debounceDelay:me=500,observerConfig:w={childList:!0,subtree:!0,attributes:!1,attributeOldValue:!1,characterData:!1,characterDataOldValue:!1},namespace:pe,onMount:R}=e,o=D({prefix:"[createElement]",namespace:pe}),s={action:"create",tagName:t,id:r,parentMethod:i?"selector":"element",parentIdentifier:i||(a?a.tagName:"unknown"),waitTimeout:I,insertionMethod:N};if(o.info(`Starting element creation: <${t}> with ID="${r}"${y?" (conditional)":""} using ${N} insertion`),!t||typeof t!="string")return o.error("Element creation failed: Tag parameter is required and must be a string",s),null;if(!r||typeof r!="string")return o.error("Element creation failed: ID parameter is required and must be a non-empty string",s),null;if(!i&&!a)return o.error("Element creation failed: Either parentSelector or parentElement must be provided",s),null;if(N!=="append"&&N!=="insertBeforeElement"&&N!=="prepend")return o.error("Element creation failed: insertionMethod must be 'append', 'insertBeforeElement', or 'prepend'",s),null;function B(d,m,f){try{let v=new DOMParser().parseFromString(m,"text/html"),p=v.querySelector("parsererror");if(p)throw new Error(`HTML parsing error: ${p.textContent}`);let E=Array.from(v.body.childNodes);return E.length===0?(o.warn(`No valid elements found in HTML string: "${m.substring(0,50)}${m.length>50?"...":""}"`,f),!1):(E.forEach($=>{let P=d.ownerDocument.importNode($,!0);d.appendChild(P)}),o.debug(`Created DOM elements programmatically: "${m.substring(0,50)}${m.length>50?"...":""}" (${E.length} elements)`,f),!0)}catch(b){o.warn(`DOMParser failed, attempting fallback method: ${b.message}`,f);try{return A(d,m),o.debug(`Successfully created DOM elements via fallback method: "${m.substring(0,50)}${m.length>50?"...":""}"`,f),!0}catch(v){return o.error(`DOM insertion failed: ${v.message}`,{...f,originalError:b.message,fallbackError:v.message}),!1}}}function M(){try{let d=null;if(k&&(d=document.getElementById(r),d))if(s.action="exists",L)o.info(`Found existing element with ID="${r}", replacing as requested`,s),d.remove(),s.action="replace";else return o.warn(`Element with ID="${r}" already exists, skipping creation. Use replaceExisting=true to replace.`,s),h?d:null;let m=a;if(!m&&i){let p=document.querySelector(i);if(!p)return o.error(`Element creation failed: Parent element not found with selector: ${i}`,s),null;m=p,o.debug(`Found parent element with selector: ${i}`,s)}if(!m)return o.error("Element creation failed: No valid parent element found",s),null;let f=document.createElement(t);o.debug(`Created DOM element: <${t}>`,s),f.setAttribute("id",r),o.debug(`Set required ID attribute: id="${r}"`,s);let b=Object.keys(n).length;if(b>0&&(Object.entries(n).forEach(([p,E])=>{E!=null&&(f.setAttribute(p,String(E)),o.debug(`Set attribute: ${p}="${E}"`,s))}),o.debug(`Applied ${b} additional attributes to element`,s)),c&&typeof c=="function")try{let p=c();p instanceof HTMLElement?(f.appendChild(p),o.debug("Inserted child element via innerElement callback",s)):(o.warn("innerElement callback did not return a valid HTMLElement, falling back to other content methods",s),l!==void 0?(f.textContent=l,o.debug(`Set textContent: "${l.substring(0,100)}${l.length>100?"...":""}"`,s)):u!==void 0&&B(f,u,s))}catch(p){o.error("Error executing innerElement callback, falling back to other content methods:",p,s),l!==void 0?(f.textContent=l,o.debug(`Set textContent: "${l.substring(0,100)}${l.length>100?"...":""}"`,s)):u!==void 0&&B(f,u,s)}else l!==void 0?(f.textContent=l,o.debug(`Set textContent: "${l.substring(0,100)}${l.length>100?"...":""}"`,s)):u!==void 0&&B(f,u,s);if(N==="insertBeforeElement")if(m.parentElement)m.parentElement.insertBefore(f,m),o.debug("Inserted element before parent",s);else return o.error("Element insertion failed: Parent element has no parent to insert before",s),null;else N==="prepend"?(m.insertBefore(f,m.firstChild),o.debug("Prepended element as first child of parent",s)):(m.appendChild(f),o.debug("Appended element to end of parent",s));if(R&&typeof R=="function")try{R(f),o.debug(`Successfully called onMount callback for element ID="${r}"`,s)}catch(p){o.warn(`Error in onMount callback for element ID="${r}":`,p,s)}let v=`Element creation successful: <${t}> (ID="${r}") ${s.action==="replace"?"replaced and ":""}${N}ed to ${s.parentMethod==="selector"?`parent selected by "${i}"`:"provided parent element"}${y?" (after content element)":""}`;return o.info(v,{...s,success:!0,hasAttributes:b>0,hasContent:!!(l||u||c),parentTagName:m.tagName,elementPath:f.tagName+"#"+f.id+(f.className?`.${f.className.replace(/\s+/g,".")}`:"")}),h?f:null}catch(d){let m=`Element creation failed with exception: ${d.message||"Unknown error"}`;return o.error(m,{...s,success:!1,error:d.message||"Unknown error",stack:d.stack||"No stack trace available"}),null}}async function H(){try{if(typeof y=="function"){let d=await y();return d instanceof HTMLElement&&document.contains(d)}else if(typeof y=="string")return document.querySelector(y)!==null}catch(d){o.warn(`Error checking content element for element ID="${r}":`,d)}return!1}function Y(){if(!T&&!x)return;o.info(`Setting up ${T?"persistent":""}${T&&x?" and ":""}${x?"auto-removal":""} monitoring for element ID="${r}"`);let d=null,m=new MutationObserver(async()=>{d&&clearTimeout(d),d=setTimeout(async()=>{o.debug(`Persistent monitoring check triggered for element ID="${r}"`);let b=await H(),v=document.getElementById(r);b?T&&!v?(o.info(`Context element found but managed element missing, recreating element ID="${r}"`),M()):o.debug(`Both context and managed elements exist for ID="${r}"`):x&&v?(o.info(`Context element no longer present, removing managed element ID="${r}"`),v.remove()):o.debug(`Context element no longer present for element ID="${r}"`)},me)}),f={childList:w.childList===!0,subtree:w.subtree===!0,attributes:w.attributes===!0,attributeOldValue:w.attributeOldValue===!0,characterData:w.characterData===!0,characterDataOldValue:w.characterDataOldValue===!0};m.observe(document.documentElement||document.body,f),o.debug(`Started persistent MutationObserver for element ID="${r}"`)}if(!y)return M();if(o.info(`Checking initial condition for element ID="${r}"`,{...s,waitCondition:typeof y=="function"?"callback":y,persistent:T}),await H()){o.info(`Initial content element already satisfied for element ID="${r}"`,s);let d=M();return(T||x)&&Y(),d}return new Promise(d=>{let m=Date.now(),f=null,b=null,v=!1;function p($){v||x&&(v=!0,f&&(clearTimeout(f),f=null),b&&(b.disconnect(),b=null,o.debug(`Disconnected MutationObserver for element ID="${r}"`,s)),d($))}f=setTimeout(()=>{o.warn(`Wait condition timeout after ${I}ms for element ID="${r}" \u2014 context element not yet in DOM`,{...s,timeoutReached:!0,waitCondition:typeof y=="function"?"callback":y}),p(null)},I),o.info(`Setting up MutationObserver for element ID="${r}"`,{...s,observerConfig:w,waitCondition:typeof y=="function"?"callback":y}),b=new MutationObserver(async $=>{if(!v&&(o.debug(`MutationObserver detected ${$.length} mutations for element ID="${r}"`,s),await H())){let P=Date.now()-m;o.info(`Wait condition satisfied via MutationObserver for element ID="${r}" after DOM changes`,{...s,elapsedTime:P});let ge=M();(T||x)&&Y(),p(ge)}});let E={childList:w.childList===!0,subtree:w.subtree===!0,attributes:w.attributes===!0,attributeOldValue:w.attributeOldValue===!0,characterData:w.characterData===!0,characterDataOldValue:w.characterDataOldValue===!0};b.observe(document.documentElement||document.body,E),o.debug(`Started MutationObserver monitoring for element ID="${r}"`,{...s,target:"document.documentElement"})})}function he(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)r.hasOwnProperty(n)&&(e[n]=r[n])}return e}function U(e,t){return Array(t+1).join(e)}function J(e){return e.replace(/^\n*/,"")}function Z(e){for(var t=e.length;t>0&&e[t-1]===` |
|
`;)t--;return e.substring(0,t)}function ee(e){return Z(J(e))}var be=["ADDRESS","ARTICLE","ASIDE","AUDIO","BLOCKQUOTE","BODY","CANVAS","CENTER","DD","DIR","DIV","DL","DT","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","FRAMESET","H1","H2","H3","H4","H5","H6","HEADER","HGROUP","HR","HTML","ISINDEX","LI","MAIN","MENU","NAV","NOFRAMES","NOSCRIPT","OL","OUTPUT","P","PRE","SECTION","TABLE","TBODY","TD","TFOOT","TH","THEAD","TR","UL"];function W(e){return j(e,be)}var te=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];function re(e){return j(e,te)}function ve(e){return ie(e,te)}var ne=["A","TABLE","THEAD","TBODY","TFOOT","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"];function ye(e){return j(e,ne)}function we(e){return ie(e,ne)}function j(e,t){return t.indexOf(e.nodeName)>=0}function ie(e,t){return e.getElementsByTagName&&t.some(function(r){return e.getElementsByTagName(r).length})}var g={};g.paragraph={filter:"p",replacement:function(e){return` |
|
|
|
`+e+` |
|
|
|
`}};g.lineBreak={filter:"br",replacement:function(e,t,r){return r.br+` |
|
`}};g.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,t,r){var n=Number(t.nodeName.charAt(1));if(r.headingStyle==="setext"&&n<3){var i=U(n===1?"=":"-",e.length);return` |
|
|
|
`+e+` |
|
`+i+` |
|
|
|
`}else return` |
|
|
|
`+U("#",n)+" "+e+` |
|
|
|
`}};g.blockquote={filter:"blockquote",replacement:function(e){return e=ee(e).replace(/^/gm,"> "),` |
|
|
|
`+e+` |
|
|
|
`}};g.list={filter:["ul","ol"],replacement:function(e,t){var r=t.parentNode;return r.nodeName==="LI"&&r.lastElementChild===t?` |
|
`+e:` |
|
|
|
`+e+` |
|
|
|
`}};g.listItem={filter:"li",replacement:function(e,t,r){var n=r.bulletListMarker+" ",i=t.parentNode;if(i.nodeName==="OL"){var a=i.getAttribute("start"),l=Array.prototype.indexOf.call(i.children,t);n=(a?Number(a)+l:l+1)+". "}var u=/\n$/.test(e);return e=ee(e)+(u?` |
|
`:""),e=e.replace(/\n/gm,` |
|
`+" ".repeat(n.length)),n+e+(t.nextSibling?` |
|
`:"")}};g.indentedCodeBlock={filter:function(e,t){return t.codeBlockStyle==="indented"&&e.nodeName==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"},replacement:function(e,t,r){return` |
|
|
|
`+t.firstChild.textContent.replace(/\n/g,` |
|
`)+` |
|
|
|
`}};g.fencedCodeBlock={filter:function(e,t){return t.codeBlockStyle==="fenced"&&e.nodeName==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"},replacement:function(e,t,r){for(var n=t.firstChild.getAttribute("class")||"",i=(n.match(/language-(\S+)/)||[null,""])[1],a=t.firstChild.textContent,l=r.fence.charAt(0),u=3,c=new RegExp("^"+l+"{3,}","gm"),h;h=c.exec(a);)h[0].length>=u&&(u=h[0].length+1);var k=U(l,u);return` |
|
|
|
`+k+i+` |
|
`+a.replace(/\n$/,"")+` |
|
`+k+` |
|
|
|
`}};g.horizontalRule={filter:"hr",replacement:function(e,t,r){return` |
|
|
|
`+r.hr+` |
|
|
|
`}};g.inlineLink={filter:function(e,t){return t.linkStyle==="inlined"&&e.nodeName==="A"&&e.getAttribute("href")},replacement:function(e,t){var r=t.getAttribute("href");r&&(r=r.replace(/([()])/g,"\\$1"));var n=S(t.getAttribute("title"));return n&&(n=' "'+n.replace(/"/g,'\\"')+'"'),"["+e+"]("+r+n+")"}};g.referenceLink={filter:function(e,t){return t.linkStyle==="referenced"&&e.nodeName==="A"&&e.getAttribute("href")},replacement:function(e,t,r){var n=t.getAttribute("href"),i=S(t.getAttribute("title"));i&&(i=' "'+i+'"');var a,l;switch(r.linkReferenceStyle){case"collapsed":a="["+e+"][]",l="["+e+"]: "+n+i;break;case"shortcut":a="["+e+"]",l="["+e+"]: "+n+i;break;default:var u=this.references.length+1;a="["+e+"]["+u+"]",l="["+u+"]: "+n+i}return this.references.push(l),a},references:[],append:function(e){var t="";return this.references.length&&(t=` |
|
|
|
`+this.references.join(` |
|
`)+` |
|
|
|
`,this.references=[]),t}};g.emphasis={filter:["em","i"],replacement:function(e,t,r){return e.trim()?r.emDelimiter+e+r.emDelimiter:""}};g.strong={filter:["strong","b"],replacement:function(e,t,r){return e.trim()?r.strongDelimiter+e+r.strongDelimiter:""}};g.code={filter:function(e){var t=e.previousSibling||e.nextSibling,r=e.parentNode.nodeName==="PRE"&&!t;return e.nodeName==="CODE"&&!r},replacement:function(e){if(!e)return"";e=e.replace(/\r?\n|\r/g," ");for(var t=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"",r="`",n=e.match(/`+/gm)||[];n.indexOf(r)!==-1;)r=r+"`";return r+t+e+t+r}};g.image={filter:"img",replacement:function(e,t){var r=S(t.getAttribute("alt")),n=t.getAttribute("src")||"",i=S(t.getAttribute("title")),a=i?' "'+i+'"':"";return n?"":""}};function S(e){return e?e.replace(/(\n+\s*)+/g,` |
|
`):""}function ae(e){this.options=e,this._keep=[],this._remove=[],this.blankRule={replacement:e.blankReplacement},this.keepReplacement=e.keepReplacement,this.defaultRule={replacement:e.defaultReplacement},this.array=[];for(var t in e.rules)this.array.push(e.rules[t])}ae.prototype={add:function(e,t){this.array.unshift(t)},keep:function(e){this._keep.unshift({filter:e,replacement:this.keepReplacement})},remove:function(e){this._remove.unshift({filter:e,replacement:function(){return""}})},forNode:function(e){if(e.isBlank)return this.blankRule;var t;return(t=V(this.array,e,this.options))||(t=V(this._keep,e,this.options))||(t=V(this._remove,e,this.options))?t:this.defaultRule},forEach:function(e){for(var t=0;t<this.array.length;t++)e(this.array[t],t)}};function V(e,t,r){for(var n=0;n<e.length;n++){var i=e[n];if(Ee(i,t,r))return i}}function Ee(e,t,r){var n=e.filter;if(typeof n=="string"){if(n===t.nodeName.toLowerCase())return!0}else if(Array.isArray(n)){if(n.indexOf(t.nodeName.toLowerCase())>-1)return!0}else if(typeof n=="function"){if(n.call(e,t,r))return!0}else throw new TypeError("`filter` needs to be a string, array, or function")}function Ne(e){var t=e.element,r=e.isBlock,n=e.isVoid,i=e.isPre||function(L){return L.nodeName==="PRE"};if(!(!t.firstChild||i(t))){for(var a=null,l=!1,u=null,c=K(u,t,i);c!==t;){if(c.nodeType===3||c.nodeType===4){var h=c.data.replace(/[ \r\n\t]+/g," ");if((!a||/ $/.test(a.data))&&!l&&h[0]===" "&&(h=h.substr(1)),!h){c=q(c);continue}c.data=h,a=c}else if(c.nodeType===1)r(c)||c.nodeName==="BR"?(a&&(a.data=a.data.replace(/ $/,"")),a=null,l=!1):n(c)||i(c)?(a=null,l=!0):a&&(l=!1);else{c=q(c);continue}var k=K(u,c,i);u=c,c=k}a&&(a.data=a.data.replace(/ $/,""),a.data||q(a))}}function q(e){var t=e.nextSibling||e.parentNode;return e.parentNode.removeChild(e),t}function K(e,t,r){return e&&e.parentNode===t||r(t)?t.nextSibling||t.parentNode:t.firstChild||t.nextSibling||t.parentNode}var G=typeof window<"u"?window:{};function ke(){var e=G.DOMParser,t=!1;try{new e().parseFromString("","text/html")&&(t=!0)}catch{}return t}function Te(){var e=function(){};return xe()?e.prototype.parseFromString=function(t){var r=new window.ActiveXObject("htmlfile");return r.designMode="on",r.open(),r.write(t),r.close(),r}:e.prototype.parseFromString=function(t){var r=document.implementation.createHTMLDocument("");return r.open(),r.write(t),r.close(),r},e}function xe(){var e=!1;try{document.implementation.createHTMLDocument("").open()}catch{G.ActiveXObject&&(e=!0)}return e}var Ce=ke()?G.DOMParser:Te();function $e(e,t){var r;if(typeof e=="string"){var n=Me().parseFromString('<x-turndown id="turndown-root">'+e+"</x-turndown>","text/html");r=n.getElementById("turndown-root")}else r=e.cloneNode(!0);return Ne({element:r,isBlock:W,isVoid:re,isPre:t.preformattedCode?De:null}),r}var _;function Me(){return _=_||new Ce,_}function De(e){return e.nodeName==="PRE"||e.nodeName==="CODE"}function Ae(e,t){return e.isBlock=W(e),e.isCode=e.nodeName==="CODE"||e.parentNode.isCode,e.isBlank=Se(e),e.flankingWhitespace=Oe(e,t),e}function Se(e){return!re(e)&&!ye(e)&&/^\s*$/i.test(e.textContent)&&!ve(e)&&!we(e)}function Oe(e,t){if(e.isBlock||t.preformattedCode&&e.isCode)return{leading:"",trailing:""};var r=Le(e.textContent);return r.leadingAscii&&Q("left",e,t)&&(r.leading=r.leadingNonAscii),r.trailingAscii&&Q("right",e,t)&&(r.trailing=r.trailingNonAscii),{leading:r.leading,trailing:r.trailing}}function Le(e){var t=e.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);return{leading:t[1],leadingAscii:t[2],leadingNonAscii:t[3],trailing:t[4],trailingNonAscii:t[5],trailingAscii:t[6]}}function Q(e,t,r){var n,i,a;return e==="left"?(n=t.previousSibling,i=/ $/):(n=t.nextSibling,i=/^ /),n&&(n.nodeType===3?a=i.test(n.nodeValue):r.preformattedCode&&n.nodeName==="CODE"?a=!1:n.nodeType===1&&!W(n)&&(a=i.test(n.textContent))),a}var Ie=Array.prototype.reduce,Re=[[/\\/g,"\\\\"],[/\*/g,"\\*"],[/^-/g,"\\-"],[/^\+ /g,"\\+ "],[/^(=+)/g,"\\$1"],[/^(#{1,6}) /g,"\\$1 "],[/`/g,"\\`"],[/^~~~/g,"\\~~~"],[/\[/g,"\\["],[/\]/g,"\\]"],[/^>/g,"\\>"],[/_/g,"\\_"],[/^(\d+)\. /g,"$1\\. "]];function O(e){if(!(this instanceof O))return new O(e);var t={rules:g,headingStyle:"setext",hr:"* * *",bulletListMarker:"*",codeBlockStyle:"indented",fence:"```",emDelimiter:"_",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",br:" ",preformattedCode:!1,blankReplacement:function(r,n){return n.isBlock?` |
|
|
|
`:""},keepReplacement:function(r,n){return n.isBlock?` |
|
|
|
`+n.outerHTML+` |
|
|
|
`:n.outerHTML},defaultReplacement:function(r,n){return n.isBlock?` |
|
|
|
`+r+` |
|
|
|
`:r}};this.options=he({},t,e),this.rules=new ae(this.options)}O.prototype={turndown:function(e){if(!Pe(e))throw new TypeError(e+" is not a string, or an element/document/fragment node.");if(e==="")return"";var t=oe.call(this,new $e(e,this.options));return Be.call(this,t)},use:function(e){if(Array.isArray(e))for(var t=0;t<e.length;t++)this.use(e[t]);else if(typeof e=="function")e(this);else throw new TypeError("plugin must be a Function or an Array of Functions");return this},addRule:function(e,t){return this.rules.add(e,t),this},keep:function(e){return this.rules.keep(e),this},remove:function(e){return this.rules.remove(e),this},escape:function(e){return Re.reduce(function(t,r){return t.replace(r[0],r[1])},e)}};function oe(e){var t=this;return Ie.call(e.childNodes,function(r,n){n=new Ae(n,t.options);var i="";return n.nodeType===3?i=n.isCode?n.nodeValue:t.escape(n.nodeValue):n.nodeType===1&&(i=He.call(t,n)),le(r,i)},"")}function Be(e){var t=this;return this.rules.forEach(function(r){typeof r.append=="function"&&(e=le(e,r.append(t.options)))}),e.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}function He(e){var t=this.rules.forNode(e),r=oe.call(this,e),n=e.flankingWhitespace;return(n.leading||n.trailing)&&(r=r.trim()),n.leading+t.replacement(r,e,this.options)+n.trailing}function le(e,t){var r=Z(e),n=J(t),i=Math.max(e.length-r.length,t.length-n.length),a=` |
|
|
|
`.substring(0,i);return r+a+n}function Pe(e){return e!=null&&(typeof e=="string"||e.nodeType&&(e.nodeType===1||e.nodeType===9||e.nodeType===11))}var se=O;var ce=/highlight-(?:text|source)-([a-z0-9]+)/;function Fe(e){e.addRule("highlightedCodeBlock",{filter:function(t){var r=t.firstChild;return t.nodeName==="DIV"&&ce.test(t.className)&&r&&r.nodeName==="PRE"},replacement:function(t,r,n){var i=r.className||"",a=(i.match(ce)||[null,""])[1];return` |
|
|
|
`+n.fence+a+` |
|
`+r.firstChild.textContent+` |
|
`+n.fence+` |
|
|
|
`}})}function Ve(e){e.addRule("strikethrough",{filter:["del","s","strike"],replacement:function(t){return"~"+t+"~"}})}var qe=Array.prototype.indexOf,_e=Array.prototype.every,C={};C.tableCell={filter:["th","td"],replacement:function(e,t){return ue(e,t)}};C.tableRow={filter:"tr",replacement:function(e,t){var r="",n={left:":--",right:"--:",center:":-:"};if(X(t))for(var i=0;i<t.childNodes.length;i++){var a="---",l=(t.childNodes[i].getAttribute("align")||"").toLowerCase();l&&(a=n[l]||a),r+=ue(a,t.childNodes[i])}return` |
|
`+e+(r?` |
|
`+r:"")}};C.table={filter:function(e){return e.nodeName==="TABLE"&&X(e.rows[0])},replacement:function(e){return e=e.replace(` |
|
|
|
`,` |
|
`),` |
|
|
|
`+e+` |
|
|
|
`}};C.tableSection={filter:["thead","tbody","tfoot"],replacement:function(e){return e}};function X(e){var t=e.parentNode;return t.nodeName==="THEAD"||t.firstChild===e&&(t.nodeName==="TABLE"||Ue(t))&&_e.call(e.childNodes,function(r){return r.nodeName==="TH"})}function Ue(e){var t=e.previousSibling;return e.nodeName==="TBODY"&&(!t||t.nodeName==="THEAD"&&/^\s*$/i.test(t.textContent))}function ue(e,t){var r=qe.call(t.parentNode.childNodes,t),n=" ";return r===0&&(n="| "),n+e+" |"}function We(e){e.keep(function(r){return r.nodeName==="TABLE"&&!X(r.rows[0])});for(var t in C)e.addRule(t,C[t])}function je(e){e.addRule("taskListItems",{filter:function(t){return t.type==="checkbox"&&t.parentNode.nodeName==="LI"},replacement:function(t,r){return(r.checked?"[x]":"[ ]")+" "}})}function fe(e){e.use([Fe,Ve,We,je])}function de(e){if(!e||typeof e!="string")return"";let t=new se({headingStyle:"atx",bulletListMarker:"-",codeBlockStyle:"fenced",emDelimiter:"*",strongDelimiter:"**"});t.use(fe),t.escape=n=>n.replace(/\\/g,"\\\\").replace(/\*/g,"\\*").replace(/_/g,"\\_").replace(/^\-/gm,"\\-").replace(/^#/gm,"\\#").replace(/\[/g,"\\[").replace(/\]/g,"\\]").replace(/^>/gm,"\\>").replace(/`/g,"\\`").replace(/^~~~/gm,"\\~~~"),t.addRule("listItem",{filter:"li",replacement:(n,i,a)=>{n=n.replace(/^\n+/,"").replace(/\n+$/,` |
|
`).replace(/\n/gm,` |
|
`);let l=`${a.bulletListMarker} `,u=i.parentNode;if(u&&u.nodeName==="OL"){let c=u.getAttribute("start"),h=Array.prototype.indexOf.call(u.children,i);l=`${c?parseInt(c,10)+h:h+1}. `}return l+n+(i.nextSibling&&!/\n$/.test(n)?` |
|
`:"")}}),t.addRule("quillIndentedListItem",{filter:n=>n.nodeName==="LI"&&typeof n.className=="string"&&/ql-indent-\d+/.test(n.className),replacement:(n,i)=>{let a=i.className.match(/ql-indent-(\d+)/),l=a?parseInt(a[1],10):0;return` |
|
${" ".repeat(l)}- ${n.trim()}`}});let r=document.createElement("div");return A(r,e),t.turndown(r).trim()}(function(){"use strict";GM_addStyle(` |
|
button#copy-note-to-markdown-btn { |
|
background-color: #fff !important; |
|
margin-right: 4px !important; |
|
} |
|
button#copy-note-to-markdown-btn:hover { |
|
background-color: #f0f0f0 !important; |
|
} |
|
button#copy-note-to-markdown-btn:active { |
|
background-color: #e0e0e0 !important; |
|
} |
|
.note-header__notices { |
|
display: flex; |
|
justify-content: space-between; |
|
align-items: center; |
|
} |
|
`);let e=D({prefix:"UserScript",namespace:"[CopyNoteToMarkdown]"});z({tagName:"button",namespace:"[CopyNoteToMarkdown]",id:"copy-note-to-markdown-btn",insertionMethod:"append",persistent:!0,attributes:{title:"Copy Note as Markdown",style:"all:unset;cursor:pointer;display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:4px;padding:2px;"},parentSelector:".note-header__notices",contextElement:".note-header__notices",innerHTML:`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy" style="width:20px;height:20px;"> |
|
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect> |
|
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path> |
|
</svg>`,onMount:t=>{t.addEventListener("click",async()=>{try{e.debug("Searching for editor element...");let r=null;if(r=document.querySelector(".editor.ql-container"),r)e.info("Found editor with original selector '.editor.ql-container'");else{if(e.error("Original selector '.editor.ql-container' not found"),r=document.querySelector("labs-tailwind-doc-viewer"),r)e.info("Found editor with selector 'labs-tailwind-doc-viewer'");else{let a=["labs-tailwind-doc-viewer","note-editor labs-tailwind-doc-viewer",".ql-editor",".editor","[contenteditable='true']",".note-content",".note-editor",".rich-text-editor",".prosemirror-editor","form labs-tailwind-doc-viewer","note-editor form labs-tailwind-doc-viewer"];for(let l of a){let u=document.querySelector(l);if(u){e.info(`Found editor with alternative selector: ${l}`),r=u;break}}}if(!r){let a=document.querySelectorAll('[class*="editor"]');e.debug(`Found ${a.length} elements with 'editor' in class:`,Array.from(a).map(c=>({tagName:c.tagName,className:c.className,id:c.id})));let l=document.querySelectorAll('[class*="ql-container"]');e.debug(`Found ${l.length} elements with 'ql-container' in class:`,Array.from(l).map(c=>({tagName:c.tagName,className:c.className,id:c.id})));let u=document.querySelectorAll("labs-tailwind-doc-viewer");e.debug(`Found ${u.length} labs-tailwind-doc-viewer elements:`,Array.from(u).map(c=>({tagName:c.tagName,className:c.className,id:c.id,innerHTML:c.innerHTML.substring(0,100)+"..."})))}if(!r){e.error("Editor not found with any selector");return}}let n=r.innerHTML;r.tagName.toLowerCase()==="labs-tailwind-doc-viewer"&&(n=(r.querySelector(".ql-editor")||r.querySelector('[contenteditable="true"]')||r.querySelector(".editor")||r).innerHTML);let i=de(n);await navigator.clipboard.writeText(i),e.log("Note content copied as Markdown to clipboard")}catch(r){e.error("Failed to copy note content:",r)}})}})})();})(); |
I think there may have some changes in the NotebookLM page that caused the script to not work anymore, it also had some lint errors.
I have fixed it, keep the credits: https://gist.github.com/heltonteixeira/116237abb54e2b55d519056a31d5d6b4