您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
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.
当前为
- // ==UserScript==
- // @name Ao3 De-Piped Tags
- // @match https://archiveofourown.org/*
- // @match http://archiveofourown.org/*
- // @version 1.0
- // @author laireshi
- // @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.
- // @namespace https://greasyfork.org/users/991512
- // ==/UserScript==
- const sideToDisplay = 'right'; //left OR right, for character tags with one pipe (two names)
- const partToDisplay = 'right'; // left OR right OR central, for character tags with two pipes (three names)
- const tagsOnFicPage = 0; //0 to disable, 1 to enable
- const shortenCharTag = function (fullTag){
- 'use strict';
- const pipe = fullTag.indexOf('|');
- let pipeRight = -1;
- if (pipe !== fullTag.lastIndexOf('|')) {
- pipeRight = fullTag.lastIndexOf('|');
- }
- let newTag;
- if (pipeRight === -1) { //just one pipe
- newTag = sideToDisplay === 'left' ? fullTag.slice(0, pipe - 1) : newTag = fullTag.slice(pipe + 2);
- } else { //two pipes
- newTag = partToDisplay === 'left' ? fullTag.slice(0, pipe - 1) : partToDisplay === 'right' ? fullTag.slice(pipeRight + 2) : fullTag.slice(pipe + 2, pipeRight);
- }
- return newTag.trim().replace('amp; ', '');
- };
- const shortenRelTag = function(fullTag){
- 'use strict';
- const gen = '&';
- const rom = '/';
- let names = fullTag.includes(rom) ? fullTag.split(rom) : fullTag.split(gen);
- names = names.map(n => {
- return n.includes('|') ? shortenCharTag(n) : n;
- });
- let newTag;
- return fullTag.includes(rom) === true ? names.join(rom) : names.join(` ${gen} `);
- };
- const shortenPipes = function(){
- 'use strict';
- //work blurbs when browsing tag pages
- let chars = Array.from(document.getElementsByClassName('characters'));
- chars.forEach(char => {
- let charTag = char.childNodes[0].innerHTML;
- if (charTag.includes('|')) {
- charTag = shortenCharTag(charTag);
- char.childNodes[0].innerHTML = charTag;
- }
- });
- let rels = Array.from(document.getElementsByClassName('relationships'));
- rels.forEach(rel => {
- let relTag = rel.childNodes[0].innerHTML;
- if (relTag.includes('|')) {
- relTag = shortenRelTag(relTag);
- rel.childNodes[0].innerHTML = relTag;
- }
- });
- //on a single work page
- if (tagsOnFicPage === 1) {
- let charsFic = Array.from(document.querySelectorAll('dd.character a'));
- charsFic.forEach(cF => {
- let cFTag = cF.innerHTML;
- if (cFTag.includes('|')) {
- cFTag = shortenCharTag(cFTag);
- cF.innerHTML = cFTag;
- }
- });
- let relsFic = Array.from(document.querySelectorAll('dd.relationship a'));
- relsFic.forEach(rF => {
- let rFTag = rF.innerHTML;
- if (rFTag.includes('|')) {
- rFTag = shortenRelTag(rFTag);
- rF.innerHTML = rFTag;
- }
- });
- }
- };
- shortenPipes();