Użytkownik:SH3VEK/common.js

Z Nonsensopedii, polskiej encyklopedii humoru

Uwaga: aby zobaczyć zmiany po zapisaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5 lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer: Przytrzymaj Ctrl jednocześnie klikając Odśwież lub naciśnij klawisze Ctrl+F5
  • Konqueror: Kliknij polecenie Odśwież lub naciśnij klawisz F5
  • Opera: Wyczyść pamięć podręczną w Narzędzia → Preferencje
mw.loader.using(["oojs", "oojs-ui"], function() {
	function NWSGDialog(config) {
		NWSGDialog.super.call(this, config);
		this.tryby = {"Główny tryb": "Strona", "Fantasy": "Fantasy/strona", "RPG – łatwy": "RPG/łatwy/strona", "RPG – średni": "RPG/średni/strona", "RPG – trudny": "RPG/trudny/strona"};
	}
	OO.inheritClass(NWSGDialog, OO.ui.ProcessDialog);
	NWSGDialog.static.name = "nswgDialog";
	NWSGDialog.static.title = "NOWE Wolne strony Gry";
	NWSGDialog.static.actions = [
		{ action: 'cancel', label: 'Zamknij', flags: [ 'safe', 'back' ] }
	];
	NWSGDialog.prototype.szukaj = function() {
		var min = Math.floor(Number(this.inputOd.getValue()))||1;
		var max = Math.floor(Number(this.inputDo.getValue()))||0;
		var w = min > max ? "Wpisz liczbę większą od początkowej" : "Rozpoczęcie wyszukiwania";
		if (min > max) {
			OO.ui.alert("Wpisz liczbę większą od początkowej!");
		} else if (min <= max) {
			this.btnSzukaj.setDisabled(true);
			this.progres(min, max, {u: 0, l: 0, f: 0, t: 0}, "Gra:" + this.selectTryb.findSelectedItem().getData());
		}
	};
	NWSGDialog.prototype.progres = function(min, max, stat, page) {
		var self = this;
		var pn = page + " " + min, api = new mw.Api();
		this.btnSzukaj.setLabel("Szukanie... (" + min + "|" + max + ")");
		var q = {action: "query", list: ["backlinks"], blnamespace: 108, titles: pn, bltitle: pn};
		if (mw.config.get("wgUserGroups").indexOf("sysop") != -1) {
			q.list.push("deletedrevs");
			q.drlimit = 1;
			q.drprop = ["user", "content"];
		}
		api.get(q).done(function(data) {
			var gc = data.query.pages["-1"] && data.query.pages["-1"].missing === "" ? [!0,[]] : [!1,[]];
			if ("deletedrevs" in data.query && data.query.deletedrevs.length && data.query.deletedrevs[0].revisions.length) {
				gc[1].push('<a class="nwsg-u" href="/wiki/Specjalna:Odtwórz/' + page + "_" + min +'">usuwany</a>');
				if (gc[0]) stat.u++;
			}
			if (data.query.backlinks.length) {
				gc[1].push('<a class="nwsg-l" href="/wiki/Specjalna:Linkujące/' + page + "_" + min +'">ma linkujące</a>');
				if (gc[0]) stat.l++;
			}
			if (gc[0]) {
				$("<li><a "+(!gc[1].length?"class='new'":"")+"href='/wiki/" + page + "_" + min + "'>Strona "+min+"</a>"+(gc[1].length?" ("+gc[1].join(", ")+")":"")+"</li>").appendTo(".nwsg-list");
				stat.t++;
			}
			if (gc[0] && !gc[1].length) stat.f++;
			if (min < max) {
				setTimeout(function() {self.progres(min+1, max, stat, page)}, 250);
			} else {
				self.btnSzukaj.setDisabled(false);
				self.btnSzukaj.setLabel("Szukaj");
			}
		});
	};
	NWSGDialog.prototype.initialize = function() {
		NWSGDialog.super.prototype.initialize.apply(this, arguments);
		// Wybór trybu
		var optTryb = [];
		for (var f in this.tryby) {
			optTryb.push(new OO.ui.ButtonOptionWidget({data: this.tryby[f], label: f}));
		}
		this.selectTryb = new OO.ui.ButtonSelectWidget({items: optTryb});
		this.selectTryb.selectItem(optTryb[0]);
		
		this.inputOd = new OO.ui.NumberInputWidget();
		this.inputDo = new OO.ui.NumberInputWidget();
		
		this.btnSzukaj = new OO.ui.ButtonWidget({label: "Szukaj", flags: ["progressive"]});
		
		var self = this;
		this.btnSzukaj.on("click", function() {self.szukaj()});
		// Lista
		this.$body.append(this.selectTryb.$element, this.inputOd.$element, this.inputDo.$element, this.btnSzukaj.$element, $('<ol class="nwsg-list"></ol>'));
	};
	NWSGDialog.prototype.getActionProcess = function(action) {
		var self = this;
		return new OO.ui.Process(function() {self.close({action: action})});
	};
	
	function makeTool(name, icon, title, onSelect, onUpdateState) {
		var fn;
		fn = function() {fn.super.apply(this, arguments)};
		OO.inheritClass(fn, OO.ui.Tool);
		fn.static.name = name;
		fn.static.icon = icon;
		fn.static.title = title;
		fn.prototype.onSelect = onSelect;
		fn.prototype.onUpdateState = onUpdateState;
		return fn;
	}
	
	var wm = new OO.ui.WindowManager();
	var tf = new OO.ui.ToolFactory();
	var nwsgD = new NWSGDialog({size: "large"});
	
	var NwsgTool = makeTool("nwsg", "circle", "NOWE wolne strony Gry", function() {this.setActive(false); wm.openWindow(nwsgD)}, function() {});
	tf.register(NwsgTool);
	var CfgTool = makeTool("settings", "settings", "Ustawienia", function() {this.setActive(false)}, function() {});
	tf.register(CfgTool);
	
	var tb = new OO.ui.Toolbar(tf, new OO.ui.ToolGroupFactory(), {position: "bottom"});
	tb.setup([{type: "list", icon: "ellipsis", include: ["*"]}]);
	
	var pl = new OO.ui.PanelLayout({$content: tb.$element, framed: true, expanded: false});
	pl.$element.css({position: "fixed", bottom: "4px", right: "4px", zIndex: 100});
	$(function() {
		$("body").append(pl.$element);
		$("body").append(wm.$element);
		tb.initialize();
		tb.emit("updateState");
		wm.addWindows([nwsgD]);
	});
});