Skip to content

Instantly share code, notes, and snippets.

@GeonoTRON2000
Created July 29, 2017 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeonoTRON2000/7f8ede2a6f5db7bb7eee68e1e4452333 to your computer and use it in GitHub Desktop.
Save GeonoTRON2000/7f8ede2a6f5db7bb7eee68e1e4452333 to your computer and use it in GitHub Desktop.
A plugin to allow users to insert functional "Buy Now" buttons into a forum using Cash Mod.
var me = document.getElementById("brdwelcome").getElementsByTagName("strong")[0].innerHTML;
var j;
var posts = document.getElementsByClassName("postmsg");
for (j = 0; j < posts.length; j++) {
var post = posts[j];
var thishtml = post.innerHTML;
var buttons = [];
var i;
for (i = 0; i < thishtml.split("[buynow]").length-1; i++) {
buttons[i] = thishtml.split("[buynow]")[i+1].split("[/buynow]")[0];
}
for (i = 0; i < buttons.length; i++) {
var username = buttons[i].split(",")[0];
var amount = buttons[i].split(",")[1];
if (amount != "x")
thishtml = thishtml.replace(/\[buynow\](.+?)\[\/buynow\]/i, "<form action=\"donate.php\" method=\"post\">\r\n<div style=\"display: none !important;\"><input type=\"submit\" name=\"submit\" value=\"Donate\" /></div>\r\n<input type=\"hidden\" name=\"username\" value=\""+username.replace(/"/g, "\'")+"\" />\r\n<input type=\"hidden\" name=\"amount\" value=\""+parseInt(amount)+"\" />\r\n<input type=\"button\" value=\"Buy Now\" onclick=\"if (window.confirm('Do you really want to buy this item from "+username+" for $"+amount+"?')) { this.form.submit.click(); }\">\r\n</form>");
else
thishtml = thishtml.replace(/\[buynow\](.+?)\[\/buynow\]/i, "<form action=\"donate.php\" method=\"post\">\r\n<div style=\"display: none !important;\"><input type=\"submit\" name=\"submit\" value=\"Donate\" /></div>\r\n<input type=\"hidden\" name=\"username\" value=\""+username.replace(/"/g, "\'")+"\" />\r\n<input type=\"hidden\" name=\"amount\" value=\""+parseInt(amount)+"\" />\r\n<input type=\"button\" value=\"Buy Now\" onclick=\"var amt=parseInt(window.prompt('Enter amount to pay:'))+''; this.form.amount.value=amt; if (window.confirm('Do you really want to buy this item from "+username+" for however much you entered?')) { this.form.submit.click(); }\">\r\n</form>");
}
post.innerHTML = thishtml;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment