Jump to content

User:Macaw*/NBE.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Macaw* (talk | contribs) at 13:10, 2 May 2025 (hopefully now). 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.
// NBE or Not Bad Edits was created by Macaw*

// CONFIGURATION: Enable features by setting to '1' or '0'
const enableMissingCoordinates = '1'; 
const enableUnreferenced = '1'; 
const enableMissingInfo = '1'; 

NBE.addPortlet = function() {
	let navigation;
	let id;
	let text;
	let nextnodeid;

	switch (mw.config.get('skin')) {
		case 'vector':
		case 'vector-2022':
			navigation = '#right-navigation';
			id = 'p-nbe';
			text = 'NBE';
			nextnodeid = 'p-cactions';
			break;
		case 'timeless':
			navigation = '#page-tools .sidebar-inner';
			id = 'p-nbe';
			text = 'NBE';
			nextnodeid = 'p-userpagetools';
			break;
		default:
			navigation = null;
			id = 'p-cactions';
	}

	if (navigation === null) {
		return id;
	}

	const root = document.querySelector(navigation);
	if (!root) {
		return id;
	}

	const item = document.getElementById(id);
	if (item) {
		return id;
	}

	mw.util.addPortlet(id, text, '#' + nextnodeid);

	if (mw.config.get('skin') === 'vector') {
		$('#p-nbe').insertAfter('#p-cactions');
	} else if (mw.config.get('skin') === 'vector-2022') {
		const $landmark = $('#right-navigation > .vector-page-tools-landmark');
		$('#p-nbe-dropdown').insertAfter($landmark);
	}

	return id; // Ensure to return the id at the end
};

NBE.addPortletLink = function(task, text, id, tooltip) {
	const portletId = NBE.addPortlet();

	const link = mw.util.addPortletLink(portletId, typeof task === 'string' ? task : '#', text, id, tooltip);

	$('.client-js .skin-vector #p-cactions').css('margin-right', 'initial');

	if (typeof task === 'function') {
		$(link).on('click', (ev) => {
			task();
			ev.preventDefault();
		});
	}
};

// Add links based on configuration
if (enableMissingCoordinates === '1') {
	NBE.addPortletLink('#', 'Missing Coordinates', 'missing-coordinates', 'Mark as missing coordinates.');
}

if (enableMissingInfo === '1') {
	NBE.addPortletLink('#', 'Missing Information', 'missing-information', 'Mark as missing information.');
}

if (enableUnreferenced === '1') {
	NBE.addPortletLink('#', 'Unreferenced', 'unreferenced', 'Mark as unreferenced.');
}

// Event handlers for the links
$(document).on('click', '#p-nbe .missing-coordinates', function(event) {
	event.preventDefault();
	const userInput = prompt("What is the general location of the missing coordinates?");
	if (userInput !== null) {
		document.editform.wpTextbox1.value = `{{coord missing|${userInput}}}\n` + document.editform.wpTextbox1.value; 
		document.editform.wpSummary.value = "Added Missing Coordinates Template with [[User:Macaw*/NBE|Not Bad Edits]]"; 
		document.editform.submit();
	}
});

$(document).on('click', '#p-nbe .missing-information', function(event) {
	event.preventDefault();
	const userInput = prompt("What information is this page missing?");
	if (userInput !== null) {
		document.editform.wpTextbox1.value = `{{Missing information|${userInput}}}\n` + document.editform.wpTextbox1.value; 
		document.editform.wpSummary.value = "Added Missing Information Template with [[User:Macaw*/NBE|Not Bad Edits]]"; 
		document.editform.submit();
	}
});

$(document).on('click', '#p-nbe .unreferenced', function(event) {
	event.preventDefault();
	const currentDate = new Date().toLocaleString('en-US', { year: 'numeric', month: 'long' });
	document.editform.wpTextbox1.value = `{{Unreferenced|date=${currentDate}}}\n` + document.editform.wpTextbox1.value; 
	document.editform.wpSummary.value = "Added Unreferenced Template with [[User:Macaw*/NBE|Not Bad Edits]]"; 
	document.editform.submit();
});

NBE.addPortlet();