AO3: [Wrangling] Quick Tag Comment Button + Iconfiy

Adds a comment button + iconfies them to make it more compact

目前為 2017-06-13 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        AO3: [Wrangling] Quick Tag Comment Button + Iconfiy
// @namespace   adustyspectacle
// @description Adds a comment button + iconfies them to make it more compact
// @include     http://archiveofourown.org/tags/*/wrangle*
// @include     https://archiveofourown.org/tags/*/wrangle*
// @include     http://archiveofourown.org/tag_wranglings*
// @include     https://archiveofourown.org/tag_wranglings*
// @version     1
// @grant       none
// ==/UserScript==

var font_awesome_icons = document.createElement('script');
font_awesome_icons.setAttribute('src', 'https://use.fontawesome.com/ed555db3cc.js');
document.getElementsByTagName('head')[0].appendChild(font_awesome_icons);

var fa_icons_css = document.createElement('style');
fa_icons_css.setAttribute('type', 'text/css');
fa_icons_css.innerHTML = "tbody td ul.actions { font-family: FontAwesome, sans-serif; } tbody td .actions input[type='checkbox'] { margin: auto auto auto 0.5em; vertical-align: -0.35em; }";
document.getElementsByTagName('head')[0].appendChild(fa_icons_css);

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

var btn_count = document.querySelector('table tbody ul.actions').children.length;

if (btn_count == 3) {
  var tag_edit_btns = document.querySelectorAll('table tbody ul.actions li:nth-child(1)');
  var tag_wrangle_btns = document.querySelectorAll('table tbody ul.actions li:nth-child(2)');
  var tag_works_btns = document.querySelectorAll('table tbody ul.actions li:nth-child(3)');
} else if (btn_count == 4 ) {
  var tag_remove_btns = document.querySelectorAll('table tbody ul.actions li:nth-child(1)');
  var tag_edit_btns = document.querySelectorAll('table tbody ul.actions li:nth-child(2)');
  var tag_wrangle_btns = document.querySelectorAll('table tbody ul.actions li:nth-child(3)');
  var tag_works_btns = document.querySelectorAll('table tbody ul.actions li:nth-child(4)');
}

for (i = 0; i < tag_edit_btns.length; i++) {
  if (btn_count == 4) {
    var tag_remove_checkbox = tag_remove_btns[i].querySelector('input');
    tag_remove_btns[i].querySelector('label').innerHTML = '&#xf00d;';
    tag_remove_btns[i].querySelector('label').appendChild(tag_remove_checkbox);
  }
  var comment_btn = tag_edit_btns[i].cloneNode(true);
  var comment_link = comment_btn.querySelector('a');
  var comment_link_href = comment_link.getAttribute('href').slice(0,-4) +'comments';

  comment_link.innerHTML = '&#xf086;';
  tag_edit_btns[i].querySelector('a').innerHTML = '&#xf044;';
  tag_wrangle_btns[i].querySelector('a').innerHTML = '&#xf00b;';
  tag_works_btns[i].querySelector('a').innerHTML = '&#xf02d;';
  
  comment_link.setAttribute('href', comment_link_href);
  
  insertAfter(comment_btn, tag_edit_btns[i]);
}