Gamefaqs Quick PM

PM from within topic in gamefaqs

  1. // ==UserScript==
  2. // @name Gamefaqs Quick PM
  3. // @namespace N-eil
  4. // @version 0.9
  5. // @description PM from within topic in gamefaqs
  6. // @include *.gamefaqs.com/boards/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. var key; //Gfaqs has a hidden field called "key" that is required to be filled with a certain code(different for each user) in order to post/edit/pm
  11.  
  12. if(document.getElementsByName('key').length) //Look for the key on the page: quickposting is enabled
  13. {
  14. key = document.getElementsByName('key')[0].value;
  15. addLinks();
  16. }
  17. else
  18. {
  19. $.post("/boards/post.php?board=" + boardID + "&topic=" + topicID, {}).done(function(response){ //Otherwise, look for the key requesting a separate post message page
  20. key = response.match(/key" value="([^"]*)"/)[1];
  21. addLinks();
  22. });
  23. }
  24. //If neither method can find the key, don't bother adding the quick PM links since they cannot function properly
  25.  
  26.  
  27. function addLinks(){
  28. var username = $(".board_nav a:first").html();
  29. username = username.substring(0,username.indexOf('(')-1);
  30. var $details = $(".msg_stats_left")
  31. , displayLeft = true;
  32. if (!$details.length){ //If nothing was found, they must have user details displayed above the message
  33. $details = $(".msg_stats");
  34. displayLeft = false;
  35. }
  36. $details.each(function(index, el) {
  37. var $el = $(el);
  38. if (!($el.html().match(username)))
  39. { //Posts without your username are from other users, and they can be PM'd
  40. var pmLink = $("<a> PM </a>");
  41. pmLink.click(function() {showPMWindow($el.find("a.name").html());});
  42. $el.append(pmLink);
  43. }
  44. });
  45. }
  46.  
  47. function createPopup(text){
  48. $("#popup-window").remove();
  49. var $window = $("<div id='popup-window'> " + text + " </div>")
  50. .css("left", "30%")
  51. .css("top","30%")
  52. .css("position", "fixed")
  53. .toggleClass("reg_dialog", true);
  54. $("body").prepend($window);
  55. return $window;
  56. }
  57.  
  58. function showPMWindow(name) {
  59. var $PMWindow = createPopup("Send a PM to " + name)
  60. , $subject = $("<div>Subject: <input type='text' maxlength='100' /></div>")
  61. , $message = $("<div><textarea rows ='" + Math.floor($(window).height() / 45) + "' cols='80' maxlength='1024'></textarea></div>");
  62. var $send = $("<button style='margin: 5px;'>Send</button>").click(function() {sendPM(name, $subject.find("input").val(), $message.find("textarea").val()); setTimeout(function() {$PMWindow.remove();},5000);})
  63. , $cancel = $("<button style='margin: 5px;'>Cancel</button>").click(function() {$PMWindow.remove();});
  64. $PMWindow.append($subject).append($message).append($send).append($cancel);
  65. }
  66.  
  67. function sendPM(name, subject, message) {
  68. name = name.slice(3,-4);
  69. $.post('/pm/new', {key: key, to: name, subject: subject, message: message, submit: 'Quick PM'}).done(function(){$("#popup-window textarea").val("PM sent.");});
  70. }