My Merge Requests Gitlab

Show Link to opened Merge Requests, auto click swipe on MR with pics

当前为 2019-02-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // https://github.com/hannsen/userscripts
  3. // @name My Merge Requests Gitlab
  4. // @namespace http://tampermonkey.net/
  5. // @version 2.1
  6. // @description Show Link to opened Merge Requests, auto click swipe on MR with pics
  7. // @author hannsen
  8. // @match https://git04.quodata.de/*
  9. // @require https://code.jquery.com/jquery-3.1.1.min.js
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // ==/UserScript==
  13. (function() {
  14. 'use strict';
  15.  
  16. // var swipe = 0;
  17. // function scrollFunction() {
  18. // if(!swipe)
  19. // swipe = $('li.swipe');
  20. //
  21. // for(var i = 0; i < swipe.length; i++){
  22. // if(isScrolledIntoView(swipe[i])){
  23. // swipe[i].click();
  24. // return;
  25. // }
  26. // }
  27. // }
  28. //
  29. // function isScrolledIntoView(elem) {
  30. // var docViewTop = $(window).scrollTop();
  31. // var docViewBottom = docViewTop + $(window).height();
  32. // var elemTop = $(elem).offset().top;
  33. // var elemBottom = elemTop + $(elem).height();
  34. // return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
  35. // }
  36. //
  37. // if(window.location.href.indexOf("merge_requests") > 0)
  38. // window.onscroll = scrollFunction;
  39.  
  40. var last_mr_count = GM_getValue("open_mr_count") || 0;
  41.  
  42. var $merge_button = $($(".user-counter:eq( 1 )").prop('outerHTML'));
  43. var new_href = $merge_button.children().attr('href').replace('assignee_username', 'scope=all&state=opened&author_username');
  44. $merge_button.children().attr('href', new_href);
  45. $merge_button.find('span').toggleClass('gitlab-own-merge-requests merge-requests-count issues-count')
  46. .removeClass('hidden');
  47. $merge_button.find('span').html(last_mr_count);
  48. $($merge_button.prop('outerHTML')).insertBefore(".user-counter:eq( 2 )");
  49.  
  50. $.ajax({
  51. url: new_href,
  52. })
  53. .done(function(data) {
  54. var open_mr_count = $(data).find('a#state-opened > span.badge').html();
  55. $('.gitlab-own-merge-requests').html(open_mr_count);
  56. GM_setValue("open_mr_count", open_mr_count);
  57. });
  58.  
  59. // Grey out issues with pending Merge Request
  60. if(document.location.href.indexOf('dashboard/issues?assignee_username=') !== -1){
  61. $('li.issue:has(.issuable-mr)').css('opacity', 0.4);
  62. }
  63.  
  64. })();