Last active
November 29, 2019 10:53
-
-
Save YoshiTheChinchilla/dd56b66c8d656c08818a54856887f9e0 to your computer and use it in GitHub Desktop.
GitHub Gist userscripts for Tampermonkey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name GitHub Topic Copier | |
// @namespace https://gist.github.com/YoshiTheChinchilla/ | |
// @version 1.0.0 | |
// @description Creating "Copy topics" button to copy topics of GitHub repository | |
// @author Takashi Yoshimura | |
// @encoding utf-8 | |
// @homepage https://gist.github.com/YoshiTheChinchilla/ | |
// @match https://github.com/*/* | |
// @exclude https://github.com/pulls/* | |
// @exclude https://github.com/issues/* | |
// @exclude https://github.com/marketplace/* | |
// @exclude https://github.com/features/* | |
// @exclude https://github.com/topics/* | |
// @exclude https://github.com/trending/* | |
// @exclude https://github.com/collections/* | |
// @exclude https://github.com/security/* | |
// @exclude https://github.com/contact/* | |
// @exclude https://github.com/about/* | |
// @exclude https://github.com/customer-stories/* | |
// @exclude https://github.com/users/* | |
// @exclude https://github.com/notifications/* | |
// @exclude https://github.com/settings/* | |
// @exclude https://github.com/account/* | |
// @exclude https://github.com/organizations/* | |
// @exclude https://github.com/new/* | |
// @exclude https://github.com/stars/* | |
// @license MIT | |
// @run-at document-end | |
// @grant none | |
// @iconURL https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png | |
// @icon64URL https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png | |
// @updateURL https://gist.github.com/YoshiTheChinchilla/dd56b66c8d656c08818a54856887f9e0/raw/github-topic-copier.user.js | |
// @downloadURL https://gist.github.com/YoshiTheChinchilla/dd56b66c8d656c08818a54856887f9e0/raw/github-topic-copier.user.js | |
// @supportURL https://gist.github.com/YoshiTheChinchilla/dd56b66c8d656c08818a54856887f9e0#new_comment_field | |
// ==/UserScript== | |
// Version History: | |
// | |
// 1.0.0 (2019-08-07): Publish this script on https://gist.github.com/YoshiTheChinchilla/dd56b66c8d656c08818a54856887f9e0 | |
// 0.2.0 (2015-10-22): Update to ES6 | |
// 0.1.0 (2012-03-02): Create this script | |
// | |
const copyToClipboard = (text) => { | |
const textarea = document.createElement('textarea') | |
textarea.textContent = text | |
const body = document.getElementsByTagName('body')[0] | |
body.appendChild(textarea) | |
textarea.select() | |
document.execCommand('copy') | |
body.removeChild(textarea) | |
} | |
const createElementFromText = (text) => { | |
const parentNode = document.createElement('div') | |
parentNode.innerHTML = text | |
return parentNode.children | |
} | |
const genCopyButtonElement = (separator=' ') => { | |
// const copyButton = document.createElement('span') | |
// copyButton.className = 'btn-link f6 mb-2 ml-2' | |
// copyButton.textContent = 'Copy topics' | |
const copyButton = createElementFromText('<span class="btn-link f6 mb-2 ml-2">Copy topics</span>')[0] | |
copyButton.addEventListener('click', (e) => { | |
e.preventDefault() | |
alert('Copied topics to your clipboard!') | |
const topicsText = [...document.querySelectorAll('.list-topics-container a')].map(node => node.innerText).join(separator) | |
copyToClipboard(topicsText) | |
}) | |
return copyButton | |
} | |
;(() => { | |
'use strict' | |
const copyButton = genCopyButtonElement() | |
// Append copy button to the topic box | |
document.querySelectorAll('.Details-content--closed')[1].appendChild(copyButton) | |
})() | |
/** | |
The MIT License (MIT) | |
Copyright (c) 2012 Takashi Yoshimura | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the "Software"), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
the Software, and to permit persons to whom the Software is furnished to do so, | |
subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
**/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name GitHub Topic Paster | |
// @namespace https://gist.github.com/YoshiTheChinchilla/ | |
// @version 1.0.0 | |
// @description Creating topics of GitHub repository with pasting a text | |
// @author Takashi Yoshimura | |
// @encoding utf-8 | |
// @homepage https://gist.github.com/YoshiTheChinchilla/ | |
// @match https://github.com/*/* | |
// @exclude https://github.com/pulls/* | |
// @exclude https://github.com/issues/* | |
// @exclude https://github.com/marketplace/* | |
// @exclude https://github.com/features/* | |
// @exclude https://github.com/topics/* | |
// @exclude https://github.com/trending/* | |
// @exclude https://github.com/collections/* | |
// @exclude https://github.com/security/* | |
// @exclude https://github.com/contact/* | |
// @exclude https://github.com/about/* | |
// @exclude https://github.com/customer-stories/* | |
// @exclude https://github.com/users/* | |
// @exclude https://github.com/notifications/* | |
// @exclude https://github.com/settings/* | |
// @exclude https://github.com/account/* | |
// @exclude https://github.com/organizations/* | |
// @exclude https://github.com/new/* | |
// @exclude https://github.com/stars/* | |
// @license MIT | |
// @run-at document-end | |
// @grant none | |
// @iconURL https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png | |
// @icon64URL https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png | |
// @updateURL https://gist.github.com/YoshiTheChinchilla/dd56b66c8d656c08818a54856887f9e0/raw/github-topic-paster.user.js | |
// @downloadURL https://gist.github.com/YoshiTheChinchilla/dd56b66c8d656c08818a54856887f9e0/raw/github-topic-paster.user.js | |
// @supportURL https://gist.github.com/YoshiTheChinchilla/dd56b66c8d656c08818a54856887f9e0#new_comment_field | |
// ==/UserScript== | |
// Version History: | |
// | |
// 1.0.0 (2019-08-07): Publish this script on https://gist.github.com/YoshiTheChinchilla/dd56b66c8d656c08818a54856887f9e0 | |
// 0.2.0 (2015-10-20): Update to ES6 | |
// 0.1.0 (2012-03-01): Create this script | |
// | |
// Official GitHub topic naming rules: | |
// "Topics must start with a lowercase letter or number, consist of 35 characters or less, and can include hyphens." | |
const pasteEventHandler = (e) => { | |
// Start console group and console time | |
console.group('github-topic-paster logs') | |
console.time('Time') | |
e.preventDefault() | |
// Get text from clipboard | |
const pastedText = (e.clipboardData || window.clipboardData).getData('text') | |
if( !pastedText ) return false | |
// Regular Expression | |
// See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-white-space | |
const regexSeparator = /(\s|,)/ | |
// Replace '.' with '' | |
const trimmedPastedText = pastedText.replace(/(\.|\(|\))/g, '') | |
// Convert clipboard text into an array and filter /(\s|,)/ | |
const topics = trimmedPastedText.split(regexSeparator).filter(s => !regexSeparator.test(s)) | |
// Get the topic box | |
const topicBox = document.querySelector('.js-tag-input-selected-tags') | |
// Focus and unfocus the input for creating topics | |
const registeredTopics = topics.filter(s => { | |
e.target.focus() | |
e.target.value = s | |
e.target.blur() | |
// Check if a topic added | |
return s === topicBox.querySelector('li:last-child').innerText.split('\n')[0] | |
}) | |
// Logs | |
console.info(`Parsed these topics:\n${topics.join(' ')}`) | |
console.info(`Registered these topics:\n${registeredTopics.join(' ')}`) | |
// End console group and console time | |
console.timeEnd('Time') | |
console.groupEnd() | |
} | |
const clickEventHandler = () => { | |
// Get Topic input and it binds to paste event | |
document.querySelector('#repo_topics').addEventListener('paste', pasteEventHandler) | |
} | |
;(() => { | |
'use strict' | |
// Get the "Manage topics" button | |
const manageButton = document.querySelector('#topics-list-container .btn-link') | |
if( !manageButton ) return false | |
manageButton.addEventListener('click', clickEventHandler) | |
})() | |
/** | |
The MIT License (MIT) | |
Copyright (c) 2012 Takashi Yoshimura | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the "Software"), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
the Software, and to permit persons to whom the Software is furnished to do so, | |
subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | |
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | |
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment