// ==UserScript== // @name ahk_forum_fix // @namespace http://tampermonkey.net/ // @version 0.2 // @description Adding back 'EXPAND VIEW' to code box; Fix Spoiler can't show/hide... // @author tmplinshi // @match https://autohotkey.com/boards/viewtopic.php* // @grant none // @downloadURL none // ==/UserScript== expand_code_init(); spoiler_init(); window.expandCode = function (e) { var c = e.parentNode.parentNode.getElementsByTagName('code')[0]; if (c.style.maxHeight == 'none') { c.style.maxHeight = '200px'; e.innerHTML = 'EXPAND VIEW'; } else { c.style.maxHeight = 'none'; e.innerHTML = 'COLLAPSE VIEW'; } } window.spoiler_showHide = function (e) { var sw = ((e.getAttribute('value') == 'Show') ? 1 : 0); e.setAttribute('value', (sw ? 'Hide' : 'Show' )); e.nextSibling.firstChild.setAttribute('style', (sw ? 'display:block;' : 'display:none;')); if (sw) { checkChildCodebox(e.nextSibling); } } function checkChildCodebox(e) { var boxes = e.getElementsByTagName('code'); for (var i = 0; i < boxes.length; i++) { if (boxes[i].scrollHeight > boxes[i].offsetHeight + 1) { var added = (boxes[i].parentNode.previousSibling.innerHTML.indexOf('EXPAND') > 0) if (!added) { boxes[i].parentNode.previousSibling.innerHTML += ' · EXPAND VIEW'; } } } } function expand_code_init() { var boxes = document.getElementsByTagName('code'); for (var i = 0; i < boxes.length; i++) { if (boxes[i].scrollHeight > boxes[i].offsetHeight + 1) { boxes[i].parentNode.previousSibling.innerHTML += ' · EXPAND VIEW'; } } } function spoiler_init() { var btns = document.getElementsByClassName('post_spoiler_show'); for (var i = 0; i < btns.length; i++) { if (btns[i].previousSibling.className == 'spoiler_title') { btns[i].setAttribute('onClick', 'spoiler_showHide(this);'); } } }