Upwork external links

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

  1. // ==UserScript==
  2. // @name Upwork external links
  3. // @description Skip "You are now leaving Upwork" page with external links
  4. // @namespace vokracko
  5. // @author Lukáš Vokráčko
  6. // @include https://www.upwork.com/*
  7. // @version 1.0
  8. // @grant none
  9. // @encoding utf-8
  10. // ==/UserScript==
  11.  
  12. var target = document.querySelector('body');
  13. var config = { attributes: false, childList: true, characterData: false, subtree: true };
  14.  
  15. function replace() {
  16. // replace links
  17. var links = document.links;
  18.  
  19. for (var i in links) {
  20. if (links[i].href && links[i].href.startsWith("https://www.upwork.com/leaving")) {
  21. if (links[i].classList.contains("url-preview-title")) {
  22. links[i].href = decodeURIComponent(links[i].href.substr(35));
  23. } else {
  24. links[i].href = links[i].text;
  25. }
  26. }
  27. }
  28. }
  29.  
  30. var observer = new MutationObserver(function (mutations) {
  31. mutations.forEach(function (mutation) {
  32. if (mutation.addedNodes) {
  33. replace();
  34. }
  35. });
  36. });
  37.  
  38. observer.observe(target, config);