MediaWiki:Common.js/closeThread.js

/*

this feature automatically disables commenting in old threads works both in Oasis and Monobook

if (mw.config.get("wgNamespaceNumber") == 1201) { // check if namespace is Thread // date - last message posting date var getTimestamps = document.getElementsByClassName("timestamp"), getTimestampsSpan = getTimestamps[getTimestamps.length-1].getElementsByTagName("span"), last_thread_comment_timestamp = getTimestampsSpan[getTimestampsSpan.length-1].innerText.substr(7), last_thread_comment = new Date(last_thread_comment_timestamp), last_thread_comment_year = last_thread_comment.getUTCFullYear, last_thread_comment_month = last_thread_comment.getUTCMonth, last_thread_comment_day = last_thread_comment.getUTCDate, // date - current date currenttime = new Date, currentyear = currenttime.getUTCFullYear, currentmonth = currenttime.getUTCMonth, currentday = currenttime.getUTCDate; // closeThread function function closeThread { document.getElementsByClassName("editarea")[document.getElementsByClassName("editarea").length-1].innerHTML = "This thread hasn't been edited for over a month. There is no reason to add new replies. "; }	// date logic if (document.getElementsByClassName("message-main")[0].children[0].className != "deleteorremove-infobox") { if (last_thread_comment_year + 1 < currentyear) { // posted n years ago closeThread; } else if (last_thread_comment_year + 1 == currentyear) { // posted a year ago if (last_thread_comment_month - 11 == currentmonth && last_thread_comment_day <= currentday) { // posted a year ago but 1 month ago closeThread; } else if (last_thread_comment_month - 11 < currentmonth) { // posted a year ago but n months ago closeThread; }		} else { // posted this year if (last_thread_comment_month + 1 < currentmonth) { // n months ago this year closeThread; } else if (last_thread_comment_month + 1 == currentmonth) { if (last_thread_comment_day < currentday) { // posted a month ago and the day number is smaller than the current day number closeThread; }			} else { // posted less than a month ago, in the following way: // a month ago but posted later than the current day number // posted this month // don't close thread }		}	} }