Участник:Js/autodel.js

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
//[[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( mw.config.get('wgCanonicalSpecialPageName') == "BrokenRedirects" || mw.config.get('wgCanonicalSpecialPageName') == "Contributions" || mw.config.get('wgCanonicalSpecialPageName') == "WhatLinksHere" || mw.config.get('wgCanonicalSpecialPageName') == "Log" || mw.config.get('wgCanonicalSpecialPageName') == "PrefixIndex" || mw.config.get('wgCanonicalSpecialPageName') == "NewPages" || (mw.config.get('wgIsArticle') == true && (mw.config.get('wgAction') == "submit" || mw.config.get('wgAction') == "view" || mw.config.get('wgAction') == "purge"))) addOnloadHook(function(){
	mw.util.addPortletLink('p-cactions','javascript:deleteLinkify()','Автоудаление','ca-dellink','создать ссылки для удаления');
})
 
function deleteLinkify() {
	var reason = prompt('Введите причину удаления','согласно [[ВП:КБУ]]');
	if(!reason) return;
	var links = document.getElementById('bodyContent').getElementsByTagName('a');
	var arp = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace(/\$1/,'');
	if(links.length == 0) return
	for(var i=0;i<links.length;i++) {
		if(links[i].href.replace(/https?:/,'').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' && ( mw.config.get('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(mw.config.get('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;
}