Wikipedia:WikiProject User scripts/Scripts/WikiBreak Enforcer

Wikipedia:WikiProject User scripts Scripts WikiBreak Enforcer

Wikipedia:WikiProject User scripts/Scripts/WikiBreak Enforcer

WikiBreak Enforcer is a script that prevents a user from logging in before a certain date, to help enforce a wikibreak. If the user logs in, they are automatically logged back out, but can still view or edit from the mobile interface, or as a temporary account.

How to Use

  1. Copy the code under Script below between /*** BEGIN WIKIBREAK ENFORCER ***/ and /*** END WIKIBREAK ENFORCER ***/.
  2. Paste the code on your user JavaScript page, and then change the lines starting with var date and var time to reflect the time you want your break to end (local time). The var date line defines the date your break will end, while the var time defines the time on that day that your break will end. For example, for a break ending at 8:22 pm on 6 February 2019, one would enter the settings:
    	var date = { year: 2019, month: 2, day: 6 };
    	var time = { hours: 20, minutes: 22, seconds: 0 };
    
  3. Save the edited user JavaScript page.
    Information Note: Previewing your edit will log you out, but will not implement the enforcer.
  4. Purge the page. If successful, you will be logged out.
  5. That's it: enjoy your wikibreak! 🙂

Script

/*** BEGIN WIKIBREAK ENFORCER ***/
$(document).ready(function() 
{

	/*** Start editing here ***/

	// When you want to end your break?
	// no leading zeroes. (example: 9 - correct, 09 - incorrect)

	var date = { year: 2020, month: 2, day: 11};
	var time = { hours: 20, minutes: 22, seconds: 0 };

	/*** Stop editing here ***/
	
	var currentDate = new Date();
	var enforcedBreakEnd = new Date(
		date.year,date.month-1,date.day,time.hours,time.minutes,time.seconds);
	$.getJSON("/w/api.php?action=query&meta=siteinfo&siprop=general&format=json", function(data) {
        var serverTimeStr = data.query.general.time; // ISO 8601 string
        var serverTime = new Date(serverTimeStr);

        if (serverTime < enforcedBreakEnd) {
			alert("Enforced wikibreak until "+enforcedBreakEnd.toLocaleString()
				+ "\n(now is "+currentDate.toLocaleString()+")\n\nBye!");
			mw.loader.using(["mediawiki.api", "mediawiki.user"]).then(function ()
			{
				new mw.Api().post(
				{
					action: 'logout',
					token: mw.user.tokens.get('csrfToken')
				}).done(function (data)
				{
					location = "//" + location.host + "/w/index.php?title="
						 + "Special:Userlogin&returnto=Main_Page";
				}).fail(function ()
				{
					console.log("logout failed");
				});
			});
        }
	});
});
/*** END WIKIBREAK ENFORCER ***/

See also

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.