Jump to content

User:Awesome Aasim/editrequestor.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Awesome Aasim (talk | contribs) at 23:55, 29 November 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
if (!EditRequestor) {
	var EditRequestor = {}
	mw.loader.using("jquery.ui", function() {
		$(document).ready(async function() {
			EditRequestor.url = new URL(location);
			let url = EditRequestor.url;
			if (mw.config.get('wgAction') == 'edit' && url.searchParams.get('section') == 'new' && url.searchParams.get('preload') == 'Template:Submit an edit request/preload') {
				EditRequestor.requestPage = '';
				EditRequestor.requestType = '';
				var preloadArray = EditRequestor.url.searchParams.getAll('preloadparams[]');
				for (var item of preloadArray) {
					switch (item) {
						case 'edit fully-protected': EditRequestor.requestType = item;
						break;
						case 'edit interface-protected': EditRequestor.requestType = item;
						break;
						case 'edit template-protected': EditRequestor.requestType = item;
						break;
						case 'edit extended-protected': EditRequestor.requestType = item;
						break;
						case 'edit semi-protected': EditRequestor.requestType = item;
						break;
						default: EditRequestor.requestPage = item;
						break;
					}
				}
				$('<form id="editrequestor-form"></form>').append('<p>Please make the change that you unambiguously would like to implement.</p><textarea id="editrequestor-area" disabled></textarea><input type="text" name="reason" id="editrequestor-reason" disabled placeholder="Reason for change"></input>').dialog({
					'buttons': [{
						"text": "Submit",
						"click": function() {
							
						}
					},
					{
						"text": "Preview",
						"click": function() {
							
						}
					}
					]
				});
				$("#editrequestor-area").text("Loading...");
				let result = await $.get(mw.config.get('wgScriptPath') + '/api.php', {
					'action': 'parse',
					'format': 'json',
					'prop': 'wikitext',
					'page': EditRequestor.requestPage
				});
				console.log(result);
				if (result.error) {
					$("#editrequestor-area").text('Error: ' + result.error.info);
				} else {
					$("#editrequestor-area").text(result.prop.wikitext['*']);
					$("#editrequestor-area").prop("disabled", false);
				}
			}
		});
	});
}