GameFAQs-Avatars

Avatars for GameFAQs

  1. // ==UserScript==
  2. // @name GameFAQs-Avatars
  3. // @Author Judgmenl
  4. // @namespace Kraust
  5. // @description Avatars for GameFAQs
  6. // @include *.gamefaqs.com/*
  7. // @version 3.0.2
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /****************************************************************************
  12. * 3.x.x will be a fork for the NEW Board Engine. It will NOT support *
  13. * Throwback or post-Throwback. *
  14. ***************************************************************************/
  15.  
  16. /****************************************************************************
  17. * Disclaimer: This product is given as is, and anyone who many want to use *
  18. * It is free to with my permission. If you need to contact me for any *
  19. * reason please send me a message over on GameFAQs. I've tried to make it *
  20. * so that in later versions of the script that people with a jQuery *
  21. * background can understand what's going on here. *
  22. ****************************************************************************/
  23. /****************************************************************************
  24. * As of 2.5.4 I'm working on re-writing a lot of this code *
  25. * due to a lot of suggestions on Blood Money. *
  26. * Thanks to OTACON120, P4wn4g3, and Corrupt_Power *
  27. ****************************************************************************/
  28. // storage stuff
  29. if(typeof(Storage)!=="undefined") {
  30. var storage = localStorage.getItem("avatar");
  31. } else {
  32. var storage = "left";
  33. }
  34.  
  35.  
  36. // we need jQuery for this.
  37. if(jQuery) {
  38.  
  39. // link to avatar settings. This goes on every page.
  40. $(".masthead_user").prepend("<a href='/boards/user.php?upload=1'>Avatar Settings <i class='icon icon-picture'></i></a> ");
  41.  
  42. if((decodeURIComponent((new RegExp('[?|&]' + "upload" + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20')) == "1") && (location.pathname == "/boards/user.php")) {
  43. // This block is for http://www.gamefaqs.com/boards/user.php?upload=1 Note the upload=1.
  44. var user = $("html.js body.wf-active div.wrapper div#mantle_skin div#content.container div.main_content div.span8 div.body table.board tbody tr td").eq(0).text();
  45. // GameWeasel Fix
  46. if( user == "") {
  47. var user = $("#content > div > div > div.body > table > tbody > tr:nth-child(1) > td").text();
  48. }
  49. console.log(user);
  50. var upload_user = user + " ";
  51.  
  52. $(".page-title").html("GameFAQs Avatars");
  53. $(".userinfo").css("border", "none");
  54. // Preparing for the Upload UI
  55. $("tbody").empty();
  56. // Renders the Upload UI
  57. if( user ) {
  58. $("tbody").append("<div style='float:left; width:100px; height:100px;'><img class='avatar' src='http://www.nostlagiasky.pw/gamefaqs-avatars/avatars/" + user + ".png' alt='' ></div>" );
  59. $("tbody").append("<div style='float:left; padding-left:10px'><h4>Global Avatar Settings</h4> <ul id=settings class='paginate user' style='margin:0;padding:0;'> \
  60. <li><a href='' id='av_left'>Avatars to the Left</a></li><li><a href='' id='av_right'>Avatars to the Right</a></li><li><a href='' id='av_no'>No Avatars</a></li></ul> \
  61. <form id='submit' method='POST' enctype='multipart/form-data' > \
  62. <input class='btn' type='file' name='file' accept='image/*' id='file'> \
  63. <input class='btn btn_primary' type='button' id='submit_btn' value='Upload'> \
  64. <input style='display:none' type='text' name='dest' value='GameFAQs-Avatars'> \
  65. <input style='display:none' type='text' name='user' value='" + upload_user + "'> \
  66. <span id='server_message'>Maximum File Size: 100KB</span> \
  67. </form></div>");
  68. $("tbody").append("<div style='clear:both;padding-left:10px;padding-top:30px;'>Your signature will be changed during the upload process and will be restored after it completes");
  69.  
  70. // Update Notes are down here.
  71. $("tbody").append("<div style='clear:both;padding-left:10px;padding-top:30px;'><h4>Version 2.5.6</h4>+ New Validation Method</div>");
  72.  
  73. $("tbody").append("<div style='clear:both;padding-left:10px;padding-top:30px;'><a href='http://www.nostlagiasky.pw/gamefaqs-avatars/' target='_blank'>GameFAQs Avatars</a> created by <a href='http://www.gamefaqs.com/users/Judgmenl/boards'>Judgmenl</a> - 2015.</div>");
  74. $("tbody").append("<div style='clear:both;padding-left:10px;padding-top:0px;'>A listing of avatars can be located <a href='http://www.nostlagiasky.pw/gamefaqs-avatars/avatars/' target='_blank'>here</a>.</div>");
  75.  
  76. }
  77. /* error checking when handling the upload */
  78.  
  79. $("#file").change(function() {
  80. var file = this.files[0];
  81. var size = file.size;
  82. var type = file.type;
  83. if( !type.match(/image.*/) ) {
  84. $("#submit_btn").css("display", "none");
  85. $("#server_message").html("Invalid File Type");
  86. return;
  87. }
  88. if( size > 102400 ) {
  89. $("#submit_btn").css("display", "none");
  90. $("#server_message").html("Image is too big (" + size/1024 + "KB). 100KB maximum.");
  91. return;
  92. }
  93. if( !user ) {
  94. $("#submit_btn").css("display", "none");
  95. $("#server_message").html("Log in to upload avatars.");
  96. }
  97. $("#submit_btn").css("display", "inline");
  98. $("#server_message").html("OK");
  99.  
  100. });
  101. /* ajax request to handle the upload */
  102.  
  103. $("#submit_btn").click( function() {
  104. var formData = new FormData($('#submit')[0]);
  105. $("#server_message").html("backing up signature...");
  106.  
  107. $.ajax
  108. ({
  109. type: "POST",
  110. url: "/boards/sigquote.php",
  111. async: false,
  112. })
  113. .done(function(response)
  114. {
  115. var sig = $(response).find("#sig").text();
  116. var quote = $(response).find("#quote").text();
  117. var key = $(response).find("input[name=key]").eq(0).attr("value");
  118. var sigpost = $(response).find("#add").attr("action");
  119. //console.log(sig);
  120. //console.log(key);
  121. //console.log(sigpost);
  122.  
  123.  
  124. if((sig == "upload:ok") || (sig == "avatarupload:true"))
  125. {
  126. // replace old signature
  127. sig = "";
  128. }
  129.  
  130. $("#server_message").html("Sending permission to change sig");
  131.  
  132. $.ajax
  133. ({
  134. type: "POST",
  135. url: sigpost,
  136. data: "key=" + key + "&sig=" + "avatarupload:true" + "&quote=" + quote + "&submit=Change Settings",
  137. })
  138. .done(function(response)
  139. {
  140.  
  141. $("#server_message").html("Uploading...");
  142.  
  143. $.ajax( {
  144. url: "http://www.nostlagiasky.pw/gamefaqs-avatars/upload-v2.php",
  145. dataType: "html",
  146. type: "POST",
  147. data: formData,
  148. processData: false,
  149. contentType: false,
  150. async: false
  151. }).done(function( data ) {
  152. if( data == 'Upload Successful! Refreshing to apply changes...')
  153. {
  154. $.ajax
  155. ({
  156. type: "POST",
  157. url: sigpost,
  158. data: "key=" + key + "&sig=" + sig + "&quote=" + quote + "&submit=Change Settings",
  159. })
  160. .done(function(response)
  161. {
  162. //console.log("Sig changed back.");
  163. $("#server_message").html(data);
  164. location.href = "http://www.gamefaqs.com/boards/user.php?settings=1#tabs-2";
  165. location.reload(true);
  166. });
  167.  
  168. }
  169. else
  170. {
  171. $.ajax
  172. ({
  173. type: "POST",
  174. url: sigpost,
  175. data: "key=" + key + "&sig=" + sig + "&quote=" + quote + "&submit=Change Settings",
  176. }).done(function(response)
  177. {
  178. //console.log("Sig changed back.");
  179. });
  180. $("#server_message").html(data);
  181. }
  182. }).error(function() {
  183. $.ajax
  184. ({
  185. type: "POST",
  186. url: sigpost,
  187. data: "key=" + key + "&sig=" + sig + "&quote=" + quote + "&submit=Change Settings",
  188. })
  189. .done(function(response)
  190. {
  191. //console.log("Sig changed back.");
  192. });
  193. $("#server_message").html("Avatar not uploaded to nostlagiasky domain. Service may be unavailable.");
  194. });
  195. });
  196.  
  197. });
  198.  
  199. });
  200. /* storage setters */
  201. $("#av_left").click( function() {
  202. localStorage.setItem("avatar", "left");
  203. });
  204. $("#av_right").click( function() {
  205. localStorage.setItem("avatar", "right");
  206. });
  207. $("#av_no").click( function() {
  208. localStorage.setItem("avatar", "no");
  209. });
  210.  
  211.  
  212. } else if((window.location.pathname.indexOf("\/users\/") > -1) && window.location.pathname.indexOf("\/boards") > -1) {
  213. // This block is for http://www.gamefaqs.com/users/<username>/boards
  214. // It handles the avatars in profiles code.
  215.  
  216. var userName = $("#content > div > div > div > table > tbody > tr:nth-child(1) > td:nth-child(2)").text();
  217.  
  218. $(".span4 > .body").prepend(" \
  219. <div class='pod'> \
  220. <div class='head'><h2 class='title'>" + userName + "'s Avatar</h2></div> \
  221. <div class='body'> \
  222. <div class='details'> \
  223. <img src='http://www.nostlagiasky.pw/gamefaqs-avatars/avatars/" + userName + ".png' alt=''> \
  224. </div> \
  225. </div> \
  226. <div class='foot'></div> \
  227. </div>");
  228. $('img').error(function() {
  229. $(this).remove();
  230. });
  231. } else {
  232. // This is what renders the avatars on a post by post basis.
  233. var msgCount = $("td.msg").length;
  234.  
  235. if ( storage == "no" ) {
  236. // no avatars.
  237. } else if (storage == "right" ) {
  238.  
  239. $(".msg_body").each(function( index )
  240. {
  241. var user = $(".name").eq(index).text().slice(0,-1);
  242. $(this).prepend("<div style='float:right;padding-left:.5em'><img src='http://nostlagiasky.pw/gamefaqs-avatars/avatars/" + user +".png' /></div>");
  243. });
  244.  
  245.  
  246.  
  247. } else {
  248.  
  249.  
  250. $(".msg_body").each(function( index )
  251. {
  252. var user = $(".name").eq(index).text().slice(0,-1);
  253. $(this).prepend("<div style='float:left;padding-right:.5em'><img src='http://nostlagiasky.pw/gamefaqs-avatars/avatars/" + user +".png' /></div>");
  254. });
  255.  
  256.  
  257.  
  258. }
  259. }
  260.  
  261. $('img').error(function() {
  262. $(this).remove();
  263. });
  264. } else {
  265. alert("GameFAQs Avatars requires jQuery to be present. It should be prsent by default. Make sure you're not blocking it with a third party addon like NoScript.");
  266. }