Better GitHub

去除“更新付款方式”错误;在 PR 界面添加快进式合并按钮。

  1. // ==UserScript==
  2. // @name Better GitHub
  3. // @namespace https://greasyfork.org/zh-CN/scripts/515684
  4. // @version 0.2.1
  5. // @description 去除“更新付款方式”错误;在 PR 界面添加快进式合并按钮。
  6. // @author ketikai
  7. // @license MIT
  8. // @match https://github.com/*
  9. // @icon https://github.com/fluidicon.png
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // <section aria-label="Error" class="flash flash-full js-notice flash-error">...</section>
  17. function RemoveUpdateYourPaymentMethodError() {
  18. let sections = document.getElementsByTagName('section');
  19. if (!sections) {
  20. return;
  21. }
  22. for (let i = 0; i < sections.length; i++) {
  23. let section = sections[i];
  24. if (!section) {
  25. continue;
  26. }
  27. if (section.ariaLabel != 'Error') {
  28. continue;
  29. }
  30. if (section.className != 'flash flash-full js-notice flash-error') {
  31. continue;
  32. }
  33. let text = section.innerText;
  34. if (!text || !text.startsWith("We are having a problem billing your account. Please update your payment method or call your payment provider for details on why the transaction failed.")) {
  35. continue;
  36. }
  37. section.remove();
  38. console.log('Removed Error: UpdateYourPaymentMethod.');
  39. break;
  40. }
  41. }
  42.  
  43. function insertFastForwardButton() {
  44. let state = document.getElementsByClassName('State State--open');
  45. if (state.length < 1) {
  46. return;
  47. }
  48. if (state[0].getAttribute('reviewable_state') !== 'ready') {
  49. return;
  50. }
  51. let commentDiv = document.getElementsByClassName('color-bg-subtle ml-1')[0];
  52. if (commentDiv.textContent.trim() === 'Comment') {
  53. let parent = commentDiv.parentElement;
  54. let fastForwardDiv = commentDiv.cloneNode(true);
  55. let fastForwardButton = fastForwardDiv.getElementsByTagName('button')[0];
  56. fastForwardButton.textContent = 'Fast forward';
  57. fastForwardButton.getAttributeNames().forEach(function(name) {
  58. if (name !== 'class') {
  59. fastForwardButton.removeAttribute(name);
  60. }
  61. });
  62. fastForwardButton.setAttribute('type', 'button');
  63. let textArea = document.getElementById('new_comment_field');
  64. let commentButton = commentDiv.getElementsByTagName('button')[0];
  65. fastForwardButton.onclick = function(event) {
  66. if (event.button == 0) {
  67. if (textArea.textContent === '/fast-forward') {
  68. commentButton.disabled = false;
  69. commentButton.click();
  70. commentButton.disabled = true;
  71. textArea.textContent = '';
  72. } else {
  73. textArea.textContent = '/fast-forward';
  74. commentButton.disabled = true;
  75. }
  76. }
  77. };
  78. parent.insertBefore(fastForwardDiv, commentDiv);
  79. }
  80. }
  81.  
  82. insertFastForwardButton();
  83. RemoveUpdateYourPaymentMethodError();
  84. document.addEventListener("DOMContentLoaded", function(event) {
  85. insertFastForwardButton();
  86. RemoveUpdateYourPaymentMethodError();
  87. });
  88. })();