Jump to content

User:Technical 13/Scripts/ACCHelp/Block list.js

From Wikipedia, the free encyclopedia
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(mw.config.get("wgCanonicalSpecialPageName") === "BlockList"){
	$("p:contains(\"The requested IP address or username is not blocked.\")").addClass("error");
	if(typeof($("p:contains(\"The requested IP address or username is not blocked.\")").html()) === "undefined"){
		var blocklistTable = '\n\t<thead>\n\t\t<tr style="text-align: center;">\n\t\t\t<th>Admin</th>\n\t\t\t<th>blocked</th>\n\t\t\t<th>Target</th>\n\t\t\t<th>because</th>\n\t\t\t<th>expires</th>\n\t\t</tr>\n\t</thead>\n\t</tbody>';
		$('table.mw-blocklist tbody').find('tr').each(function(){
			var blocklistAdmin = $(this).find('td.TablePager_col_ipb_by').html();
			blocklistAdmin = blocklistAdmin.replace(/(\(|\))/ig, '$1').replace(/&nbsp;\| /ig, '|').replace('>talk</a>', '>t</a>').replace('>contribs</a>', '>c</a>');
			var blocklistTimestamp = $(this).find('td.TablePager_col_ipb_timestamp').html();
			var blocklistTimestampISO = new Date(blocklistTimestamp);
			blocklistTimestampISO = blocklistTimestampISO.toISOString();
			blocklistTimestampReturn = '<a href="/w/index.php?title=Special:Log&type=block&limit=1&dir=prev&offset=' + blocklistTimestampISO.replace(/(\-|T|:|\.|Z)/ig, "")+1 + '" title="view entry in block log">' + blocklistTimestamp + '</a>';
			blocklistTimestamp = new Date(blocklistTimestamp);
			var blocklistTarget = $(this).find('td.TablePager_col_ipb_target').html();
			if(blocklistTarget.indexOf("</a>") === -1){
				blocklistTarget = '<a href="/wiki/Special:Contributions/' + blocklistTarget + '" title="contributions of ' + blocklistTarget + '" class="mw-userlink">' + blocklistTarget + '</a><span class="mw-usertoollinks"><code>(<a href="/wiki/User_talk:' + $('input#mw-input-wpTarget').val() + '" title="User talk:' + $('input#mw-input-wpTarget').val() + '">t</a>)</code></span>';
			} else {
				blocklistTarget = blocklistTarget.replace(/(\(|\))/ig, '1').replace(/&nbsp;\| /ig, '|').replace('>talk</a>', '>t</a>');
			}
			var blocklistReason = $(this).find('td.TablePager_col_ipb_reason').html();
			if(blocklistReason.search(/\{\{(.*?)\}\}/) !== -1){
				blocklistReason = $(this).find('td.TablePager_col_ipb_reason').html().match(/\{\{(.*?)\}\}(.*?)/);
				blocklistReason = '{'+'{<a href="/wiki/Template:' + blocklistReason[1].charAt(0).toUpperCase() + blocklistReason[1].substr(1) + '" title="Template:' + blocklistReason[1].charAt(0).toUpperCase() + blocklistReason[1].substr(1) + '">' + blocklistReason[1].charAt(0).toUpperCase() + blocklistReason[1].substr(1) + '</a>}'+'}' + blocklistReason[2];
			}
//			var blocklistExpires = new Date($(this).find('td.TablePager_col_ipb_expiry').html());
			var blocklistParameters = $(this).find('td.TablePager_col_ipb_params').html();
			blocklistParameters = blocklistParameters.split(", ").sort().join(", ");
//			var blocklistExpiresIn = new Date();
//			blocklistExpiresIn = blocklistExpires.getTime() - Date.now();
var			blocklistExpires = $(this).find('td.TablePager_col_ipb_expiry').html();
			blocklistTable += '\n\t\t<tr style="text-align: center;">\n\t\t\t<td class="TablePager_col_ipb_by">' + blocklistAdmin + '</td>\n\t\t\t<td class="TablePager_col_ipb_timestamp">' + blocklistTimestampReturn + '</td>\n\t\t\t<td class="TablePager_col_ipb_target">' + blocklistTarget + '</td>\n\t\t\t<td class="TablePager_col_ipb_reason TablePager_col_ipb_params">' + blocklistReason + ', ' + blocklistParameters + '</td>\n\t\t\t<td class="TablePager_col_ipb_expiry">' + blocklistExpires + '</td>\n\t\t</tr>';
		});
		blocklistTable += '\n\t</tbody>';
		$('table.TablePager').css({"border": "", "width": "100%"});
		$('table.TablePager').html(blocklistTable);
		$("h1#firstHeading").html(tickBad + " " + $("h1#firstHeading").html());
		document.title = Ucross + document.title;
		var blocklistTimestampWeek = blocklistTimestamp.valueOf()+(7*24*60*60*1000);
		if(blocklistTimestampWeek >= Date.now()){
			alert('WARNING!\n\t\tThe local block on:\n\n\t\t\t\t' + $("input#mw-input-wpTarget").val() + '\n\n\t\t... is less than a week old.');
		}
	} else {
		$("h1#firstHeading").html(tickGood + " " + $("h1#firstHeading").html());
		document.title = Ucheck + document.title;
	}
}