ハース翻訳
by
fmimali
2018-02-16 [2018/02/16 00:25:25]
ハースストーンのデッキを日本語に翻訳します。ポップアップを許可して使ってね
@@ -1,90 +1,79 @@
/*
- * @title ハースストーン翻訳
+ * @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/*
* @license MIT License
- * @require jQuery
+ * @javascript_url
*/
-
-function hs2jp(deck_name, author, cards) {
- var data = 'deck_name=' + deck_name + '&' + 'author=' + author + '&' + 'url=' + window.location.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);
-}
-
-
+var deck_name, author;
+var cards = [];
var href = window.location.href;
if (href.startsWith('http://www.hearthpwn.com/decks/')) {
- var deck_name = $('h2.deck-title.tip:first').text();
- var author = $('#content section.user-details ul.user li.name a.tip').text().trim();
- var cards = $('table#cards tr td b a');
- var arr = [];
- for (var i = 0; i < cards.length; i++) {
- var card = cards[i];
- var c = $(card).attr('data-count');
- var n = $(card).text().trim();
- arr.push([n, c]);
+ deck_name = 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]);
}
- hs2jp(deck_name, author, arr);
-
} else if (href.startsWith('http://www.hearthhead.com/decks/')) {
- var deck_name = encodeURIComponent(window.HearthHeadData.deck.name);
- var author = encodeURIComponent(window.HearthHeadData.deck.username);
- var cards = window.HearthHeadData.deck.cards;
- var arr = [];
+ 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 < cards.length; i++) {
- var card = cards[i];
+ for (var i = 0; i < cc.length; i++) {
+ var card = cc[i];
var n = card.name;
if (set.has(n)) {
- arr.push([n, 2]);
+ cards.push([n, 2]);
set.delete(n);
} else {
set.add(n);
}
}
for (let name of set.values()) {
- arr.push([name, 1]);
+ cards.push([name, 1]);
}
- hs2jp(deck_name, author, arr);
-
} else if (href.startsWith('http://hearthstone.metabomb.net/deck-guides/')) {
- var deck_name = encodeURIComponent($('h1.title').text().trim());
- var author = encodeURIComponent($('i.fa-user + span').text());
- var cards = $('div.article-content section table tbody tr td');
- var arr = [];
- for (var i = 0; i < cards.length; i++) {
- var card = cards[i];
- var n = $(card).children('span').text().trim();
- if (n.length == 0) {
+ deck_name = encodeURIComponent(document.querySelector('h1.title').textContent.trim());
+ author = encodeURIComponent(document.querySelector('i.fa-user + span').textContent);
+ var cc = document.querySelectorAll('div.article-content section table tbody tr td');
+ for (var i = 0; i < cc.length; i++) {
+ var card = cc[i];
+ var span = card.querySelector('span');
+ if (span == null) {
continue;
}
- var c = $(card).text().trim().substr(0, 1);
- arr.push([n, c]);
+ var n = card.querySelector('span').textContent.trim();
+ var c = card.textContent.trim().substr(0, 1);
+ cards.push([n, c]);
}
- hs2jp(deck_name, author, arr);
} else if (href.startsWith('http://www.hearthstonetopdecks.com/decks/')) {
- var deck_name = encodeURIComponent(document.title);
- var author = encodeURIComponent($('div.player-wrap h2 a').text());
- var cards = $('ul.deck-class li');
- var arr = [];
- for (var i = 0; i < cards.length; i++) {
- var card = cards[i];
- var n = $(card).children('a').children('span.card-name').text().trim();
- var c = $(card).children('span.card-count').text().trim();
- arr.push([n, c]);
+ 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]);
}
- hs2jp(deck_name, author, arr);
} else {
window.open('http://www.hearth.tokyo/not-found');
}
+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);
/*
* @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/*
* @license MIT License
* @javascript_url
*/
var deck_name, author;
var cards = [];
var href = window.location.href;
if (href.startsWith('http://www.hearthpwn.com/decks/')) {
deck_name = 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://hearthstone.metabomb.net/deck-guides/')) {
deck_name = encodeURIComponent(document.querySelector('h1.title').textContent.trim());
author = encodeURIComponent(document.querySelector('i.fa-user + span').textContent);
var cc = document.querySelectorAll('div.article-content section table tbody tr td');
for (var i = 0; i < cc.length; i++) {
var card = cc[i];
var span = card.querySelector('span');
if (span == null) {
continue;
}
var n = card.querySelector('span').textContent.trim();
var c = card.textContent.trim().substr(0, 1);
cards.push([n, c]);
}
} 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 {
window.open('http://www.hearth.tokyo/not-found');
}
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);
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。