N embed2link

    @@ -14,6 +14,7 @@ (() => { 'use strict'; // creepy + const swfSelector = [ 'embed[type="application/x-shockwave-flash"]', '[src^="http://ext.nicovideo.jp/swf/player/thumbwatch.swf"]',
  • /*
     * @title N embed2link
     * @description replace Nicovideo embed player to link
     * @include http://*
     * @license MIT License http://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // ES6/7/2015+ monkey traning
    // let|const and magic-comment; too lame yet
    
    // TODO more smart Harmony+ way e.g.
    //      - ugly Array scan and RegExp captures, to Array#includes
    
    (() => {
        'use strict'; // creepy
    
        const swfSelector = [
            'embed[type="application/x-shockwave-flash"]',
            '[src^="http://ext.nicovideo.jp/swf/player/thumbwatch.swf"]',
            '[flashvars]'
        ].join('');
    
        // TBD Array#find replace to Array#findIndex/Array#indexOf
        let selectKVPValue = (ary, key) => {
            let kvp = ary.find(a => RegExp(key + '=').test(a));
            if (!kvp) return '';
    
            return (kvp.split('=') || [])[1] || '';
        };
    
        Array.from(document.body.querySelectorAll(swfSelector)).forEach(swf => {
            // flashvars can't access from property and bracket-notation;
            // swf.flashvars / swf['flashvars'] -> Error
            let queries = decodeURIComponent(swf.getAttribute('flashvars')).split('&');
    
            let container = document.createElement('div');
    
            let id = selectKVPValue(queries, 'v');
            container.appendChild(document.createElement('br'));
            let title = selectKVPValue(queries, 'thumbTitle');
            container.appendChild(document.createTextNode(title));
            container.appendChild(document.createElement('br'));
    
            let link = document.createElement('a');
            link.href = 'http://www.nicovideo.jp/watch/' + id;
            let description = selectKVPValue(queries, 'thumbDescription');
            link.title = description;
            link.appendChild(document.createTextNode(link));
    
            container.appendChild(link);
    
            swf.parentNode.replaceChild(container, swf);
        });
    })();
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2015/12/03 06:36:10 - 2015-12-03
  2. 2015/12/03 06:35:41 - 2015-12-03
  3. 2015/12/03 06:11:02 - 2015-12-03
  4. 2015/11/26 08:01:33 - 2015-11-26