ハース翻訳

    @@ -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){ - -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); +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 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]); + + +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'); } -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/16 00:25:25 - 2018-02-16
  2. 2017/06/12 01:13:54 - 2017-06-12
  3. 2017/06/12 01:10:57 - 2017-06-12
  4. 2017/06/12 01:07:09 - 2017-06-12
  5. 2017/05/15 20:24:50 - 2017-05-15
  6. 2017/05/13 18:11:17 - 2017-05-13
  7. 2017/05/10 21:59:25 - 2017-05-10
  8. 2017/05/10 21:35:24 - 2017-05-10
  9. 2017/05/10 21:33:14 - 2017-05-10
  10. 2017/05/10 20:38:21 - 2017-05-10
  11. 2017/05/10 20:11:32 - 2017-05-10
  12. 2017/05/08 02:12:43 - 2017-05-08
  13. 2017/05/07 03:36:04 - 2017-05-07
  14. 2017/05/06 19:40:15 - 2017-05-06
  15. 2017/05/06 19:39:13 - 2017-05-06
  16. 2017/05/06 19:34:19 - 2017-05-06
  17. 2017/05/06 19:24:43 - 2017-05-06
  18. 2017/05/06 18:46:54 - 2017-05-06
  19. 2017/05/05 04:01:48 - 2017-05-05
  20. 2017/05/05 03:59:45 - 2017-05-05
  21. 2017/05/05 03:59:01 - 2017-05-05