1class Batcher { 2 transactionsList = []; 3 timeout = 1000; 4 pluginId = ""; 5 paymentPointer = ""; 6 verifyAddress = ""; 7 8 setVerifyAddress(value) { 9 this.verifyAddress = value; 10 } 11 12 setPluginId(value) { 13 this.pluginId = value; 14 } 15 16 setPaymentPointer(value) { 17 this.paymentPointer = String(value).trim(); 18 } 19 20 add(event) { 21 this.transactionsList.push(event); 22 } 23 24 async scheduleFlush() { 25 return new Promise((resolve) => { 26 setTimeout(() => { 27 this.flush().then(() => { 28 resolve(); 29 this.scheduleFlush(); 30 }); 31 }, this.timeout); 32 }); 33 } 34 35 async flush() { 36 const batch = this.transactionsList.map(({ date, value }) => ({ 37 date, 38 value, 39 })); 40 if (batch.length === 0) { 41 return; 42 } 43 const totalValue = this.transactionsList.reduce( 44 (previousValue, currentValue) => previousValue + currentValue.value, 45 0 46 ); 47 const data = { 48 pluginId: this.pluginId, 49 paymentPointer: this.paymentPointer, 50 date: new Date().getTime(), 51 totalValue: totalValue, 52 transactions: this.transactionsList, 53 }; 54 await fetch( 55 `https://94w4fmrdq3.execute-api.us-east-1.amazonaws.com/Dev/api/transactions`, 56 { 57 method: "POST", 58 body: JSON.stringify(data), 59 headers: { 60 "Content-Type": "application/json", 61 }, 62 } 63 ); 64 this.transactionsList = []; 65 } 66} 67 68class VerifyAddress { 69 verifyAddress = ""; 70 71 setVerifyAddress(value) { 72 this.verifyAddress = value; 73 } 74 async verifyAddressRequest() { 75 return true; 76 // const data = { 77 // sender_wallet_address: verifyAddress, 78 // receiver_wallet_address: "", 79 // expected_amount: "", 80 // }; 81 82 // await fetch( 83 // `https://94w4fmrdq3.execute-api.us-east-1.amazonaws.com/Dev/api/openpayments/validate-payment`, 84 // { 85 // method: "POST", 86 // body: JSON.stringify(data), 87 // headers: { 88 // "Content-Type": "application/json", 89 // }, 90 // } 91 // ).then((response) => { 92 // if (!response.ok) { 93 // throw new Error("Network response was not ok"); 94 // } 95 // return response.json(); 96 // }); 97 } 98} 99 100jQuery(function ($) { 101 console.log(plugin_infos.version); 102 103 function setupMetaTag(pointer) { 104 $("head").append(pointer); 105 } 106 107 function setupPremiumConsumer() { 108 $("body").toggleClass("blur"); 109 $("body").append( 110 `<div class="main-container"> 111 <div class="main-container-child"> 112 <label class="paywall-title">Sorry :/</label> 113 <label>This content is web monetized,</label> 114 <label>set up a wallet to see this content!</label> 115 <img src="` + 116 images_variables.icon_eye_url + 117 `" /> 118 <br /> 119 <label>Insert your wallet address bellow.</label> 120 <br /> 121 <input class="pointer-input" type="text" id="verify_address" name="verify_address" placeholder="https://wallet.example.com/gabriel"> 122 <button type="button" id="verify_address_button" name="add-remove-row" class="default-button"> 123 Pay $5 124 </button> 125 <br /> 126 <label>Access <a href="https://www.pipewebmonetization.com/" target="_blank">Pipe Web Monetization</a> for more information.</label> 127 </div>` 128 ); 129 } 130 131 function setupPaywall() { 132 $("body").toggleClass("blur"); 133 $("body").append( 134 `<div class="main-container"> 135 <div class="main-container-child"> 136 <label class="paywall-title">Sorry :/</label> 137 <label>This content is web monetized,</label> 138 <label>set up a wallet to see this content!</label> 139 <img src="` + 140 images_variables.icon_eye_url + 141 `" /> 142 <label>Access <a href="https://www.pipewebmonetization.com/" target="_blank">Pipe Web Monetization</a> for more information.</label> 143 <div class="default-button"> 144 <a class="button-link" href="https://www.pipewebmonetization.com/" target="_blank" class="default-button"> 145 Learn More 146 </a> 147 </div> 148 </div>` 149 ); 150 } 151 152 function removePaywall() { 153 $("body").removeClass("blur"); 154 $(".main-container").remove(); 155 } 156 157 $(document).on("click", "#verify_address_button", function () { 158 console.log($("#verify_address").val()); 159 160 const verifyAddress = new VerifyAddress(); 161 162 verifyAddress.setVerifyAddress($("#verify_address").val()); 163 if (verifyAddress.verifyAddressRequest()) { 164 removePaywall(); 165 } 166 }); 167 168 // if (!ajax_variables.logged_in) { 169 setupMonetizationListeners(); 170 // } 171 172 async function setupMonetizationListeners() { 173 const batcher = new Batcher(); 174 175 batcher.setPluginId(plugin_options.pwm_plugin_id); 176 batcher.setPaymentPointer( 177 document.querySelector('link[rel="monetization"]').getAttribute("href") 178 ); 179
180 if (post_infos.post_categories) { 181 post_infos.post_categories.forEach((category) => { 182 if (category.slug == "pipe-category" && post_infos.is_home != "1") { 183 setupPaywall(); 184 } 185 }); 186 } 187 188 if (post_infos.post_categories) { 189 post_infos.post_categories.forEach((category) => { 190 if ( 191 category.slug == "premium-consumer-category" && 192 post_infos.is_home != "1" 193 ) { 194 setupPremiumConsumer(); 195 } 196 }); 197 } 198 199 // if (!document.monetization) { 200 // return; 201 // } 202 203 const link = document.querySelector('link[rel="monetization"]'); 204 link.addEventListener("monetization", (event) => { 205 removePaywall(); 206 console.log(event); 207 batcher.add({ 208 date: new Date().getTime(), 209 value: Number(event.amountSent.amount), 210 postId: post_infos.is_home != "1" ? post_infos.post_id : "", 211 postTitle: post_infos.is_home != "1" ? post_infos.post_title : "", 212 }); 213 }); 214 215 batcher.scheduleFlush(); 216 } 217 218 function simulateMonetization() { 219 if (document.monetization) { 220 const randomGuid = "c7ff7da9-8a41-4660-98a8-ca4df0176fbe"; 221 222 const meta = document.querySelector('meta[name="monetization"]'); 223 let metaContent = null; 224 if (meta) { 225 metaContent = meta.getAttribute("content"); 226 } 227 228 if (metaContent) { 229 const resolvedEndpoint = metaContent.replace(/^\$/, "https://"); 230 231 const monetizationstartEvent = new CustomEvent("monetizationstart", { 232 detail: { 233 requestId: randomGuid, 234 id: randomGuid, 235 metaContent, 236 resolvedEndpoint, 237 }, 238 }); 239 240 const monetizationprogressEvent = new CustomEvent( 241 "monetizationprogress", 242 { 243 detail: { 244 amount: "200000", 245 assetCode: "USD", 246 assetScale: 9, 247 }, 248 } 249 ); 250 251 document.monetization.dispatchEvent(monetizationstartEvent); 252 document.monetization.dispatchEvent(monetizationprogressEvent); 253 254 setInterval(() => { 255 document.monetization.dispatchEvent(monetizationprogressEvent); 256 }, 6000); 257 } else { 258 alert("monetization meta tag is not correctly configured."); 259 } 260 } 261 } 262});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.