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.

目前为 2022-12-02 提交的版本。查看 最新版本

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