MMH and GHF Better Page Titles

On Morrowind Modding History and Great House Fliggerty, this adds the mod name or sub-category name to the page title for better bookmarking. Also, sometimes mod pages are blank except the header and footer and the mod isn't downloadable, this adds a download link to the page when that happens.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        MMH and GHF Better Page Titles
// @namespace   nerevar009
// @include     http://mw.modhistory.com/*
// @include     http://download.fliggerty.com/*
// @description On Morrowind Modding History and Great House Fliggerty, this adds the mod name or sub-category name to the page title for better bookmarking. Also, sometimes mod pages are blank except the header and footer and the mod isn't downloadable, this adds a download link to the page when that happens.
// @version     1
// @grant       none
// ==/UserScript==

var contents = document.getElementById("contents");

// page type; 1 = mod page, 2 = sub-category page, 0 = any other page
var pagetype = 0;
if(/^\/download-\d+-\d+$/.test(location.pathname))
  pagetype = 1;
else if(/^\/download-\d+$|^\/download-p\d+-i.*-\d+$/.test(location.pathname))
  pagetype = 2;


// check if page content have loaded, if not, add download link in contents div in case it never loads
// and create a mutation observer to watch for it being loaded and run the addInfoToPageTitle function.
// if page content has loaded, just run the addInfoToPageTitle function
if(contents.childNodes.length == 1) {
  if(pagetype == 1) {
    var download = document.createElement("img");
    download.setAttribute("src", "images/download_button.png");
    download.setAttribute("alt", "Download");
    download.setAttribute("style", "float: right;");
    download.addEventListener("click", function(e) {
      e.preventDefault();
      location.href = "file.php?id=" + location.pathname.match(/^\/download-\d+-(\d+)$/)[1];
    })
    contents.appendChild(download);
  }

  var observer = new MutationObserver(function() {
    observer.disconnect();
    addInfoToPageTitle();
  });
  observer.observe(contents, {childList: true});

}
else addInfoToPageTitle();


// add mod name or sub-category name to page title
function addInfoToPageTitle() {
  var title = document.getElementsByClassName("cattitle");

  if(pagetype == 1)
    document.title = title[0].childNodes[0].nodeValue + " - " + document.title;
  else if(pagetype == 2)
    document.title = "Sub-Category: " + title[0].childNodes[1].nodeValue.trim() + " - " + document.title;
}