-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbulk-make-offer-fav.js
1 lines (1 loc) · 2.78 KB
/
bulk-make-offer-fav.js
1
javascript: (function(){let a=document.createElement("div");a.innerHTML=`<div id="nb-hda-makeOffer" style=" position: absolute; background: rgba(0, 0, 0, 0.288); top: 0; bottom: 0; left: 0; right: 0; z-index: 999; display: flex; flex-direction: column; justify-content: center; align-items: center;"> <div id="nb-hda-makeOffer-content" style="display: flex; flex-direction: column; background: white; min-width: 500px; padding: 1em; border-radius: .5em;" ></div></div>`,document.getElementsByTagName("body")[0].append(a);let c=document.getElementById("nb-hda-makeOffer-content"),d=()=>{for(;c.firstChild;)c.removeChild(c.lastChild)},e,b=()=>{console.log("here"),d();let a=document.createElement("div");a.innerHTML='<div id="nb-hda-makeOffer-preparation"> <div> <label><span style="display:flex;">Offers to make</span><textarea id="nb-hda-makeOffer-input" style="width:100%; min-width:500px"></textarea> </label> </div><div style="margin-top:.5em;"> <button id="nb-hda-makeOffer-cancel">Cancel</button> <button id="nb-hda-makeOffer-submit">Submit</button> </div></div>',c.append(a.firstChild),document.getElementById("nb-hda-makeOffer-input").value=e??"";let b=document.getElementById("nb-hda-makeOffer-submit");b.onclick=()=>{e=document.getElementById("nb-hda-makeOffer-input").value,i()};let g=document.getElementById("nb-hda-makeOffer-cancel");g.onclick=()=>f()},f=()=>{a.remove()},g,h=!1,i=async()=>{g=e.replace(/\r/g,"").split("\n").map(b=>{let a=b.split(",");return{name:a[0],amount:a[1]}}),d();let a=document.createElement("div"),f=g.map(a=>`<tr><td>${a.name}</td><td>${a.amount}</td><td id="nb-hda-makeOffer-sent-${a.name}">${a.sent?"true":""}</td></tr>`).join("");a.innerHTML=`<div id="nb-hda-makeOffer-confirmation"><table style="border: 1px solid black;width: 100%; text-align: left;border-spacing: .5em;"> <thead> <th>Name</th> <th>Amount</th> <th>Sent</th> </thead> <tbody>${f}</tbody> </table><div style="margin-top:.5em;"> <button id="nb-hda-makeOffer-cancel">Cancel</button> <button id="nb-hda-makeOffer-submit">Submit</button> </div></div>`,c.append(a);let i=document.getElementById("nb-hda-makeOffer-submit");i.onclick=()=>{confirm("Are you sure you want to send those offers ?")&&k()};let l=document.getElementById("nb-hda-makeOffer-cancel");l.onclick=()=>{h?j=!0:(g=void 0,b())}},j=!1,k=async()=>{for(let a of(h=!0,g.filter(a=>!a.sent))){if(j){h=!1;break}await l(a.name,a.amount).then(b=>a.sent=!0).catch(a=>alert(a.message)),document.getElementById(`nb-hda-makeOffer-sent-${a.name}`).innerHTML="true",await new Promise(a=>setTimeout(()=>{a()},100))}!j&&confirm("All done ! Exit ?")&&f()},l=async(a,b)=>{await fetch("https://www.namebase.io/api/v0/marketplace/"+a+"/bid",{credentials:"include",headers:{Accept:"application/json","Content-Type":"application/json"},body:'{"buyOfferAmount":"'+b+'"}',method:"POST"})};b()})()