Created
June 4, 2018 16:52
-
-
Save karubabu/f908b357922c056329aa853ab80fb8a8 to your computer and use it in GitHub Desktop.
crypkoカードの祖先一覧を表示するやつをGM_registerMenuCommandに対応させたもの fork元:http://let.hatelabo.jp/pacochi/let/hJmc-bbGmZpw
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 [Crypko]祖先辿り | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description カードの祖先一覧を表示します。 | |
// @author You | |
// @match https://crypko.ai/* | |
// match文に#があるの上手くマッチングしてくれないのどうすればいいのかしら | |
// @license MIT | |
// @grant GM_registerMenuCommand | |
// @fork http://let.hatelabo.jp/pacochi/let/hJmc-bbGmZpw | |
// ==/UserScript== | |
function aoeu() { | |
void (async ( | |
w = 512, | |
m = w >> 3, // w だけにするとめいっぱい(9世代前まで)読み込む | |
D = document, | |
E = (n, a = {}, c = []) => ((n = Object.assign(D.createElement(n), a)), c.forEach(e => n.appendChild(e)), n), | |
q = {}, | |
t = [[(location.href.match(/\d+$/) || [0])[0]]], | |
g, i, l, d, p | |
) => { | |
for (i = 1; i < m ; i++) { | |
g = i.toString(2).length; | |
l = i - (1 << g - 1); | |
d = t[g - 1][l]; | |
p = [0, 0]; | |
if (d && !q[d]) await fetch(`https:\u002F\u002Fapi.crypko.ai/crypkos/${d}/detail`) | |
.then(r => r.json()).catch(e => console.error(e)).then(j => console.log(q[d] = j)); | |
if (q[d]) { | |
p = [q[d].matronId, q[d].sireId]; | |
// 参考: https://github.com/yuntan/crypkograph/blob/514e71daa5839a4a8f7e2f0c53750843c5d9225a/crypkograph.py#L70 | |
await crypto.subtle.digest({ name: 'SHA-1' }, | |
Uint8Array.from([...`${q[d].noise}asdasd3edwasd${q[d].attrs}`] | |
.map(c => c.charCodeAt())) | |
).then(h => | |
(q[d].img = Array.from(new Uint8Array(h)) | |
.map(c => c.toString(16).padStart(2, '0')).join('')) | |
); | |
} | |
if (!t[g]) t[g] = []; | |
[t[g][l * 2], t[g][l * 2 + 1]] = p; | |
} | |
console.log(t,q); | |
D.head.appendChild(E('style', { textContent: ` | |
#ancestors { width: ${w}px; margin: 0 auto; } | |
#ancestors>div { width: 100% } | |
#ancestors>div>div { position: relative; display: inline-block; } | |
#ancestors>div>div>img { position: absolute; transition-duration: 0.5s; } | |
#ancestors>div>div>img:hover { z-index: 99; width: 256px; } | |
` })); | |
D.querySelector('#header-template').after(E('div', { id: 'ancestors' }, [p = E('div', {})])); | |
t.filter(b => b.some(d => d)).forEach(b => p.before(p = | |
E('div', {}, | |
b.map((d, i, a) => E('div', { style: `width: ${w / a.length}px; height: ${w / a.length}px;` }, | |
(q[d] ? [E('img', { | |
src: `https:\u002F\u002Fimg.crypko.ai/daisy/${q[d].img}_lg.jpg`, | |
width: w / a.length, title: `${q[d].name ? q[d].name : ''}#${q[d].id}`, | |
onclick: e => window.open('https://crypko.ai/#/card/' + e.target.title.split('#').pop(), '_blank') | |
})] : []) | |
)) | |
) | |
)); | |
})(); | |
} | |
GM_registerMenuCommand("祖先辿り", aoeu); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment