משתמש:Mikimik/js/autoUserWarnings.js
מראה
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
if ( !userTPWarnings ) var userTPWarnings =
[ "בחרו הודעה/אזהרה להוספה", //X
"אזהרה", "הבל", "ניסויים", "נמחק", "נמחק ניסויים", "בוטל", "חזרה על עריכה", "פרסומת", "קישור מבוטל", "העתקה", "לך", "נחסמת", //X
"הסבר", "כוונות טובות", "הזמנה", "תודה", "ברוך הבא", //X
"שגיאה", "כבר קיים", "עבר", "לא כאן", //X
"ויקיזציה", "סגנון", "נייטרליות", "מילון" ]; //X
if ( !userDiffWarnings ) var userDiffWarnings = [ "אזהרה", "ניסויים", "בוטל", "פרסומת", "לא כאן", "תודה" ];
if ( !userRollbackWarnings ) var userRollbackWarnings = [ "אזהרה", "ניסויים", "בוטל", "לא כאן", "פרסומת", "נחסמת", "שגיאה", "תודה" ];
if ( !userDeleteWarnings ) var userDeleteWarnings = [ "הבל", "נמחק ניסויים", "נמחק", "אזהרה", "נחסמת" ];
if ( !userBlockWarnings ) var userBlockWarnings = [ "נחסמת", "הבל", "נמחק ניסויים" ];
//---
// in user talk page: add a list of warning templates to the toolbar
function createUserTalkWarningsSelectList()
{
try {
if ( !document.getElementById("t-contributions") ) return; // not a user talk page
var select = document.createElement("select");
select.id = "userWarningsList";
for ( var i in userTPWarnings )
{
var option = document.createElement("option");
select.options.add ( option );
option.appendChild ( document.createTextNode(userTPWarnings[i]) );
option.title = userTPWarnings[i];
}
select.onchange =
function() {
if ( this.selectedIndex )
{
document.getElementById("wpTextbox1").value += ( /(^|\n)$/.test(document.getElementById("wpTextbox1").value) ? "" : "\n" ) +
"{" + "{" + this.options[this.selectedIndex].firstChild.nodeValue + "}} ~~" + "~~";
document.getElementById("wpSummary").value += ( /(^| )$/.test(document.getElementById("wpSummary").value) ? "" : ", " ) +
this.options[this.selectedIndex].firstChild.nodeValue;
}
this.selectedIndex = 0;
return false;
};
document.getElementById("toolbar").appendChild ( select );
}
catch(e)
{
return; // lets just ignore what's happened
}
}
if ( ( wgAction == "edit" || wgAction == "submit" ) && wgNamespaceNumber == 3 && wgTitle != wgUserName )
hookEvent ( "load", createUserTalkWarningsSelectList );
//---
function getUserWarningLinks ( username, warningsList )
{
function createWarningLink ( warning, alt )
{
var link = document.createElement("a");
link.href = wgScript + "?title=User_Talk:" + encodeTextToWikiURL(username) +
"&action=edit&userwarning=" + encodeTextToWikiURL(warning) +
( alt || wgNamespaceNumber < 0 ? "" : "&frompage=" + (wgNamespaceNumber == 6 || wgNamespaceNumber == 14 ? ":" : "") +
encodeTextToWikiURL(wgPageName) );
link.appendChild ( document.createTextNode( alt ? "X" : warning ) );
link.title = "הוספת תבנית לדף המשתמש: " + warning + ( alt ? " (ללא שם הדף)" : "" );
return link;
}
var span = document.createElement("span");
span.className = "mk-userWarningLinks";
if ( username == wgUserName ) return span;
span.appendChild ( document.createTextNode( " (" ) );
for ( var i in warningsList )
{
span.appendChild ( createWarningLink( warningsList[i] ) );
if ( wgNamespaceNumber >= 0 )
{
span.appendChild ( document.createTextNode(" ") );
span.appendChild ( createWarningLink( warningsList[i], true ) );
}
span.appendChild ( document.createTextNode(" | ") );
}
span.replaceChild ( document.createTextNode(")"), span.lastChild );
return span;
}
function postUserWarningOnTalkPage()
{
try {
if ( typeof(window.postUserWarningOnTalkPageOnlyOnce_safety) != 'undefined' ) return;
window.postUserWarningOnTalkPageOnlyOnce_safety = true;
document.getElementById("wpTextbox1").value += ( getParamValue("frompage") ? "\n== [" + "[" + getParamValue("frompage").replace(/_/g," ") + "]] ==" : "" ) + "\n{" + "{" + getParamValue("userwarning") + "}} ~~" + "~~";
document.getElementById("wpSummary").value = getParamValue("userwarning");
document.getElementById("editform").submit();
}
catch(e)
{
return; // lets just ignore what's happened
}
}
if ( wgAction == "edit" && getParamValue("userwarning") ) addOnloadHook ( postUserWarningOnTalkPage );
//---
// in diff page: add links to add templates to user talk page
function initDiffWarningLinks()
{
try {
if ( !document.getElementById("mw-diff-otitle2") || !document.getElementById("mw-diff-ntitle2") ) return;
var point = document.getElementById("mw-diff-otitle2").getElementsByTagName("a")[0];
point.parentNode.insertBefore ( getUserWarningLinks(point.firstChild.nodeValue,userDiffWarnings), point.nextSibling );
point = document.getElementById("mw-diff-ntitle2").getElementsByTagName("a")[0];
point.parentNode.insertBefore ( getUserWarningLinks(point.firstChild.nodeValue,userDiffWarnings), point.nextSibling );
}
catch(e)
{
return; // lets just ignore what's happened
}
}
if ( getParamValue("diff") ) addOnloadHook ( initDiffWarningLinks );
// after rollback: add links to add templates to user talk page
function initRollbackWarningLinks()
{
try {
var point = document.getElementsByClassName("mw-userlink")[0];
if ( point ) point.parentNode.insertBefore ( getUserWarningLinks(point.firstChild.nodeValue,userRollbackWarnings), point.nextSibling );
}
catch(e)
{
return; // lets just ignore what's happened
}
}
if ( wgAction == "rollback" ) addOnloadHook ( initRollbackWarningLinks );
// in blocked successfully page: add links to add templates to user talk page
function initBlockWarningLinks()
{
try {
var alllinks = document.getElementById("bodyContent").getElementsByTagName("a");
for ( var i = 0 ; alllinks[i] && alllinks[i].firstChild.nodeValue.replace(/[_\+]/g," ") != getParamValue("ip").replace(/[_\+]/g," ") ; ) i++;
if ( alllinks[i] )
alllinks[i].parentNode.insertBefore ( getUserWarningLinks(alllinks[i].firstChild.nodeValue,userBlockWarnings), alllinks[i].nextSibling );
}
catch(e)
{
return; // lets just ignore what's happened
}
}
if ( wgCanonicalSpecialPageName == "Blockip" && wgAction == "success" && getParamValue("ip") ) addOnloadHook ( initBlockWarningLinks );