Gitlab code review mouse shortcut

Add mouse shortcut to Gitlab code review (NOTE: only for settings: show one file at a time)

  1. // ==UserScript==
  2. // @name Gitlab code review mouse shortcut
  3. // @namespace http://kenngsimply.com/
  4. // @version 0.1
  5. // @description Add mouse shortcut to Gitlab code review (NOTE: only for settings: show one file at a time)
  6. // @author Ken Ng
  7. // @match https://gitlab.com/*/merge_requests*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. /* jshint esversion: 6 */
  13.  
  14. (function() {
  15. function eventFire(el, etype='click'){
  16. if (el.fireEvent) {
  17. el.fireEvent('on' + etype);
  18. } else {
  19. const evObj = document.createEvent('Events');
  20. evObj.initEvent(etype, true, false);
  21. el.dispatchEvent(evObj);
  22. }
  23. }
  24.  
  25. function debounced(func, timeout = 300){
  26. let timer;
  27. return (...args) => {
  28. if (!timer) {
  29. func.apply(this, args);
  30. }
  31. clearTimeout(timer);
  32. timer = setTimeout(() => {
  33. timer = undefined;
  34. }, timeout);
  35. };
  36. }
  37.  
  38. function showPrevOrNextFile(ev) {
  39. if(ev.altKey) {
  40. if(ev.wheelDelta < 0) {
  41. // mouse wheel rotate downwards
  42. const item = document.querySelector('.page-item .next-page-item')
  43. eventFire(item)
  44. return
  45. }
  46.  
  47. // mouse wheel rotate upwards
  48. const item = document.querySelector('.page-item .prev-page-item')
  49. eventFire(item)
  50. }
  51. }
  52.  
  53. document.addEventListener("wheel", debounced(showPrevOrNextFile));
  54. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址