Check_MK - WATO Uncheck Service

Remember which checkbox should be always on or off by doubleclick on checkbox under WATO/Services of host.

当前为 2014-11-18 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Check_MK - WATO Uncheck Service
// @namespace    http://openuserjs.org/users/ardiman
// @description  Remember which checkbox should be always on or off by doubleclick on checkbox under WATO/Services of host.
// @description:de-DE Merkt sich, welches Kontrollkästchen immer ein- oder ausgeschaltet sein soll durch Doppelklick auf das Kontrollkästchen unter WATO/Services of host.
// @grant        GM_getValue
// @grant        GM_setValue
// @homepage     https://github.com/ardiman/userscripts/tree/master/checkmkwatouncheckservice
// @icon         https://raw.githubusercontent.com/ardiman/userscripts/master/scriptlogo.gif
// @include      */check_mk/wato.py?mode=inventory&host*
// @include      */check_mk/wato.py?filled_in=edithost*
// @include      */check_mk/wato.py?folder=&host=*&mode=inventory
// @version      1.0.2
// @date         2014-11-18
// ==/UserScript==

var cmkwatouncheckservice = {
	setting: {
		bgru: "blue",        // background of table cell with automatically unchecked checkbox
		bgrc: "purple",      // background of table cell with automatically checked checkbox
		speeks: false,       // show alert if "automatically unchecked/checked" is changed
	},

	init: function() {
		// Select checkboxes
		var nodes = document.evaluate(
			"//span[@class='checkbox']/input[@type='checkbox']",
			document,
			null,
			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
			null);
		var uncheckedservices = GM_getValue('cmkwatouncheckedservices','');
		var checkedservices = GM_getValue('cmkwatocheckedservices','');
		var myUArr = uncheckedservices.split(";");
		var myCArr = checkedservices.split(";");
		var i = 0;
		// Change style of checkboxes (grandparent) and set their dblclick-event
		for(var j = 0; j<nodes.snapshotLength; j++) {
			var thisNode = nodes.snapshotItem(j);
			var thisNodeName = thisNode.name;
			var hitU = myUArr.indexOf(thisNodeName);
			var hitC = myCArr.indexOf(thisNodeName);
			if (hitU !== -1) {
				i++;
				thisNode.checked = false;
				thisNode.parentNode.parentNode.setAttribute('style','background: ' + cmkwatouncheckservice.setting.bgru + ';');
			}
			if (hitC !== -1) {
				i++;
				thisNode.checked = true;
				thisNode.parentNode.parentNode.setAttribute('style','background: ' + cmkwatouncheckservice.setting.bgrc + ';');
			}
			thisNode.ondblclick=function(event) {
				event.preventDefault();
				event.stopPropagation();
				if (this.checked) {
					cmkwatouncheckservice.changecheck(this,'cmkwatocheckedservices',true,cmkwatouncheckservice.setting.bgrc);
				} else {
					cmkwatouncheckservice.changecheck(this,'cmkwatouncheckedservices',false,cmkwatouncheckservice.setting.bgru);
				}
			};
		}
		return i;
	},

	changecheck: function(ele,whichValue,forMsg,bg) {
		var myServices = GM_getValue(whichValue,'');
		var myArr = myServices.split(";");
		var hit = myArr.indexOf(ele.name);
		if (hit === -1) {
			myServices = myServices + ";" + ele.name;
			if (cmkwatouncheckservice.setting.speeks) {
				alert("Next page load will set checked=" + forMsg + " for this input.");
			}
			ele.parentNode.parentNode.setAttribute('style','background: ' + bg + ';');
		}
		else {
			myArr.splice(hit, 1);
			myServices = myArr.join(';');
			if (cmkwatouncheckservice.setting.speeks) {
				alert("Next page load won't change checked status for this input anymore.");
			}
			ele.parentNode.parentNode.setAttribute('style','background: inherit;');
		}
		GM_setValue(whichValue,myServices);
	}
};

var setchkbx = cmkwatouncheckservice.init();
if (cmkwatouncheckservice.setting.speeks && setchkbx !==0) {
	alert("One or more (" + setchkbx + ") checkboxes were set automatically. Please save this configuration.");
}