Pi-hole+

Set your own timezone

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name        Pi-hole+
// @namespace   V@no
// @author      V@no
// @description Set your own timezone
// @license     MIT
// @icon        data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABllpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTQ1IDc5LjE2MzQ5OSwgMjAxOC8wOC8xMy0xNjo0MDoyMiAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOnBob3Rvc2hvcD0iaHR0cDovL25zLmFkb2JlLmNvbS9waG90b3Nob3AvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDQyAyMDE5IChXaW5kb3dzKSIgeG1wOkNyZWF0ZURhdGU9IjIwMjAtMDUtMTRUMTU6MjY6MzktMDQ6MDAiI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2neQs070kT/ASr5opzmpgewcSNQW5taODQEhJe9tnGCX2FUdPHr4fd43gQ0ODXvvPaip1LA5xLfPmniRoJvEb29Kd8Gg5pAnNHx8YjEv78Aj7B/Ow+PVSo8G1b4m3RPunYBUbcSvD0DPNmmUhesGoHAR0uDjY1f8Pe2oxJTPzEravBkEQKUjwlsG5DoGgC2ub8DAoecrFNOs1cGgndER0ePwO+/d2mivr4qdvHi65sDwef1msyWYJU2KfCq61Tc6REz9vc83QgOf09vzks1uDeI8329TprOtiyqtW6jwIcCN7ql2LULeG1/dhqPnB5Kajg9OtpNy43bEsx45MxwSM/pNVnces61Cz4tEjuZ7N+z4jmzPvxmn8LDGBtrF1VV+5NDExNvfbhhw8FLkoUacIsjkMDu5wzV78oCTyzigzuBNxgCfyyzjMLXTQpfsfsj2tr2L00cPvwCC8Z23tq+LB7o2reI/rzqAY5K+q1jGqiJCURvViipSD29KV86JCIWhO/zvWjKOK5n0kRzK6+BI1augkSlLPQu5RmXdy3RIzHOsrgy5XZ0R0y0tFoFrROWzF2FJTe2WCTcNO86Zj2L/DE7+KoKEm0JylEXT7EKSYQ7JN5WDll0VfWAPpDyTi7wReDXbOAFqYgsEm9mIRA/K3EgG3hBCNiIPEY5RZnTwkdnkPHasJL68z8BBgAaaq0RvyK2tgAAAABJRU5ErkJggg==
// @include     http://pi.hole/*
// @include     https://pi.hole/*
// @require     https://greasyfork.org/scripts/403344-moment-js-v2-25-3/code/Momentjs%20v2253.js?version=805187
// @require     https://greasyfork.org/scripts/403343-moment-timezone/code/Moment%20Timezone.js?version=805186
// @version     1.0
// @grant       none
// ==/UserScript==
!function()
{
	'use strict';

	let log = console.log,
			timeZone = localStorage.getItem("timeZone") || "",
			settings = $("#api").find(".box-body > .row > div > h4").last(),
			_unix;

	if ("moment" in window)
	{
		_unix = window.moment.unix;
//a hack that hijacks moment.unix() function
		window.moment.unix = function(f)
		{
			let t = moment.unix.apply(moment.unix, arguments),
					r = t.tz(timeZone);

			return t || r;
		}
	}
//add new setting
	if (settings.length)
	{
		$('<h4>Timezone</h4><div class="form-group"><div class="dropdown"><select id="timezone"><option value="">Default</option></select></div></div>')
		.insertBefore(settings)
		.find("#timezone")
		.each(function()
		{
			let that = this,
					options = moment.tz.names()
										.reduce(function(o, tz)
										{
											o[o.length] = {
												name: tz,
												offset: moment.tz(tz).utcOffset()
											};

											return o;
										}, [])
										.sort(function (a, b)
										{
											return a.offset - b.offset
										})
										.reduce(function (o, tz)
										{
											return o += '<option value="' + tz.name + '">(GMT' + (tz.offset ? moment.tz(tz.name).format('Z') : '') + ') ' + tz.name + '</option>';
										}, "");

			this.innerHTML += options;
			this.value = timeZone;
			$(this).closest("form").on("submit", function(e)
			{
				timeZone = that.value;
				if (timeZone)
					localStorage.setItem("timeZone", that.value);
				else
					localStorage.removeItem("timeZone");
			});
		});
	};
}()