🏠 返回首頁 

Greasy Fork is available in English.

CircleCI Workflow Panner

Pan across large workflow charts using your mouse instead of relying on the scrollbars. Set naturalScroll to false to disable inverted panning.


安装此脚本?
  1. // ==UserScript==
  2. // @name CircleCI Workflow Panner
  3. // @namespace antontsvil
  4. // @match *://app.circleci.com/*
  5. // @grant GM.getValue
  6. // @grant GM.setValue
  7. // @require https://unpkg.com/arrive@2.4.1/src/arrive.js
  8. // @version 1.1
  9. // @license MIT
  10. // @author antontsvil@gmail.com
  11. // @description Pan across large workflow charts using your mouse instead of relying on the scrollbars. Set naturalScroll to false to disable inverted panning.
  12. // ==/UserScript==
  13. /*jshint esversion: 8 */
  14. const graphSelector = "[data-cy='workflow-graph']";
  15. const graph = () => document.querySelector(graphSelector);
  16. const html = () => document.querySelector('html');
  17. let isDragging = false;
  18. const dragStart = () => {
  19. isDragging = true;
  20. const gel = graph();
  21. gel.style.cursor = 'move';
  22. gel.style.userSelect = 'none';
  23. };
  24. const dragStop = () => {
  25. isDragging = false;
  26. const gel = graph();
  27. gel.style.cursor = 'default';
  28. gel.style.userSelect = 'initial';
  29. };
  30. const b = document.querySelector('body');
  31. b.arrive(graphSelector, async () => {
  32. let naturalScroll = await GM.getValue('naturalScroll');
  33. if (naturalScroll!== false && naturalScroll !== true) {
  34. await GM.setValue('naturalScroll', true);
  35. naturalScroll = true;
  36. }
  37. const gel = graph();
  38. gel.addEventListener('mousedown', ({ target, button }) => {
  39. if (target.tagName === 'svg' && button === 0) {
  40. dragStart();
  41. }
  42. });
  43. gel.addEventListener('mouseup', (event) => {
  44. dragStop();
  45. });
  46. gel.addEventListener('mouseout', (event) => {
  47. if (event.relatedTarget === gel) {
  48. dragStop();
  49. }
  50. });
  51. gel.addEventListener('mousemove', (event) => {
  52. const el = graph();
  53. const rightSide = el.scrollWidth - el.clientWidth;
  54. const horizontalScroll = {
  55. left: naturalScroll
  56. ? el.scrollLeft - event.movementX
  57. : el.scrollLeft + event.movementX,
  58. };
  59. const verticalScroll = {
  60. top: naturalScroll
  61. ? html().scrollTop - event.movementY
  62. : html().scrollTop + event.movementY,
  63. };
  64. if (isDragging) {
  65. el.scrollTo(horizontalScroll);
  66. html().scrollTo(verticalScroll);
  67. }
  68. });
  69. });