/*
* @title ハース翻訳
* @description ハースストーンのデッキを日本語に翻訳します。ポップアップを許可して使ってね
* @include http://www.hearthpwn.com/decks/*
* @include http://www.hearthhead.com/decks/*
* @include http://hearthstone.metabomb.net/deck-guides/*
* @include http://www.hearthstonetopdecks.com/decks/*
* @include https://tempostorm.com/hearthstone/decks/*
* @license MIT License
* @javascript_url
*/
var deck_name, author;
var cards = [];
var href = window.location.href;
if (href.startsWith('https://www.hearthpwn.com/decks/')) {
deck_name = encodeURIComponent(document.querySelector('h2.deck-title.tip').textContent);
author = document.querySelector('#content section.user-details ul.user li.name a.tip').textContent.trim();
var cc = document.querySelectorAll('table#cards tr td b a');
for (var i = 0; i < cc.length; i++) {
var card = cc[i];
var c = card.getAttribute('data-count');
var n = card.textContent.trim();
cards.push([n, c]);
}
} else if (href.startsWith('http://www.hearthhead.com/decks/')) {
deck_name = encodeURIComponent(window.HearthHeadData.deck.name);
author = encodeURIComponent(window.HearthHeadData.deck.username);
var cc = window.HearthHeadData.deck.cards;
var set = new Set();
for (var i = 0; i < cc.length; i++) {
var card = cc[i];
var n = card.name;
if (set.has(n)) {
cards.push([n, 2]);
set.delete(n);
} else {
set.add(n);
}
}
for (let name of set.values()) {
cards.push([name, 1]);
}
} else if (href.startsWith('http://www.hearthstonetopdecks.com/decks/')) {
deck_name = encodeURIComponent(document.title);
author = encodeURIComponent((document.querySelector('div.player-wrap h2 a') || '?').textContent);
var cc = document.querySelectorAll('ul.deck-class li');
for (var i = 0; i < cc.length; i++) {
var card = cc[i];
var n = card.querySelector('a span.card-name').textContent.trim();
var c = card.querySelector('span.card-count').textContent.trim();
cards.push([n, c]);
}
} else if (href.startsWith('https://tempostorm.com/hearthstone/decks/')) {
deck_name = encodeURIComponent(document.title);
author = encodeURIComponent((document.querySelector('a.m-r-sm') || '?').textContent);
var cc = document.querySelectorAll('div.db-deck-card-name');
var qq = document.querySelectorAll('div.db-deck-card-qty');
for (var i = 0; i < cc.length; i++) {
var card = cc[i];
var n = cc[i].textContent.trim();
var c = qq[i].textContent.trim();
cards.push([n, c]);
}
} else {
window.open('http://www.hearth.tokyo/unsupported');
}
var data = 'deck_name=' + deck_name + '&' + 'author=' + author + '&' + 'url=' + href + '&';
for (i = 0; i < cards.length; i++) {
var n_key = 'n' + i;
var c_key = 'c' + i;
var name = cards[i][0];
var count = cards[i][1];
data = data + n_key + '=' + name + '&';
data = data + c_key + '=' + count + '&';
}
var params = encodeURI(data);
window.open('http://www.hearth.tokyo/translate?' + params);