Skip to content

Instantly share code, notes, and snippets.

@hinaloe
Last active April 13, 2019 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hinaloe/372a842f4dc82e539ebb5edf34efc45d to your computer and use it in GitHub Desktop.
Save hinaloe/372a842f4dc82e539ebb5edf34efc45d to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Tissue more gravatar
// @namespace http://tampermonkey.net/
// @version 0.1
// @description GravatarからTissueのプロフィールを補完
// @author hinaloe
// @match https://shikorism.net/user/*
// @match https://shikorism.net/checkin/*
// @grant GM_xmlhttpRequest
// @connect gravatar.com
// ==/UserScript==
const createLink = (text, href) => {
const p = document.createElement('p')
const el = document.createElement('a')
el.href = href
el.textContent = text
p.appendChild(el)
return p
}
(function() {
'use strict';
const url = document.querySelector('.rounded.mb-1').src.replace('/avatar','').replace(/\?.*$/,'')+'.json'
const profileBox = document.querySelector('body > div.container > div > div.col-lg-4 > div:nth-child(1) > div')
console.log(new GM_xmlhttpRequest({
//fetch: true,
method:'GET',
responseType: 'json',
headers : {
},
url,
onload(res) {
if(res.status !== 200) {
throw new Error(`Gravatar API Returns ${res.status}!`)
}
console.log(res)
const {response} = res
if(!response.entry[0]) return
if(Array.isArray(response.entry[0].accounts)) {
for(const account of response.entry[0].accounts) {
console.log(`${account.shortname}: ${account.display} (${account.url})`)
profileBox.appendChild(createLink(`${account.shortname}: ${account.display}`, account.url))
}
}
if(Array.isArray(response.entry[0].emails)) {
for(const email of response.entry[0].emails) {
console.log(`email: ${email.value}`)
profileBox.appendChild(createLink(`email: ${email.value}`, `mailto:${email.value}`))
}
}
},
}))
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment