⛏️Ironwood Idle Indicators

Updates the tab title when an action stops.

As of 2023-09-22. See the latest version.

// ==UserScript==
// @name        ⛏️Ironwood Idle Indicators
// @description Updates the tab title when an action stops.
// @version     1.0.0
// @license     MIT
// @author      bradp
// @namespace   bradp
// @match       https://ironwoodrpg.com/*
// @run-at      document-end
// @grant       none
// ==/UserScript==

(() => {
  'use strict';

  const onRequest = (url, callback) => {
    const req = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function () {
      this.addEventListener('load', function () {
        if (this.responseText) {
          let response = {};
          try {
            response = JSON.parse(this.responseText);
          } catch (e) {
            return;
          }

          if (response && this.responseURL.indexOf(url) !== -1) {
            callback(response);
          }
        }
      });
      req.apply(this, arguments);
    };
  };

  onRequest('stopAction', (response) => {
    console.log('stopAction', response);
    // Update the tab title to show the action has stopped.
    setTimeout(() => {
	  document.title = `🟥️ ${document.title}`
	}, 250);
  });

  onRequest('startAction', (response) => {
    console.log('startAction', response);
    // Update the tab title to remove the action stopped indicator.
    document.title = document.title.replace('🟥️ ', '');
  });
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。