Created
November 6, 2017 01:37
-
-
Save khsk/d68ef861fa4ef7af0ed0e7f8d60c8cca to your computer and use it in GitHub Desktop.
Qiitaの通知の分類をした…かったユーザースクリプト ref: http://qiita.com/khsk/items/5756c477df3dc011d01a
This file contains 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 Qiita Notification classification | |
// @namespace khsk | |
// @description 新規通知を分類分けして表示する | |
// @include http://qiita.com/* | |
// @include https://qiita.com/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
console.time('Qiita Notification classification'); | |
// 初期色相 | |
const INIT_HUE = 180; | |
// 色相増分 | |
const INCREMENTAL_HUE = 30; | |
var deferred = $.ajax({ | |
url:'https://qiita.com/api/notifications?locale=ja' | |
}) | |
deferred.done(function(data) { | |
var nocheckNotices = data.filter(function(notice) { | |
return !notice.seen | |
}); | |
// 分類 | |
var classifications = {}; | |
nocheckNotices.forEach(function(notice) { | |
classifications[notice.action] = classifications[notice.action] || 0; | |
classifications[notice.action] = ++(classifications[notice.action]); | |
}); | |
var originalNotifications = document.getElementsByClassName('sharedHeader_notifications')[0]; | |
var parentNode = document.getElementsByClassName('sharedHeader_right')[0]; | |
var i = 0; | |
for(action in classifications) { | |
// 色は取得順で何の種類かはツールチップで。アクション種類一覧が特定できたら色と日本語訳を固定したい | |
var classification = originalNotifications.cloneNode(true); | |
classification.setAttribute('data-toggle','tooltip'); | |
classification.setAttribute('data-placement','bottom'); | |
classification.setAttribute('title',action); | |
// デフォルトだと並べてすかすかなので | |
classification.style.paddingLeft = '1px'; | |
classification.style.paddingRight = '1px'; | |
classification.firstChild.firstChild.firstChild.innerHTML = classifications[action]; | |
classification.firstChild.firstChild.firstChild.style.backgroundColor = 'hsl(' + (INIT_HUE + (INCREMENTAL_HUE * i)) + ' , 100%, 50%)'; | |
parentNode.insertBefore(classification, originalNotifications); | |
++i; | |
} | |
$('[data-toggle="tooltip"]').tooltip(); | |
}) | |
deferred.fail(function(data) { | |
console.error(data) | |
}) | |
console.timeEnd('Qiita Notification classification'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment