AO3: Display Tag ID – Fixed

a quick and dirty script to display a canonical tag's tag id in its /works page – written by adustyspectacle (to 1.3), updated by WhyEssEff

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        AO3: Display Tag ID – Fixed
// @namespace   WhyEssEff
// @description a quick and dirty script to display a canonical tag's tag id in its /works page – written by adustyspectacle (to 1.3), updated by WhyEssEff
// @version     1.4
// @history     1.4 – WhyEssEff's quick fix
// @history     1.3 - changed how the tag id's displayed
// @history     1.2 - updated include urls to work with ao3's https switch
// @history     1.1 - changed the include to be more specific
// @grant       none
// @match     http://*archiveofourown.org/tags/*/works*
// @match     https://*archiveofourown.org/tags/*/works*
// @match     http://*archiveofourown.org/works?*
// @match     https://*archiveofourown.org/works?*
// ==/UserScript==

function insertAfter(el, referenceNode) {
  referenceNode.parentNode.insertBefore(el, referenceNode.nextSibling);
}

// this bit checks whether someone is logged in or not. Logged out users will only see tag ids
// for those with RSS feeds, i.e. fandoms, characters, and relationships. Logged in users will
// also see those, plus additional tags, ratings, categories, and warnings.
var log_status = document.getElementsByTagName('body')[0].getAttribute('class');
var tag_id;
if (log_status.startsWith('logged-out')) {
  tag_id = document.getElementsByClassName('rss')[0].getAttribute('href').slice(6,-10);
} else {
  tag_id = document.getElementById('favorite_tag_tag_id').getAttribute('value');
}

// this bit is where the creation of the tag id element happens.
var tag_id_container = document.createElement('span');
tag_id_container.setAttribute('id', 'tag_id');
tag_id_container.innerHTML = "Include: <strong>filter_ids:" + tag_id + "</strong><br/>Exclude: <strong>-filter_ids:" + tag_id + "</strong>";
tag_id_container.style['vertical-align'] = '-0.3em';
tag_id_container.style['display'] = 'inline-block';
tag_id_container.style['margin-left'] = '0.5em';

insertAfter(tag_id_container, document.querySelector('h2.heading'));