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

Материал из Викицитатника
Содержимое удалено Содержимое добавлено
Нет описания правки
Нет описания правки
Строка 2: Строка 2:
mw.hook('wikipage.content').add(function ($content) {
mw.hook('wikipage.content').add(function ($content) {
$content.find('.tpl-permalink-reason a').attr('href', function (i, oldVal) {
$content.find('.tpl-permalink-reason a').attr('href', function (i, oldVal) {
var tpl = document.querySelectorAll('.tpl-permalink-reason');
var links = document.querySelectorAll('.tpl-permalink-reason a');
var links = tpl.querySelectorAll('a');
var usernames = document.querySelectorAll('.tpl-permalink-reason .userlink');
var usernames = tpl.querySelectorAll('.userlink');
var label = {
var label = {
"ЗСАП": encodeURIComponent("ВП:ЗСАП"),
"ЗСАП": encodeURIComponent("ВП:ЗСАП"),

Версия от 21:06, 30 апреля 2020

// script
mw.hook('wikipage.content').add(function ($content) {
  $content.find('.tpl-permalink-reason a').attr('href', function (i, oldVal) {
    var links = document.querySelectorAll('.tpl-permalink-reason a');
    var usernames = document.querySelectorAll('.tpl-permalink-reason .userlink');
    var label = {
        "ЗСАП": encodeURIComponent("ВП:ЗСАП"),
        "ЗСПАТ": encodeURIComponent("ВП:ЗСПАТ"),
        "ЗСПИ": encodeURIComponent("ВП:ЗСПИ")
    }
    var regular = new RegExp('%5B%5B.*?%7C' + '(' + label["ЗСАП"] + '|' + label["ЗСПАТ"] + '|' + label["ЗСПАТ"] + ')' + '%5D%5D', 'g')
    var name = Array.from(oldVal.matchAll(regular))[0]
    var username = usernames[i].text
    if (name !== undefined) {
    	return oldVal.replace(regular, encodeURIComponent(
      '[[Special:Permalink/' + (mw.config.get('wgRevisionId') + "#" + username || mw.config.get('wgCurRevisionId')) + "#" + username + '|' + decodeURIComponent(name[1]) + ']]'
    ));
    }
  });
});