Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. Install Tampermonkey (Chrome) or Greasemonkey (Firefox).
  2.  
  3. I use the one found here: https://greasyfork.org/en/scripts/6187-xenforo-invis-text-multi-reveal/code
  4.  
  5. I've modified the code so that the button reads "Toggle Invistext: Nonvisible" when the text is not visible and "Toggle Invisitext: Visible" when it is. However, it's a bit buggy, so contact me if you think you can fix that.
  6.  
  7. My modified version:
  8.  
  9. // ==UserScript==
  10. // @name Xenforo Invis-Text Multi-Reveal
  11. // @namespace com.user.twixion
  12. // @description This script adds a button to reveal invisible text. The button is placed under a poster's avatar, and will only be displayed if there is transparent text in the post. Also, a dotted grey border is placed around any invisible text to denote its presence.
  13. // @include /^https?://forums\.(spacebattles|sufficientvelocity)\.com/(threads|conversations)/.*$/
  14. // @version 2.3
  15. // @grant none
  16. // @history 2.3 bugfix: changed search for transparency to be case-insensitive
  17. // @history 2.2 added include for https
  18. // @history 2.1 bugfix: search string now case insensitive, used jquery instead of injecting JS into page
  19. // @history 2.0 major rewrite to consolidate buttons, renamed
  20. // @history 1.0 initial public version
  21.  
  22. // ==/UserScript==
  23.  
  24. // grab id from button, test if there exists any spans with "transparent" (case-insensitive)
  25. // in the style and sets color to grey. If no match found, set to color "transparent"
  26. function toggleVisibility() {
  27. var id = $(this).attr('id');
  28. var strPostID = "span.".concat(id);
  29. if($(strPostID).filter(function(){
  30. // regex test "transparent", case-insensitive
  31. return /transparent/i.test($(this).attr('style'));
  32. }).length > 0){
  33. $(strPostID).css("color","red");
  34. buttonText = document.createTextNode("Toggle Invis-text: Visible");
  35. newButton.textContent = "";
  36. newButton.appendChild(buttonText);
  37. } else {
  38. $(strPostID).css("color","transparent");
  39. buttonText = document.createTextNode("Toggle Invis-text: Nonvisible");
  40. newButton.textContent = "";
  41. newButton.appendChild(buttonText);
  42. }
  43. }
  44.  
  45. // inject css style to page;
  46. // spoilerShow not currently used, spoilerHide puts a dotted border around element
  47. (function() {
  48. var injectedCSS = document.createElement('style');
  49. injectedCSS.appendChild(document.createTextNode(
  50. ".spoilerShow {color:#FF0000!important;}\
  51. .spoilerHide {border: 1px dotted grey!important;}\
  52. .spoilerHide:hover{color: #FF0000!important;}\
  53. "));
  54. (document.body || document.head || document.documentElement).appendChild(injectedCSS);
  55. })();
  56.  
  57. function createSpoilerButton(){
  58. // create id variable if doesn't exist
  59. if(typeof createSpoilerButton.id == 'undefined'){createSpoilerButton.id = 0;}
  60.  
  61. // var id = createSpoilerButton.id;
  62. var strPostID = "post_id_";
  63. // only create button if post contains transparent text
  64. if($(this).find("span").filter(function(){
  65. // regex test "transparent", case-insensitive
  66. return /transparent/i.test($(this).attr('style'));
  67. }).length > 0){
  68. newButton = document.createElement("button");
  69. //buttonText = document.createTextNode("Toggle Invis-text");
  70. buttonText = document.createTextNode("Toggle Invis-text: Nonvisible");
  71. newButton.setAttribute('type','button');
  72. newButton.setAttribute('id',strPostID.concat(createSpoilerButton.id));
  73. newButton.setAttribute('class','invisButton');
  74. newButton.appendChild(buttonText);
  75. $(this).find("div.messageUserBlock").append(newButton);
  76. $(this).find("span").filter(function(){return /transparent/i.test($(this).attr('style'));}).addClass(strPostID.concat(createSpoilerButton.id));
  77. createSpoilerButton.id++;
  78. }
  79. };
  80.  
  81. $(document).ready(function(){
  82. $("span").filter(function(){
  83. // regex test "transparent", case-insensitive
  84. return /transparent/i.test($(this).attr('style'));
  85. }).addClass('spoilerHide');
  86. $("li.message").each(createSpoilerButton);
  87. $("button.invisButton").click(toggleVisibility);
  88. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement