User:Moonythedwarf/handyman.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Moonythedwarf/handyman. |
"use strict";
if (window.handyman === undefined) {
let hmn = {};
window.handyman = {};
hmn.build_ui_core = () => {
hmn.ui = {};
hmn.ui.frame = new OO.ui.PanelLayout({
expanded: false,
framed: true
});
hmn.ui.innerFrame_a = new OO.ui.PanelLayout({
expanded: false,
padded: true
});
hmn.ui.frame.$element.append(
hmn.ui.innerFrame_a.$element
);
hmn.ui_target.append(hmn.ui.frame.$element);
};
/* BEGIN RCP */
hmn.build_rcp_ui = async () => {
hmn.build_ui_core();
};
/* END OF RCP | BEGIN FILTER TESTER */
hmn.build_filter_ui = async () => {
hmn.ui = {};
await window.avtools.load_libavtools_filters();
let css = await window.avtools.load_json_file("User:Moonythedwarf/HandymanFilterInterface.css"); //totally JSON.
let st = $("<style>");
hmn.ui.style = st;
st.text(css);
hmn.ui_target.append(st);
let f = JSON.parse(await window.avtools.load_json_file("User:Moonythedwarf/HandymanFilterInterface.json"));
window.libcui.build_ui(f, hmn.ui, hmn.ui_target);
//hmn.ui.submit.$element.addClass("fullwidth");
hmn.ui.submit.on("click", hmn.filter_test_run_filters);
/*
await window.avtools.load_libavtools_filters();
hmn.build_ui_core();
hmn.ui.innerFrame_b = new OO.ui.PanelLayout({
expanded: false,
padded: true
});
hmn.ui.frame.$element.append(
$("<hr>"),
hmn.ui.innerFrame_b.$element
);
hmn.ui.filter_type_select = new OO.ui.DropdownInputWidget({
options: [
{ data: "username_filters", label: "Username" },
{ data: "content_filters", label: "Content" },
{ data: "summary_filters", label: "Summary" },
]
});
hmn.ui.filter_text_input = new OO.ui.MultilineTextInputWidget({
placeholder: "Text to filter",
})
let submit = new OO.ui.ButtonInputWidget({
label: "Check filters"
});
hmn.ui.fields = new OO.ui.FieldsetLayout({
label: "Handyman Filter Testing"
});
hmn.ui.fields.addItems([
new OO.ui.FieldLayout(hmn.ui.filter_text_input),
new OO.ui.FieldLayout(hmn.ui.filter_type_select, {
label: "Select filter type:",
align: "top"
}),
new OO.ui.FieldLayout(submit)
]);
//TODO: pretty JSON output.
hmn.ui.output_text = $("<p>");
hmn.ui.output_text.css("white-space", "pre-wrap");
hmn.ui.output_frame = new OO.ui.PanelLayout({
expanded: false,
framed: true,
padded: true,
});
hmn.ui.output_frame.$element.append(hmn.ui.output_text);
hmn.ui.innerFrame_a.$element.append(hmn.ui.fields.$element, submit.$element);
hmn.ui.innerFrame_b.$element.append(hmn.ui.output_frame.$element);
*/
}
hmn.filter_test_run_filters = () => {
let avt = window.avtools;
let results = avt.match_against_filters(avt[hmn.ui.filter_type_select.value], hmn.ui.filter_text_input.value);
let i = $("<p>");
hmn.ui.outputFrame.$element.text(JSON.stringify(results, null, 2));
}
/* END FILTER TESTER | BEGIN CONFIG UI */
hmn.build_config_ui = async () => {
hmn.ui = {};
let f = JSON.parse(await window.avtools.load_json_file("User:Moonythedwarf/HandymanConfigInterface.json"));
window.libcui.build_ui(f, hmn.ui, hmn.ui_target);
hmn.ui.reload_avtools_config_btn.on("click", () => {
window.avtools.wipe_cache();
location.reload();
});
/*
hmn.build_ui_core();
hmn.ui.reload_avtools_config_btn = new OO.ui.ButtonWidget({
label: "Reload libavtools configuration and data (Unsaved config changes will be lost!)",
flags: "destructive",
});
hmn.ui.save_
hmn.ui.innerFrame_a.$element.append(
$("<hr>"),
hmn.ui.reload_avtools_config_btn.$element
);
*/
}
/* END CONFIG UI */
hmn.interfaces = [
"Moonythedwarf/HandymanRCPInterface",
"Moonythedwarf/HandymanFilterInterface",
"Moonythedwarf/HandymanConfigInterface",
"Moonythedwarf/HandymanPatrolFeed",
];
$(async () => {
// libavtools takes a fairly significant amount of time to load fully, so only load it on pages effected by handyman.
try {
if (hmn.interfaces.includes(mw.config.get("wgTitle"))) {
let startTime = performance.now();
mw.notify("Handyman loading...");
await Promise.all([
mw.loader.getScript("/w/index.php?title=User:Moonythedwarf/libavtools.js&action=raw&ctype=text/javascript"),
mw.loader.getScript("/w/index.php?title=User:Moonythedwarf/libcui.js&action=raw&ctype=text/javascript"),
mw.loader.using(["oojs", "oojs-ui-core", "oojs-ui-widgets", "oojs-ui-toolbars"]),
]);
await window.avtools.load_libavtools_core();
hmn.ui_target = $("#mw-content-text");
switch (mw.config.get("wgTitle")) {
case "Moonythedwarf/HandymanRCPInterface":
await hmn.build_rcp_ui();
break;
case "Moonythedwarf/HandymanFilterInterface":
await hmn.build_filter_ui();
break;
case "Moonythedwarf/HandymanConfigInterface":
await hmn.build_config_ui();
break;
case "Moonythedwarf/HandymanPatrolFeed":
await mw.loader.getScript("/w/index.php?title=User:Moonythedwarf/handyman-usernames.js&action=raw&ctype=text/javascript")
window.handyman.uns.build_usernamefeed_ui();
break;
default:
throw new Error("unimplemented interface");
}
let endTime = performance.now();
mw.notify(`Loaded in ${endTime-startTime}ms`);
}
} catch (e) {
mw.notify(e);
}
});
}