Spark Standalone Master App Proxy Fix

Fix links to Spark jobs descriptions and nav bar in Spark Standalone Master when spark.ui.reverseProxy=true.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Spark Standalone Master App Proxy Fix
// @name:zh-CN   Spark Standalone Master 反向代理链接修复
// @namespace    https://rabit.pw/
// @version      0.2
// @description  Fix links to Spark jobs descriptions and nav bar in Spark Standalone Master when spark.ui.reverseProxy=true.
// @description:zh-CN 修复Spark Standalone模式中,启用了`spark.ui.reverseProxy=true`之后,在任务详情页面,任意链接点击后跳转回首页的问题。
// @author       ttimasdf
// @match        http://*/proxy/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

// ref: https://stackoverflow.com/a/17599814/1043209
(function() {
    'use strict';

    var imgs = document.getElementsByTagName("img");//"/static/spark-logo-77x50px-hd.png"

    // Check whether this is Spark Master page
    for (var i = 0, found = false; i < imgs.length && i < 3; i++) {
        if (imgs[i].getAttribute("src") == "/static/spark-logo-77x50px-hd.png") {
            found = true;
        }
    }
    if (!found) return;

    // Extract links
    var links = Array.from(document.links);
    links.push.apply(links, document.getElementsByTagName("a"));
    // get link to current page and extract http://xxxx/proxy/app-xxxx part
    var root = /^.*proxy\/[^\/]*/.exec(window.location.href)[0];
    // console.log(links);

    var i;
    for (i = 0; i < links.length; i++ ) {
        var link = links[i].getAttribute('href');
        if (/^\/(?!proxy).+/.test(link)) {
            console.log(link, "=>", root + link);
            links[i].setAttribute("href", root + link);
        }
    }
})();