Spark Standalone Master App Proxy Fix

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

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

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==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);
        }
    }
})();