Last active
September 30, 2017 16:24
-
-
Save koyumeishi/fe100716f1b3a59492acc01ed74416f6 to your computer and use it in GitHub Desktop.
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 tweet atcoder rating (simple) | |
// @namespace tweet atcoder rating (simple) | |
// @version 0.2 | |
// @author koyumeishi | |
// @match https://atcoder.jp/user/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let prevRating = rating_history.length >= 2 ? rating_history[1][1] : "unrated"; | |
let currentRating = rating_history[0][1]; | |
let ratingDelta = currentRating - (prevRating !== "unrated" ? prevRating : 0); | |
let contestName = rating_history[0][3]; | |
let contestRank = rating_history[0][2]; | |
let rankSuffix = 11 <= contestRank && contestRank <= 19 ? "th" : ["th", "st", "nd", "rd","th","th","th","th","th","th","th"][contestRank%10]; | |
let text = | |
`${contestName} : Rank ${contestRank}${rankSuffix}, Rating ${prevRating} -> ${currentRating} (${ | |
ratingDelta >= 0 ? "+" : "" | |
}${ratingDelta})`; | |
console.log(text); | |
$('div.col-sm-8 > dl.dl-horizontal').append(`<dd><a href="https://twitter.com/share" class="twitter-share-button" data-hashtags="AtCoder">Tweet</a> | |
<script> | |
!function(d,s,id){ | |
let tweet_text = \`${text}\`; | |
document.getElementsByClassName("twitter-share-button")[0].setAttribute("data-text", tweet_text); | |
var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https'; | |
if(!d.getElementById(id)){ | |
js=d.createElement(s); | |
js.id=id; | |
js.src=p+'://platform.twitter.com/widgets.js'; | |
fjs.parentNode.insertBefore(js,fjs); | |
} | |
}(document, 'script', 'twitter-wjs'); | |
</script> | |
</dd>`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment