Seattle Public Library Rename Change Status Button

Changes the "Change Status" button to reflect what action it will take.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// vim: et tw=80 ts=4 sw=4 ai

// ==UserScript==
// @name           Seattle Public Library Rename Change Status Button
// @description    Changes the "Change Status" button to reflect what action it will take.
// @namespace      http://www.arthaey.com
// @include        https://catalog.spl.org/ipac20/ipac.jsp?*submenu=holds*
// @author         Arthaey Angosii
// @version        1.1
//
// Backed up from http://userscripts.org/scripts/review/22059
// Last updated on  2008-02-03
// ==/UserScript==
//
// CHANGELOG:
//  v1.1 - highlight selected rows
//  v1.0 - initial release

window.addEventListener("load", function() {

    var button = document.getElementsByName("changestatus")[0];

    var unsuspend = 0;
    var suspend = 0;

    function run() {
        GM_addStyle("tr.selected * { background-color: lightyellow !important; }");

        updateButton();

        var checkboxes = document.getElementsByName("waitingholdselected");
        for (var i = 0; i < checkboxes.length; i++) {
            checkboxes[i].addEventListener(
                "change",
                checkStatusFunc(checkboxes[i], i),
                true
            );
        }
    }

    function checkStatusFunc(checkbox, i) {
        return function() {
            var row = checkbox.parentNode.parentNode;
            var status = row.childNodes[3].textContent;

            if (status.match(/suspend/i)) {
                unsuspend += (checkbox.checked ? 1 : -1);
            }
            else if (status.match(/active/i)) {
                suspend += (checkbox.checked ? 1 : -1);
            }

            row.className = (checkbox.checked ? "selected" : null );
            console.log("Row class name: " + row.className);

            updateButton();
        }
    }

    function updateButton() {
        button.style.backgroundColor = null;

        if (suspend && unsuspend) {
            button.value = "Mixed Status!";
            button.style.backgroundColor = "red !important";
        }
        else if (suspend) {
            button.value = "Suspend";
        }
        else if (unsuspend) {
            button.value = "Activate";
        }
        else {
            button.value = "Toggle Status";
        }
    }

    run();

}, true);