Check_MK - WATO Uncheck Service

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

目前為 2014-11-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();