Last active
November 17, 2017 09:25
-
-
Save oieioi/076600530e256f92dbc75572c9f00a4d to your computer and use it in GitHub Desktop.
issuesかプルリクかわかりやすくする
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 issuesかプルリクかわかりやすくする | |
// @namespace https://gist.github.com/oieioi/ | |
// @version 0.9 | |
// @description try to take over the world! | |
// @author You | |
// @match https://github.com/*/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const body = document.querySelector('body'); | |
const label = document.createElement('div'); | |
const titleElement = document.querySelector('title'); | |
const prettyTitle = (titleElement, newTitle) => { | |
const regNotification = /^\(\d+\)/; | |
const notificationCount = titleElement.innerText.match(regNotification) ? titleElement.innerText.match(regNotification)[0] : "" ; | |
titleElement.innerText = titleElement.innerText.replace(regNotification, ""); | |
const regAdded = /^\[.+?\]/; | |
if (! titleElement.innerText.match(regAdded)) { | |
titleElement.innerText = "[dummy]" + titleElement.innerText; | |
} | |
const prefix = newTitle ? `[${newTitle}]${notificationCount}` : ''; | |
titleElement.innerText = titleElement.innerText.replace(regAdded, prefix); | |
}; | |
label.style.fontSize = '3em'; | |
label.style.margin = '10px'; | |
label.style.position = 'fixed'; | |
label.style.bottom = '10px'; | |
body.append(label); | |
setInterval(()=>{ | |
const categoryName = location.pathname.match(/\/.+?\/.+?\/(.+?)(\/|$)/) || []; | |
const id = location.pathname.match(/\/.+?\/.+?\/.+?\/(\d+)/) || []; | |
const newTitle = categoryName ? [categoryName[1], id[1]].filter((e)=>e).join(' #') : null; | |
label.innerText = newTitle; | |
prettyTitle(titleElement, newTitle); | |
}, 500); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment