GameFAQs Sig Box

Appearifies the sig box while avoiding a reset on your custom sig with edits.

  1. // ==UserScript==
  2. // @name GameFAQs Sig Box
  3. // @author Metallia
  4. // @namespace Cats
  5. // @description Appearifies the sig box while avoiding a reset on your custom sig with edits.
  6. // @include http://www.gamefaqs.com/*
  7. // @version 2.0
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // Feel free to edit, redistribute, all that good stuff.
  12.  
  13. function decodeHtml(html) { // http://stackoverflow.com/a/7394787
  14. var txt = document.createElement("textarea");
  15. txt.innerHTML = html;
  16. return txt.value;
  17. }
  18.  
  19. var hiddenSigField = document.querySelector("input[name='custom_sig']");
  20. if (hiddenSigField) {
  21. var newP = document.createElement("p");
  22. var newTextArea = document.createElement("textarea");
  23. hiddenSigField.parentNode.insertBefore(newP,hiddenSigField);
  24. hiddenSigField.parentNode.removeChild(hiddenSigField);
  25. newP.appendChild(newTextArea);
  26. newTextArea.setAttribute("name","custom_sig");
  27. newTextArea.setAttribute("maxlength","165");
  28. newTextArea.setAttribute("style","width: 100% !important; height: 46px !important;");
  29. var postPreview = document.evaluate('//table[@class="board message"]//td[@class="msg"]//div[@class="msg_body"]//div[@class="signature"]//div[@class="sig_text"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  30. if (postPreview) {
  31. var sig = postPreview.innerHTML;
  32. sig = sig.replace("<br>","\n");
  33. newTextArea.textContent = decodeHtml(sig);
  34. }
  35. }
  36.  
  37. function myFightMoney(item,id,sig) { // Yes, this is stupid, but I couldn't find any better way to handle this without the loop overwriting information or the event listener throwing a fit.
  38. item.addEventListener("mouseleave", function () {profoundSadness(item,id,sig)}, false);
  39. }
  40.  
  41. function profoundSadness(item,id,sig) {
  42. if ((item.getAttribute("onmousedown") === null) && (document.getElementById("sig_box_"+id) === null)) {
  43. var newSigBox = document.createElement('textarea');
  44. newSigBox.value = sig;
  45. newSigBox.id= "sig_box_"+id;
  46. newSigBox.style = "width: 100% !important; height: 46px !important;"; // May need to adjust the css depending on your own settings.
  47. newSigBox.maxlength = "165";
  48. item.parentNode.parentNode.parentNode.parentNode.childNodes[0].insertBefore(newSigBox,item.parentNode.parentNode.parentNode.parentNode.childNodes[0].childNodes[2]);
  49. // There might be more than one input[name=custom_sig] on the page if you open multiple edit fields, so I just set its value to the 'current' sig box repeatedly.
  50. document.querySelector("input[name='custom_sig']").value = sig;
  51. newSigBox.addEventListener("change", function () {document.querySelector("input[name='custom_sig']").value = this.value}, false);
  52. var saveButton = document.querySelector("input[name='"+id+"']");
  53. saveButton.addEventListener("focus", function () {document.querySelector("input[name='custom_sig']").value = newSigBox.value}, false);
  54. saveButton.addEventListener("mouseover", function () {document.querySelector("input[name='custom_sig']").value = newSigBox.value}, false);
  55. } else {
  56. return;
  57. }
  58. }
  59.  
  60. var editButtons = document.evaluate('//span[@class="postaction"]//a[text()="edit"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  61. if (editButtons.snapshotItem(0)) {
  62. var currentPostSig = new Array();
  63. var currentPostID = new Array();
  64. for (var i = 0; i < editButtons.snapshotLength; i++) {
  65. currentPostSig[i] = editButtons.snapshotItem(i).parentNode.parentNode.parentNode.parentNode.childNodes[0].getElementsByClassName("sig_text")[0].innerHTML.replace("<br>","\n");
  66. currentPostID[i] = editButtons.snapshotItem(i).getAttribute('onclick').split(',')[2].split(')')[0];
  67. editButtons.snapshotItem(i).setAttribute("onmousedown",editButtons.snapshotItem(i).getAttribute("onclick").substring(7)+"this.removeAttribute('onmousedown');");
  68. editButtons.snapshotItem(i).removeAttribute("onclick");
  69. myFightMoney(editButtons.snapshotItem(i),currentPostID[i],currentPostSig[i]);
  70. }
  71. }