ahk_codebox_quick_fix

Add 'EXPAND VIEW' to code box

  1. // ==UserScript==
  2. // @name ahk_codebox_quick_fix
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Add 'EXPAND VIEW' to code box
  6. // @author You
  7. // @match https://autohotkey.com/boards/viewtopic.php*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. expand_code_init();
  12.  
  13. window.expandCode = function expandCode(e) {
  14. var c = e.parentNode.parentNode.getElementsByTagName('code')[0];
  15. if (c.style.maxHeight == 'none') {
  16. c.style.maxHeight = '200px';
  17. e.innerHTML = 'EXPAND VIEW';
  18. }
  19. else {
  20. c.style.maxHeight = 'none';
  21. e.innerHTML = 'COLLAPSE VIEW';
  22. }
  23. }
  24.  
  25. function expand_code_init() {
  26. var boxes = document.getElementsByTagName('code');
  27. for (var i = 0; i < boxes.length; i++) {
  28. if (boxes[i].scrollHeight > boxes[i].offsetHeight + 1) {
  29. boxes[i].parentNode.previousSibling.innerHTML += ' &middot; <a href="#" onclick="expandCode(this); return false;">EXPAND VIEW</a>';
  30. }
  31. }
  32. }