ハース翻訳 Fork

    @@ -1,33 +1,64 @@ /* * @title ハースストーン翻訳 - * @description HearthPwn のデッキを日本語に翻訳します。 + * @description ハースストーンのデッキを日本語に翻訳します。 * @include http://www.hearthpwn.com/decks/* + * @include http://www.hearthhead.com/decks/* * @license MIT License * @require jQuery */ - function hspwn2jp(deck_name, author, cards){ + 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 + '&'; + } + params = encodeURI(data); + window.open('http://www.hearth.tokyo/translate?' + params); + } - 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 + '&'; - } - params = encodeURI(data); - window.open('http://www.hearth.tokyo/translate?' + params); + + 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 (i = 0; i < cards.length; i++) { + card = cards[i]; + var c = $(card).attr('data-count'); + var n = $(card).text().trim(); + arr.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 = []; + var set = new Set(); + for (i = 0; i < cards.length; i++) { + card = cards[i]; + var n = card.name; + if (set.has(n)) { + arr.push([n, 2]); + set.delete(n); + } else { + set.add(n); + } + } + for (let name of set.values()) { + arr.push([name, 1]); + } + for (let ar of arr) { + console.log(ar); + } + hs2jp(deck_name, author, arr); + } else { + window.open('http://www.hearth.tokyo/not-found'); } - 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(i=0;i<cards.length;i++){ - card = cards[i]; - var c = $(card).attr('data-count'); - var n = $(card).text().trim(); - arr.push([n,c]); - } - hspwn2jp(deck_name,author,arr);
  • /*
     * @title ハースストーン翻訳
     * @description ハースストーンのデッキを日本語に翻訳します。
     * @include http://www.hearthpwn.com/decks/*
     * @include http://www.hearthhead.com/decks/*
     * @license MIT License
     * @require jQuery
     */
    
    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 + '&';
        }
        params = encodeURI(data);
        window.open('http://www.hearth.tokyo/translate?' + params);
    }
    
    
    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 (i = 0; i < cards.length; i++) {
            card = cards[i];
            var c = $(card).attr('data-count');
            var n = $(card).text().trim();
            arr.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 = [];
        var set = new Set();
        for (i = 0; i < cards.length; i++) {
            card = cards[i];
            var n = card.name;
            if (set.has(n)) {
                arr.push([n, 2]);
                set.delete(n);
            } else {
                set.add(n);
            }
        }
        for (let name of set.values()) {
            arr.push([name, 1]);
        }
        for (let ar of arr) {
            console.log(ar);
        }
        hs2jp(deck_name, author, arr);
    } else {
        window.open('http://www.hearth.tokyo/not-found');
    }
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2018/02/15 15:25:25 - 02/15
  2. 2017/06/11 16:13:54 - 2017-06-11
  3. 2017/06/11 16:10:57 - 2017-06-11
  4. 2017/06/11 16:07:09 - 2017-06-11
  5. 2017/05/15 11:24:50 - 2017-05-15
  6. 2017/05/13 09:11:17 - 2017-05-13
  7. 2017/05/10 12:59:25 - 2017-05-10
  8. 2017/05/10 12:35:24 - 2017-05-10
  9. 2017/05/10 12:33:14 - 2017-05-10
  10. 2017/05/10 11:38:21 - 2017-05-10
  11. 2017/05/10 11:11:32 - 2017-05-10
  12. 2017/05/07 17:12:43 - 2017-05-07
  13. 2017/05/06 18:36:04 - 2017-05-06
  14. 2017/05/06 10:40:15 - 2017-05-06
  15. 2017/05/06 10:39:13 - 2017-05-06
  16. 2017/05/06 10:34:19 - 2017-05-06
  17. 2017/05/06 10:24:43 - 2017-05-06
  18. 2017/05/06 09:46:54 - 2017-05-06
  19. 2017/05/04 19:01:48 - 2017-05-04
  20. 2017/05/04 18:59:45 - 2017-05-04
  21. 2017/05/04 18:59:01 - 2017-05-04