Участник:VasilievVV/autodel.js: различия между версиями

Содержимое удалено Содержимое добавлено
Новая страница: «//Mike.lifeguard // Outline for an automatic delete link generator. // Not highly tested. Started by Splarka @ test.wikipedia // Written fo...»
(нет различий)

Версия от 09:18, 18 августа 2009

//[[Category:User scripts|Mike.lifeguard]]
// Outline for an automatic delete link generator.
// Not highly tested. Started by Splarka @ test.wikipedia
// Written for & maintained by Mike_lifeguard @ en.wikibooks
 
//GO IF contribs or log or newpages or [article AND (submit|view|purge)]
 
if( wgCanonicalSpecialPageName == "BrokenRedirects" || wgCanonicalSpecialPageName == "Contributions" || wgCanonicalSpecialPageName == "WhatLinksHere" || wgCanonicalSpecialPageName == "Log" || wgCanonicalSpecialPageName == "PrefixIndex" || wgCanonicalSpecialPageName == "NewPages" || (wgIsArticle == true && (wgAction == "submit" || wgAction == "view" || wgAction == "purge"))) addOnloadHook(function(){
	addPortletLink('p-cactions','javascript:deleteLinkify()','автоудаление','ca-dellink','создать ссылки для удаления');
})
 
function deleteLinkify() {
	var reason = prompt('Введите причину удаления','согласно [[ВП:КБУ]]');
	if(!reason) return;
	var links = document.getElementById('bodyContent').getElementsByTagName('a');
	var arp = wgServer + wgArticlePath.replace(/\$1/,'');
	if(links.length == 0) return
	for(var i=0;i<links.length;i++) {
		if(links[i].href.indexOf(arp)==0 && links[i].href.indexOf('action=delete') == -1 && links[i].href.indexOf('Служебная:') == -1 ) {
			links[i].href += '?action=delete&submitdelete=true&deletetalkalso=true&wpReason=' + encodeURIComponent(reason);
			links[i].innerHTML += ' (удалить)';
		}
	}
}
 
if(queryString('submitdelete') == 'true') addOnloadHook(function() {
	if(document.getElementById('ca-talk').className.indexOf('new')==-1 && queryString('deletetalkalso')=='true' && ( wgNamespaceNumber % 2 == 0 ) ) {//if the talk tab is redlinked and this is the first time 'round AND this is not a talk page then:
		document.getElementById('deleteconfirm').action += '&deletetalk=true&wpReason=' + queryString('wpReason');
	}
	var sub = (document.getElementById('wpConfirmB')) ? document.getElementById('wpConfirmB') : document.getElementById('mw-filedelete-submit')
	sub.click();
})
 
if(wgAction == 'delete' && queryString('deletetalk') == 'true') addOnloadHook(function() {
	var url = document.getElementById('ca-talk').getElementsByTagName('a')[0].href + '?action=delete&submitdelete=true&wpReason=' + queryString('wpReason');
	document.location.href = url;
})
 
function queryString(p) {
  var re = RegExp('[&?]' + p + '=([^&]*)');
  var matches;
  if (matches = re.exec(document.location)) {
    try { 
      return decodeURI(matches[1]);
    } catch (e) {
    }
  }
  return null;
}