Greasy Fork

Greasy Fork is available in English.

ahk_forum_fix

Adding back 'EXPAND VIEW' to code box; Fix Spoiler can't show/hide...

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ahk_forum_fix
// @namespace    http://tampermonkey.net/
// @version      0.4
// @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
// ==/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;'));
    var c = e.parentNode.getElementsByClassName('bbc_spoiler_content')[0];
    c.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 tagP = (boxes[i].parentNode.tagName.toLowerCase() == 'pre' ? boxes[i].parentNode.previousSibling : boxes[i].previousSibling);
            var added = (tagP.innerHTML.indexOf('EXPAND') > 0)
            if (!added) {
                tagP.innerHTML += ' &middot; <a href="#" onclick="expandCode(this); return false;">EXPAND VIEW</a>';
            }
        }
	}
}

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) {
			var tagP = (boxes[i].parentNode.tagName.toLowerCase() == 'pre' ? boxes[i].parentNode.previousSibling : boxes[i].previousSibling);
            tagP.innerHTML += ' &middot; <a href="#" onclick="expandCode(this); return false;">EXPAND VIEW</a>';
        }
	}
}

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);');
        }
        */
        btns[i].setAttribute('onClick', 'spoiler_showHide(this);');
	}
}