Utilisateur:Phe/monobook.js
Un article de Wikipédia, l'encyclopédie libre.
Note : Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements : Mozilla / Konqueror / Firefox : Shift-Ctrl-R, Internet Explorer / Opera : Ctrl-F5, Safari : Cmd-R.
/* <source lang="javascript"> */ /*loadJs('Utilisateur:EDUCA33E/LiveRC.js');*/ /*loadJs('Utilisateur:Phe/redirect ou page protégé.js');*/ loadJs('Utilisateur:Phe/Purge_hist_(maloq).js'); var wma_settings = { height : 400, width : 480, } var ugly_url = 'http://fr.wikipedia.org/w/index.php?title='; var pretty_url = 'http://fr.wikipedia.org/wiki/'; obtenir("FusionContribs"); /*loadJs('Utilisateur:Phe/sortable table.js');*/ /* == Popup de Lupin == */ document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); simplePopups=true; popupDelay=0.7; popupStructure='original'; popupOnEditSelection=false; popupAdminLinks=true; var oldEditsectionLinks = true; /* == Fonctions générales == */ function page_name_match(page_name, regexp) { var index = document.URL.indexOf(pretty_url + page_name); if (index != -1) index = document.URL.search(regexp); return index; } //-------------------------------------------------------------------- // XMLHttpRequest support //-------------------------------------------------------------------- if (document.implementation.createDocument) { var xmlparser = new DOMParser(); if (!xmlparser) { alert("Can't create xmlparser"); } } // ajax functionnality come from the god-mode script // by Sam Hocever, poulet.zoy.org function XMLParse(string) { if (document.implementation.createDocument) { return xmlparser.parseFromString(string, "text/xml"); } else if (window.ActiveXObject) { var xmldoc = new ActiveXObject("Microsoft.XMLDOM"); xmldoc.async = "false"; ret = xmldoc.loadXML(string); if (!ret) return null; return xmldoc.documentElement; } return null; } function HTTPClient() { var http; if(window.XMLHttpRequest) { http = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { http = false; } } } return http; } function do_edit_http_request(funct) { var xml_http_client = HTTPClient(); if (!xml_http_client) { alert("Can't create http client"); return; } url = document.URL.slice(pretty_url.length); url_name = ugly_url + url + '&action=edit'; xml_http_client.open("GET", url_name, true); xml_http_client.onreadystatechange = function() { if (xml_http_client.readyState != 4) return; newform = document.createElement('form'); doc = XMLParse(xml_http_client.responseText); form = doc.getElementById('editform'); funct(doc, newform, form); newform.name = form.name; newform.method = form.method; newform.id = form.id; newform.action = form.action; document.getElementById('bodyContent').innerHTML += '<br />Submitting'; document.getElementById('bodyContent').appendChild(newform); newform.submit(); } xml_http_client.send(null); delete xml_http_client; } /* == dist_edit et article_sans_cat == */ //------------------------------------------------------------------ // dist_edit et article_sans_cat /* return true if the most left html tag is a red link */ function first_red_link(li) { var a = li.getElementsByTagName('a'); if (!a || a.length == 0) return false; if (a[0].className == 'new') return true; return false; } /* return true if a part of the element is striked */ function striked_element(e) { return e.getElementsByTagName('s').length != 0; } function article_sans_cat_change_text(text) { var content = document.getElementById('bodyContent'); var input = content.getElementsByTagName("input"); var li = content.getElementsByTagName("li"); if (li.length != input.length) { alert('bad li/input count ' + li.length + ' ' + input.length) return text; } new_text = ''; lines = text.split('\n'); var k = 0; for (var j = 0; j < lines.length; ++j) { if (lines[j].indexOf('#') == 0) { if (k >= li.length) { alert('something feel bad, k >= input.length'); return text; } if (!input[k].disabled && !input[k].checked) { new_text += lines[j] + '\n'; } k++; } else { new_text += lines[j] + '\n'; } } if (k != input.length) { alert('k != input.length' + k + ' ' + input.length); return text; } return new_text; } function article_sans_cat_submit_change_step2(doc, newform, form) { l = form.getElementsByTagName('textarea'); for (i = l.length; i--; ) { var t = document.createElement('input'); t.type = 'hidden'; t.name = l[i].name; t.value = article_sans_cat_change_text(l[i].value); newform.appendChild(t); } l = form.getElementsByTagName('input'); for (i = l.length; i--; ) { if (l[i].name == 'wpSummary') { l[i].value = 'mise à jour'; } else if (l[i].name == 'wpMinoredit') { l[i].value = '1'; } else if (l[i].name == 'wpWatchthis') { if (!l[i].checked) continue; // Don’t touch the "watch" status l[i].value = "on"; } else if (l[i].name == 'wpPreview') { continue; } else if (l[i].name == 'wpDiff') { continue; } l[i].type = 'hidden'; newform.appendChild(l[i]); } return newform; } function article_sans_cat_submit_change_step1() { do_edit_http_request(article_sans_cat_submit_change_step2); } function article_sans_cat() { var page_name = 'Projet:Articles_sans_cat%C3%A9gories/'; var index = page_name_match(page_name, /gories\/([A-Z]|Autres|0-9|faune|flore|faune_et_flore|biographie)$/); var idx2 = document.URL.indexOf(pretty_url + 'Utilisateur:Phe/Page_vide/'); var idx3 = document.URL.indexOf(pretty_url + 'Projet:Articles_les_plus_demand%C3%A9s/'); var idx4 = document.URL.indexOf(pretty_url + 'Utilisateur:Phe/Orphaned_talk'); var idx5 = document.URL.indexOf(pretty_url + 'Utilisateur:Phe/Nouvelle_page/'); var idx6 = document.URL.indexOf(pretty_url + 'Utilisateur:Phe/temp'); if (index == -1 && idx2 == -1 && idx3 == -1 && idx4 == -1 && idx5 == -1 && idx6 == -1) return; content = document.getElementById('bodyContent'); var li = content.getElementsByTagName("li"); if (!li) return; for(var j = 0; j < li.length; j++) { input = document.createElement('input'); input.type = 'checkbox'; input.checked = false; //striked_element(li[j]); if (idx3 == -1) input.disabled = first_red_link(li[j]); else input.disabled = !first_red_link(li[j]); li[j].insertBefore(input, li[j].firstChild); } submit = document.createElement('button'); submit.type = 'submit'; submit.innerHTML = 'submit'; submit.onclick = article_sans_cat_submit_change_step1; content.appendChild(submit); } addOnloadHook(article_sans_cat); /* return true if the second left html tag is a red link */ function second_red_link(li) { var a = li.getElementsByTagName('a'); if (!a || a.length <= 1) return false; if (a[1].className == 'new') return true; return false; } /* return true if all a html element except two first are red link */ function other_red_link(li) { var a = li.getElementsByTagName('a'); if (!a || a.length <= 2) return false; for (var j = 2; j < a.length; j++) { if (a[j].className != 'new') return false; } return true; } function dist_edit_change_text(text) { var content = document.getElementById('bodyContent'); var input = content.getElementsByTagName("input"); var li = content.getElementsByTagName("li"); if (li.length * 2 != input.length) { alert('bad li/input count ' + li.length + ' ' + input.length) return text; } new_text = ''; lines = text.split('\n'); var k = 0; for (var j = 0; j < lines.length; ++j) { if (lines[j].indexOf('*') == 0) { if (k >= li.length) { alert('something feel bad, k >= input.length'); return text; } if (input[k*2].disabled || input[k*2+1].checked) { } else if (input[k*2].checked && lines[j].indexOf('<s>') == -1) { new_text += '*<s>' + lines[j].slice(1) + '</s>\n'; } else { new_text += lines[j] + '\n'; } k++; } else { new_text += lines[j] + '\n'; } } if (k * 2 != input.length) { alert('k != input.length' + k + ' ' + input.length); return text; } return new_text; } function dist_edit_submit_change_step2(doc, newform, form) { l = form.getElementsByTagName('textarea'); for (i = l.length; i--; ) { var t = document.createElement('input'); t.type = 'hidden'; t.name = l[i].name; t.value = dist_edit_change_text(l[i].value); newform.appendChild(t); } l = form.getElementsByTagName('input'); for (i = l.length; i--; ) { if (l[i].name == 'wpSummary') { l[i].value = 'mise à jour'; } else if (l[i].name == 'wpMinoredit') { l[i].value = '1'; } else if (l[i].name == 'wpWatchthis') { if (!l[i].checked) continue; // Don’t touch the "watch" status l[i].value = "on"; } else if (l[i].name == 'wpPreview') { continue; } else if (l[i].name == 'wpDiff') { continue; } l[i].type = 'hidden'; newform.appendChild(l[i]); } } function dist_edit_submit_change_step1() { do_edit_http_request(dist_edit_submit_change_step2); } function edit_by_distance() { var lien_rouge = true; var page_name = 'Projet:Restauration_lien_rouge/par_distance/'; var index = page_name_match(page_name, /par_distance\/([A-Z]|autres)$/); if (index == -1) index = page_name_match(page_name, /par_distance\/Exceptions\/([A-Z]|autres)\/[1-9]+$/); if (index == -1) index = page_name_match('Utilisateur:Phe/Projet:Restauration_lien_rouge/par_distance/', /par_distance\/([A-Z]|autres)$/); if (index == -1) { lien_rouge = false; page_name = 'Projet:Restauration_des_ancres_bris%C3%A9es/'; index = page_name_match(page_name, /bris%C3%A9es\/([A-Z]|Autres|0-9)$/); page_name = 'Projet:Biographie/Date_de_naissance_et_d%C3%A9c%C3%A8s_manquante/'; var idx1 = page_name_match(page_name, /manquante\/([A-Z]|Autres)$/); if (index == -1 && idx1 == -1) return; } var content = document.getElementById('bodyContent'); var li = content.getElementsByTagName("li"); if (!li) return; for(var j = 0; j < li.length; j++) { var input = document.createElement('input'); input.type = 'checkbox'; input.checked = striked_element(li[j]); input.disabled = first_red_link(li[j]); if (input.disabled == false && lien_rouge) input.disabled = !second_red_link(li[j]); if (input.disabled == false && lien_rouge) input.disabled = other_red_link(li[j]); var input2 = document.createElement('input'); input2.type = 'checkbox'; input2.checked = false; input2.disabled = input.disabled; li[j].insertBefore(input2, li[j].firstChild); li[j].insertBefore(input, li[j].firstChild); } var submit = document.createElement('button'); submit.type = 'submit'; submit.innerHTML = 'submit'; submit.onclick = dist_edit_submit_change_step1; content.appendChild(submit); } addOnloadHook(edit_by_distance); /* == Message vandalisme == */ /** * suivant le nom de la page et referer ajoute un {{vandalisme|article}} * ou un {{bienvenu}} ou {{bienvenue}} + la signature. Pour une page * utilisateur {{bienvenu}} est toujours utilisé, pour une page de * discussion d'un utilisateur {{bienvenue}} est utilisé si le referrer * est une page utilisateur sinon {{vandalisme}} est utilisé. */ function vandalisme_ou_bienvenu() { var user_talk = 'Discussion_Utilisateur:'; var user = 'Utilisateur:'; //if (document.ULR.indexOf(ugly_url + user_talk + 'Phe/') != -1) // return; var index1 = document.URL.indexOf(ugly_url + user_talk); var index2 = document.URL.indexOf(ugly_url + user); if (index1 == -1 && index2 == -1) return; if (document.editform == undefined) return; var text_area = document.editform.wpTextbox1; if (text_area.value.length == 0) { refferer = document.referrer; var text = '{{subst:' if (index2 != -1) { text += 'Bienvenu'; } else if (refferer.indexOf(pretty_url + user) != -1) { text += 'Bienvenue'; } else { refferer = refferer.slice(ugly_url.length); refferer = refferer.split('&')[0]; refferer = decodeURI(refferer); refferer = refferer.replace(/_/g, ' '); text += 'Vandalisme|' + refferer; } text += '}}\n~~~~'; text_area.value = text; } } addOnloadHook(vandalisme_ou_bienvenu); function getArticleName() { var strOut = document.title // case search if (strOut == "Rechercher - Wikipédia") return document.getElementById("lsearchbox").value // case article being modified strOut = strOut.replace("modification de ", "").replace(" - Modifier", "") strOut = strOut.replace(" - Prévisualiser", "").replace(" - Wikipédia", "") return strOut } /* * addOngletJournal * * Permet de passer d'une page à son log * * Auteur : bayo à partir de [[MediaWiki:Gadget-EditZeroth.js]] * [[Catégorie:MediaWiki:Fonction Monobook en JavaScript]] * identique au gadget + ajout d'une accessKey, phe */ function addOngletJournal() { if (!document.getElementById) { return; } x = document.getElementById('ca-talk'); if (!x) { return; } x = x.parentNode y = document.createElement('LI'); y.id = 'ca-log'; z = document.createElement('A'); z.accessKey = "a"; uri = wgScript + '?title=Special:Journal&page=' + encodeURI(wgPageName) z.href = uri; z.appendChild(document.createTextNode('journal')); y.appendChild(z); x.appendChild(y); } if ( wgNamespaceNumber >= 0 ) { addOnloadHook(addOngletJournal); } /* == Page spécial undelete == */ //---------------------------------------------------- function UndeleteSelectAll() { if (getArticleName() != "Voir et restaurer la page supprimée") return; var title2 = document.getElementsByTagName("h2") var all = document.createElement("input") all.setAttribute("type", "checkbox") all.setAttribute("onchange", "selectAll(this.checked)") all.setAttribute("title", "Sélectionner/Désélectionner tous") if (title2.length > 0) title2[title2.length -1].appendChild(all) all.click() } function selectAll(bool) { var inputs = document.getElementsByTagName("input") for (var cpt = 0 ; cpt < inputs.length ; cpt++) inputs[cpt].checked = bool } addOnloadHook(UndeleteSelectAll) function setFocus() { if (document.editform == undefined) return; var text_area = document.editform.wpTextbox1; if (text_area) text_area.focus(); } //addOnloadHook(setFocus); /* == Timing == */ var millisecs; var secs; function begin_time() { date = new Date(); millisecs = date.getMilliseconds(); secs = date.getSeconds(); } function end_time() { date = new Date(); var msec = date.getMilliseconds() - millisecs; if (msec < 0) { msec += 1000; secs += 1; } alert((date.getSeconds() - secs) + '.' + msec); } /*</source>*/