Ao3 De-Piped Tags

For some fandoms, a character is given two names, like: "Geralt z Rivii | Geralt of Rivia". This script lets you choose which name you want to see.

  1. // ==UserScript==
  2. // @name Ao3 De-Piped Tags
  3. // @match https://archiveofourown.org/*
  4. // @match http://archiveofourown.org/*
  5. // @version 1.1
  6. // @author laireshi
  7. // @description For some fandoms, a character is given two names, like: "Geralt z Rivii | Geralt of Rivia". This script lets you choose which name you want to see.
  8. // @namespace https://greasyfork.org/users/991512
  9. // ==/UserScript==
  10.  
  11. //SCRIPT SETTINGS//
  12. const sideToDisplay = 'right'; //left OR right, for character tags with one pipe (two names)
  13. const partToDisplay = 'right'; // left OR right OR central, for character tags with two pipes (three names)
  14. const tagsOnFicPage = 0; //0 to disable, 1 to enable
  15.  
  16. //SCRIPT FUNCTIONS//
  17. const shortenCharTag = function (fullTag){
  18. 'use strict';
  19.  
  20. const pipe = fullTag.indexOf('|');
  21. let pipeRight = -1;
  22. if (pipe !== fullTag.lastIndexOf('|')) {
  23. pipeRight = fullTag.lastIndexOf('|');
  24. }
  25. let newTag;
  26. if (pipeRight === -1) { //just one pipe
  27. newTag = sideToDisplay === 'left' ? fullTag.slice(0, pipe - 1) : newTag = fullTag.slice(pipe + 2);
  28. } else { //two pipes
  29. newTag = partToDisplay === 'left' ? fullTag.slice(0, pipe - 1) : partToDisplay === 'right' ? fullTag.slice(pipeRight + 2) : fullTag.slice(pipe + 2, pipeRight);
  30. }
  31. return newTag.trim();
  32. };
  33.  
  34. const shortenRelTag = function(fullTag){
  35. 'use strict';
  36. const gen = '&';
  37. const rom = '/';
  38. let names = fullTag.includes(rom) ? fullTag.split(rom) : fullTag.replace(/& */g,'&').split(gen);
  39. names = names.map(n => {
  40. return n.includes('|') ? shortenCharTag(n) : n;
  41. });
  42. return fullTag.includes(rom) === true ? names.join(rom) : names.join(` ${gen} `);
  43. };
  44.  
  45. const shortenPipes = function(){
  46. 'use strict';
  47. //work blurbs when browsing tag pages
  48. let chars = Array.from(document.getElementsByClassName('characters'));
  49. chars.forEach(char => {
  50. let charTag = char.childNodes[0].innerHTML;
  51. if (charTag.includes('|')) {
  52. charTag = shortenCharTag(charTag);
  53. char.childNodes[0].innerHTML = charTag;
  54. }
  55. });
  56. let rels = Array.from(document.getElementsByClassName('relationships'));
  57. rels.forEach(rel => {
  58. let relTag = rel.childNodes[0].innerHTML;
  59. if (relTag.includes('|')) {
  60. relTag = shortenRelTag(relTag);
  61. rel.childNodes[0].innerHTML = relTag;
  62. }
  63. });
  64.  
  65. //on a single work page
  66. if (tagsOnFicPage === 1) {
  67. let charsFic = Array.from(document.querySelectorAll('dd.character a'));
  68. charsFic.forEach(cF => {
  69. let cFTag = cF.innerHTML;
  70. if (cFTag.includes('|')) {
  71. cFTag = shortenCharTag(cFTag);
  72. cF.innerHTML = cFTag;
  73. }
  74. });
  75. let relsFic = Array.from(document.querySelectorAll('dd.relationship a'));
  76. relsFic.forEach(rF => {
  77. let rFTag = rF.innerHTML;
  78. if (rFTag.includes('|')) {
  79. rFTag = shortenRelTag(rFTag);
  80. rF.innerHTML = rFTag;
  81. }
  82. });
  83. }
  84. };
  85.  
  86. shortenPipes();