Created
June 5, 2025 20:18
-
-
Save lwcorp/fd1a4057f49af843ff9b0be7bc2708d7 to your computer and use it in GitHub Desktop.
Bookmarklet - Pmfm.ai app bot bulk link adder to knowledge base
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:function allowMultipleURLs(){const a="#externalMultiple";if(document.querySelector("#datatab").click(),document.querySelector(a))return;document.querySelector("#tab1-url-tab").click();const b=document.querySelector("#tab1-url-content"),c=b.parentNode,d=b.cloneNode(!0);for(d.id=a.substring(1);3<d.children.length;)d.removeChild(d.lastChild);const e=d.lastElementChild,f=d.querySelectorAll("*");f.forEach(a=>{const b=a.classList,c=a.attributes;for(let b=c.length-1;0<=b;b--)"class"!==c[b].name&&a.removeAttribute(c[b].name);if("INPUT"===a.tagName&&"text"===a.type){const b=document.createElement("textarea");b.id="externalURLs",b.className=a.className,a.parentNode.replaceChild(b,a)}"LABEL"===a.tagName&&(a.textContent="Enter multiple URLs")}),e&&(e.id="external-error");const g=document.createElement("sub");g.id="externalProgress",d.insertBefore(g,d.firstChild),c.insertBefore(d,b);const h=d.querySelector("button");h&&h.setAttribute("onclick","ExternalBTNs(); return false;")}async function ExternalBTNs(){const a=!1,b=!1,c=/\/\/([^\/]*)/,d="input + button",e=10,f=.5,g="#url-error-message",h="hidden",i=document.querySelector("#externalURLs"),j=[...new Set(i.value.trim().split("\n").filter(a=>""!==a))],k=document.querySelector("#external-error");if(0===j.length){for(k.classList.add(h);;){const c=Array.from(document.querySelectorAll(d));if(2>c.length)break;const g=c[c.length-1];if(b){console.log("Would have clicked",g);break}else if(a){const a=c.length;g.click();const b=Date.now();let h=!0;for(;Date.now()-b<1e3*e;){const b=Array.from(document.querySelectorAll(d));if(b.length<a){h=!1;break}await new Promise(a=>setTimeout(a,1e3*f))}if(h){alert("Timeout waiting for deleting links");break}}else g.click()}return}k.classList.add(h);let l=0;urlLoop:for(const k of j){document.querySelector(g).textContent="";const m=document.querySelector(d).previousElementSibling;m.value=k;const n=Array.from(document.querySelectorAll(d));0<n.length&&n[0].click(),m.value="";const o=Date.now();let p=!0;for(;Date.now()-o<1e3*e;){const i=document.querySelector(g);if(i&&!i.classList.contains(h)&&i.textContent.split(" ")[0]==="Error"){if(a)return void alert("Error detected during URL processing");continue urlLoop}const j=Array.from(document.querySelectorAll(d));if(j.length>n.length){p=!1;for(let g=!1;!g;){const h=Array.from(document.querySelectorAll(d));if(2>h.length){g=!0;break}const i=h[h.length-1],j=i.previousElementSibling,k=h[h.length-2],l=k.previousElementSibling,m=j.value,n=l.value,o=m.match(c),p=n.match(c);if(!(o&&p&&o[1]===p[1]))g=!0;else if(b)console.log("Would have clicked",i),g=!0;else if(a){const a=h.length;i.click();const b=Date.now();let c=!0;for(;Date.now()-b<1e3*e;){const b=Array.from(document.querySelectorAll(d));if(b.length<a){c=!1;break}await new Promise(a=>setTimeout(a,1e3*f))}if(c)return void alert("Timeout waiting for deleting links")}else i.click()}break}await new Promise(a=>setTimeout(a,1e3*f))}if(a&&p)return void alert("Timeout waiting for generating links");if(!p){l++;const a=document.getElementById("externalProgress");a.textContent=`${l} / ${j.length} (${Math.round(100*(l/j.length))}%) - missing ${j.length-l} (${Math.round(100*((j.length-l)/j.length))}%)`;const b=i.value.split("\n"),c=b.filter(a=>""!==a.trim()&&a!==k);i.value=c.join("\n")}}}allowMultipleURLs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment