Make links to PYSIDE bug reports

Make links to PYSIDE bug reports on https://wiki.qt.io/Qt_for_Python_Development_Notes page

Stan na 03-11-2023. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Make links to PYSIDE bug reports
// @namespace   Violentmonkey Scripts
// @match       https://wiki.qt.io/Qt_for_Python_Development_Notes
// @grant       none
// @version     1.0.1
// @author      StSav012
// @description Make links to PYSIDE bug reports on https://wiki.qt.io/Qt_for_Python_Development_Notes page
// ==/UserScript==

"use strict";

function bugreportsLink(bug) {
  const a = document.createElement('A');
  a.setAttribute('class', "external text");
  a.setAttribute('rel', "nofollow");
  a.setAttribute('href', 'https://bugreports.qt.io/browse/' + bug);
  a.appendChild(document.createTextNode(bug));
  return a;
}

function repl(str) {
  const bugreportPattern = /PYSIDE-\d+/g;
  var bugs = str.match(bugreportPattern);
  if (bugs === null) {
    return [str];
  }
  var newNodes = [];
  if (str.startsWith(bugs[0])) {
    newNodes.push(bugreportsLink(bugs.shift()));
  }
  var textParts = str.split(bugreportPattern);
  while (textParts.length || bugs.length) {
    var text = textParts.shift();
    if (text !== undefined && text.length) {
      newNodes.push(text);
    }
    var bug = bugs.shift();
    if (bug !== undefined) {
      newNodes.push(bugreportsLink(bug));
    }
  }
  return newNodes;
}

function makeLinks(parent) {
  for (let n of parent.childNodes) {
    if (parent.tagName === 'A') {  // should be here in case `parent` changes
      return;
    }
    if (n.tagName === 'A') {
      continue;
    }
    if (n.nodeName === "#text" && n.nodeValue !== undefined) {
      n.replaceWith(...repl(n.nodeValue));
    } else {
      makeLinks(n);
    }
  }
}
makeLinks(document.body);