LibraryThing blurber author pages

For each of the blurbers listed on a work, this script creates a link to their author page (assumes it exists)

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        LibraryThing blurber author pages
// @namespace   https://greasyfork.org/en/users/11592-max-starkenburg
// @description For each of the blurbers listed on a work, this script creates a link to their author page (assumes it exists)
// @include     http*://*.librarything.tld/work/*
// @include     http*://*.librarything.com/work/*
// @version     2
// @grant       none
// ==/UserScript==

var blurbers = document.querySelector("[fieldname=blurbers]").getElementsByClassName("fwikiItemText");

if (blurbers.length) {
  for (var i=0; i<blurbers.length; i++) {
    var blurber = blurbers[i];
    var string = blurber.textContent.trim();
    if (string != "") {
      var parens = new RegExp("\\(.*\\)","g");
      if (string.replace(parens,"") != "") { // Remove any parenthetical text, unless the string is entirely parenthetical (probably unnecessary for blurbers, but who knows)
        string = string.replace(parens,"");
      }
      if (string.indexOf(",") == -1) { // Since sometimes people have written them as "First Last" instead of "Last, First" (though these should really just be fixed)
        var lastspace = string.lastIndexOf(" ");
        string = string.substring(lastspace) + string.substring(0,lastspace);
      }
      string = string.toLowerCase().replace(/[^a-z]/g,"").substring(0,20); // Remove non-alpha character, lower-case it, and limit it to 20 characters
      if (string.length) { // Just in case it was all non-Latin characters, whose number generation is a mystery to me
        var aLink = document.createElement("span");
        aLink.style.cssFloat = "right";
        aLink.style.fontSize = ".9em";
        aLink.innerHTML = '(<a href="/author/' + string + '">author page</a>)';
        blurber.insertBefore(aLink, blurber.firstChild); // Attach it somewhere that won't get in the way while editing
      }
    }
  }
}