Upwork external links

Skip "You are now leaving Upwork" page with external links

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Upwork external links
// @description  Skip "You are now leaving Upwork" page with external links
// @namespace    vokracko
// @author       Lukáš Vokráčko
// @include      https://www.upwork.com/*
// @version      1.0
// @grant        none
// @encoding     utf-8
// ==/UserScript==

var target = document.querySelector('body');
var config = { attributes: false, childList: true, characterData: false, subtree: true };

function replace() {
    // replace links
    var links = document.links;

    for (var i in links) {
        if (links[i].href && links[i].href.startsWith("https://www.upwork.com/leaving")) {
            if (links[i].classList.contains("url-preview-title")) {
                links[i].href = decodeURIComponent(links[i].href.substr(35));
            } else {
                links[i].href = links[i].text;
            }
        }
    }
}

var observer = new MutationObserver(function (mutations) {
    mutations.forEach(function (mutation) {
        if (mutation.addedNodes) {
            replace();
        }
    });
});

observer.observe(target, config);