SoundCloud Auto-reload on Connection

Automatically reloads the SoundCloud page when online or when the internet connection is re-established.

当前为 2024-05-09 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SoundCloud Auto-reload on Connection
// @name:ru      SoundCloud Автоматическая перезагрузка при подключении
// @name:de      SoundCloud Automatisches Neuladen bei Verbindung
// @name:fr      SoundCloud Rechargement automatique lors de la connexion
// @name:es      SoundCloud Recarga automática al conectarse
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Automatically reloads the SoundCloud page when online or when the internet connection is re-established.
// @description:ru Автоматически перезагружает страницу SoundCloud при наличии подключения к интернету или при восстановлении интернет-соединения.
// @description:de Lädt die SoundCloud-Seite automatisch neu, wenn eine Verbindung zum Internet besteht oder die Internetverbindung wiederhergestellt wurde.
// @description:fr Recharge automatiquement la page SoundCloud lorsque vous êtes en ligne ou lorsque la connexion Internet est rétablie.
// @description:es Recarga automáticamente la página de SoundCloud cuando estás en línea o cuando se restablece la conexión a Internet.
// @author       Levi Somerset
// @match        https://soundcloud.com/*
// @license      MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=soundcloud.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to reload if online
    function reloadIfOnline() {
        if (navigator.onLine) {
            const offlineMessage = document.querySelector('h1');
            if (offlineMessage && /Not available while you’re offline|Seite nicht verfügbar offline|No disponible sin conexión/i.test(offlineMessage.textContent)) {
                window.location.reload();
            }
        }
    }

    // Listen for the browser regaining connection
    window.addEventListener('online', reloadIfOnline);

    // Initial check in case the page loads while offline
    reloadIfOnline();

    // Regularly check in case the online event is missed
    setInterval(reloadIfOnline, 5000); // Check every 5 seconds
})();