Użytkownik:SH3VEK/common.js: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
M (Serwery Wikii nie skompilują tego) Znacznik: edytor źródłowy |
M |
||
Linia 1: | Linia 1: | ||
(function() { |
mw.loader.using(["oojs", "oojs-ui"], function() { |
||
function NWSGDialog(config) { |
|||
"use strict"; |
|||
NWSGDialog.super.call(this, config); |
|||
const fn = () => 3; |
|||
this.tryby = {"Główny tryb": "Strona", "Fantasy": "Fantasy/strona", "RPG – łatwy": "RPG/łatwy/strona", "RPG – średni": "RPG/średni/strona", "RPG – trudny": "RPG/trudny/strona"}; |
|||
function fff() {console.log(arguments);} |
|||
} |
|||
OO.inheritClass(NWSGDialog, OO.ui.ProcessDialog); |
|||
const uf = new Function('fff`Jajko na ${{"w": 4}} patelni ${fn()}! ${[2, 3, 4]}`'); |
|||
NWSGDialog.static.name = "nswgDialog"; |
|||
uf(); |
|||
NWSGDialog.static.title = "NOWE Wolne strony Gry"; |
|||
})(); |
|||
NWSGDialog.static.actions = [ |
|||
{ action: 'cancel', label: 'Zamknij', flags: [ 'safe', 'back' ] } |
|||
]; |
|||
NWSGDialog.prototype.szukaj = function() { |
|||
let min = Math.floor(Number(this.inputOd.getValue()))||1, max = Math.floor(Number(this.inputDo.getValue()))||0, 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.getSelectedItem().getData()); |
|||
} |
|||
}; |
|||
NWSGDialog.prototype.progres = function(min, max, stat, page) { |
|||
let pn = page + " " + min, api = new mw.Api(); |
|||
this.btnSzukaj.setLabel("Szukanie... (" + min + "|" + max + ")"); |
|||
let 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((data) => { |
|||
let 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(() => this.progres(min+1, max, stat, page), 250); |
|||
} else { |
|||
this.btnSzukaj.setDisabled(false); |
|||
this.btnSzukaj.setLabel("Szukaj"); |
|||
} |
|||
}); |
|||
} |
|||
NWSGDialog.prototype.initialize = function() { |
|||
NWSGDialog.super.prototype.initialize.apply(this, arguments); |
|||
// Wybór trybu |
|||
let optTryb = []; |
|||
for (let 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"]}); |
|||
this.btnSzukaj.on("click", () => this.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) { |
|||
return new OO.ui.Process(() => this.close({action: action})) |
|||
} |
|||
function makeTool(name, icon, title, onSelect, onUpdateState) { |
|||
let 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; |
|||
} |
|||
let wm = new OO.ui.WindowManager(); |
|||
let tf = new OO.ui.ToolFactory(); |
|||
let nwsgD = new NWSGDialog({size: "large"}); |
|||
let NwsgTool = makeTool("nwsg", "circle", "NOWE wolne strony Gry", function() {this.setActive(false); wm.openWindow(nwsgD)}, function() {}); |
|||
tf.register(NwsgTool); |
|||
let CfgTool = makeTool("settings", "settings", "Ustawienia", function() {this.setActive(false)}, function() {}); |
|||
tf.register(CfgTool); |
|||
let tb = new OO.ui.Toolbar(tf, new OO.ui.ToolGroupFactory(), {position: "bottom"}); |
|||
tb.setup([{type: "list", icon: "ellipsis", include: ["*"]}]); |
|||
let 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]); |
|||
}) |
|||
}); |
Wersja z 00:08, 11 mar 2019
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() {
let min = Math.floor(Number(this.inputOd.getValue()))||1, max = Math.floor(Number(this.inputDo.getValue()))||0, 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.getSelectedItem().getData());
}
};
NWSGDialog.prototype.progres = function(min, max, stat, page) {
let pn = page + " " + min, api = new mw.Api();
this.btnSzukaj.setLabel("Szukanie... (" + min + "|" + max + ")");
let 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((data) => {
let 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(() => this.progres(min+1, max, stat, page), 250);
} else {
this.btnSzukaj.setDisabled(false);
this.btnSzukaj.setLabel("Szukaj");
}
});
}
NWSGDialog.prototype.initialize = function() {
NWSGDialog.super.prototype.initialize.apply(this, arguments);
// Wybór trybu
let optTryb = [];
for (let 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"]});
this.btnSzukaj.on("click", () => this.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) {
return new OO.ui.Process(() => this.close({action: action}))
}
function makeTool(name, icon, title, onSelect, onUpdateState) {
let 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;
}
let wm = new OO.ui.WindowManager();
let tf = new OO.ui.ToolFactory();
let nwsgD = new NWSGDialog({size: "large"});
let NwsgTool = makeTool("nwsg", "circle", "NOWE wolne strony Gry", function() {this.setActive(false); wm.openWindow(nwsgD)}, function() {});
tf.register(NwsgTool);
let CfgTool = makeTool("settings", "settings", "Ustawienia", function() {this.setActive(false)}, function() {});
tf.register(CfgTool);
let tb = new OO.ui.Toolbar(tf, new OO.ui.ToolGroupFactory(), {position: "bottom"});
tb.setup([{type: "list", icon: "ellipsis", include: ["*"]}]);
let 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]);
})
});