Check_MK - WATO Uncheck Service

Automatically unchecks service in WATO/Services of host x by doubleclick

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

您需要先安装一个扩展,例如 篡改猴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  Automatically unchecks service in WATO/Services of host x by doubleclick
// @description:de-DE Entfernt automatisch den Haken bei WATO/Services für host x per Doppelklick
// @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.1
// @date         2014-11-16
// ==/UserScript==

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

	init: function() {
		// Zunächst das Deaktivieren vornehmen und anzeigen:
		var uncheckedservices = GM_getValue('cmkwatouncheckedservices','');
		var mySarr = uncheckedservices.split(";");
		for (var i = 0; i<mySarr.length; i++) {
			var myEle = document.getElementsByName(mySarr[i])[0];
			if (myEle !== undefined) {
				myEle.checked = false;
				myEle.parentNode.parentNode.setAttribute('style','background: ' + cmkwatouncheckservice.setting.bgr + ';');
			}
		}

		// Checkboxen selektieren:
		var nodes = document.evaluate(
			"//span[@class='checkbox']/input[@type='checkbox']",
			document,
			null,
			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
			null);

		// Checkboxen Doppelklick-Ereignis zuweisen, mit dem die entsprechende Einstellung gewählt wird
		for(var j = 0; j<nodes.snapshotLength; j++) {
			var thisNode = nodes.snapshotItem(j);
			var thisNodeName = thisNode.name;
			thisNode.ondblclick=function(event) {
				event.preventDefault();
				event.stopPropagation();
				var uncheckedservices = GM_getValue('cmkwatouncheckedservices','');
				var mySarr = uncheckedservices.split(";");
				var hit = mySarr.indexOf(this.name);
				if (hit === -1) {
					uncheckedservices = uncheckedservices + ";" + this.name;
					if (cmkwatouncheckservice.setting.speeks) {
						alert("Next page load will set checked=false for this input.");
					}
					this.parentNode.parentNode.setAttribute('style','background: ' + cmkwatouncheckservice.setting.bgr + ';');
				}
				else {
					mySarr.splice(hit, 1);
					uncheckedservices = mySarr.join(';');
					if (cmkwatouncheckservice.setting.speeks) {
						alert("Next page load won't change checked status for this input anymore.");
					}
					this.parentNode.parentNode.setAttribute('style','background: inherit;');
				}
				GM_setValue('cmkwatouncheckedservices',uncheckedservices);
			};
		}
	}
};
cmkwatouncheckservice.init();