Skip to content

Instantly share code, notes, and snippets.

@mandel59
Created December 2, 2020 01:38
Show Gist options
  • Save mandel59/333f382668c914ae9bdc2869845be8a0 to your computer and use it in GitHub Desktop.
Save mandel59/333f382668c914ae9bdc2869845be8a0 to your computer and use it in GitHub Desktop.
star-first.user.js
// ==UserScript==
// @name star-first
// @namespace https://ryusei.dev/
// @version 0.1
// @description Star before you submit an issue
// @author Ryusei Yamaguchi
// @match https://github.com/*/*/issues/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const formset = new Set();
const xpathResult = document.evaluate("//button[contains(text(), 'Submit new issue')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i = 0; i < xpathResult.snapshotLength; i++) {
const button = xpathResult.snapshotItem(i);
const form = button.form;
button.type = 'button';
const hook = function (e) {
const unstarredButton = document.querySelector("form.unstarred button")
if (unstarredButton) {
unstarredButton.click();
setTimeout(function() { form.submit(); }, 100);
} else {
form.submit();
}
};
button.addEventListener('click', hook);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment