OSM iD saving indicator

Change tab's title when iD is saving (based on saving modal visibility)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         OSM iD saving indicator
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Change tab's title when iD is saving (based on saving modal visibility)
// @author       JackNUMBER
// @match        https://www.openstreetmap.org/edit*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  let state = "idle";
  const originalTitle = document.title;

  // Function to check for the loader image in the iframe
  function checkLoaderVisibility() {
    const iframe = document.querySelector('iframe'); // Select the iframe


    if (iframe) {
      const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
      const loaderImage = iframeDocument.querySelector('.modal-section.fillL .loader'); // Target loader image in the saving modal

      if (loaderImage) { // Loader is visible
        state = "saving"
        document.title = "Saving...";
      } else { // Loader is hidden
        if (state === "saving") {
          state = "saved"
          document.title = `✔ Saved`; // Tell the saving is done

          setTimeout(() => {
            document.title = originalTitle; // Revert back to the original title
          }, 1500);
          state = "saved"
        }
      }
    }
  }

  // Set an interval to check for the loader's visibility
  setInterval(checkLoaderVisibility, 500); // Check every 500 milliseconds
})();