Admin URL Rewrite

Automatically updates admin links to point to the internal or external site depending on your settings.

目前为 2023-11-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Admin URL Rewrite
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Automatically updates admin links to point to the internal or external site depending on your settings.
  6. // @author You
  7. // @match https://roger-team.atlassian.net/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=atlassian.net
  9. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM.getValue
  13. // @grant GM.setValue
  14. // ==/UserScript==
  15. /* global $ GM_config */
  16.  
  17. (function () {
  18. 'use strict';
  19.  
  20. let initialized = false;
  21. const internal = "admin.i.corpayone.com"
  22. const external = "admin.corpayone.com"
  23.  
  24. let gmc = new GM_config(
  25. {
  26. 'id': 'Admin_URL_Rewrite',
  27. 'title': 'Admin URL Rewrite',
  28. 'fields':
  29. {
  30. 'fleetcor':
  31. {
  32. 'label': 'Are you on the Fleetcor VPN?',
  33. 'type': 'checkbox',
  34. 'default': false,
  35. },
  36. 'initialized': {
  37. type: 'hidden',
  38. default: false,
  39. },
  40. },
  41. 'events':
  42. {
  43. 'init': function () {
  44. if (!this.get('initialized')) {
  45. this.open();
  46. const style = this.frame.style
  47. style.width = '280px';
  48. style.height = '145px';
  49. style.inset = undefined;
  50. style.top = '50%';
  51. }
  52. else {
  53. initialized = true;
  54. }
  55. },
  56. 'save': function () {
  57. this.set('initialized', true);
  58. initialized = true;
  59. this.frame.style.display = 'none';
  60. }
  61. },
  62. });
  63.  
  64.  
  65. const interval = setInterval(() => {
  66. console.log(initialized)
  67. if (initialized) replaceLinks();
  68. }, 250)
  69.  
  70. function replaceLinks() {
  71. const source = gmc.get('fleetcor') ? internal : external
  72. const target = gmc.get('fleetcor') ? external : internal
  73. const externalLinks = [...document.querySelectorAll(`a[href*="${source}"]`)]
  74. externalLinks.forEach(node => {
  75. if (node.innerHTML) {
  76. node.innerHTML = node.innerHTML.replace(source, target);
  77. }
  78. if (node.title) {
  79. node.title = node.title.replace(source, target);
  80. }
  81. node.href = node.href.replace(source, target);
  82. })
  83. }
  84. })();