User:Penguin-Pal/wikia.js/sandbox/closeThread.js

/* auto-close old forum thread discussions */ /* you can import this script by adding your Special:MyPage/wikia.js the following line: importScriptPage('User:Penguin-Pal/wikia.css/sandbox/closeThread.js', 'clubpenguin'); if (mw.config.get("wgNamespaceNumber") == 1201) { // check if namespace is Thread var last_thread_comment_timestamp = document.getElementsByClassName("timestamp")[document.getElementsByClassName("timestamp").length-1].innerText.substr(7); var last_thread_comment = new Date(last_thread_comment_timestamp); var last_thread_comment_year = last_thread_comment.getUTCFullYear; var last_thread_comment_month = last_thread_comment.getUTCMonth; var last_thread_comment_day = last_thread_comment.getUTCDate; // date - current date var currenttime = new Date; var currentyear = currenttime.getUTCFullYear; var currentmonth = currenttime.getUTCMonth; var 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 && 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 closeThread; }		}	} }