iframe2link

  • /*
     * @title iframe2link
     * @description replace iframe to anchor link
     * @include http://example.com/DIY/*
     * @license MIT http://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // UserScript
    // https://gist.github.com/noromanba/26d1804fac23f76d9dfc
    
    (() => {
        const whitelist = [
            '[src^="javascript:"]',
            '[src*="//www.facebook.com/plugins/"]',
            // #twitter-widget-* .twitter-share-button .twitter-tweet-button
            '[class|="twitter"]',
            '[src^="//platform.twitter.com/widgets/"]',
            '[src^="https://apis.google.com/"]',
            '[src^="https://accounts.google.com/o/"]',
            '[src^="https://embed.tumblr.com/widgets/share/button"]',
            '[src^="https://widgets.getpocket.com/"]'
        ].map(sel => ':not(' + sel + ')').join('');
    
        const replace = (ctx) => {
            if (ctx.tagName.toLowerCase() === 'iframe') {
                ctx = ctx.parentNode || document.body;
            }
    
            Array.from(ctx.querySelectorAll('iframe[src]' + whitelist), iframe => {
                const link = document.createElement('a');
                link.href = iframe.src;
                link.appendChild(document.createTextNode(link.href));
    
                iframe.parentNode.replaceChild(link, iframe);
            });
        };
        replace(document.body);
    
        new MutationObserver(records => {
            records.forEach(record => {
                const ctx = record.target;
                if (!ctx.tagName || !ctx.querySelectorAll) return;
    
                replace(ctx);
            });
        }).observe(document.body, { childList: true, subtree: true });
    })();
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2016/02/29 06:20:18 - 2016-02-29
  2. 2016/02/03 07:39:53 - 2016-02-03
  3. 2016/01/18 23:44:20 - 2016-01-18
  4. 2016/01/15 05:35:35 - 2016-01-15
  5. 2016/01/15 05:18:43 - 2016-01-15
  6. 2014/11/04 07:14:42 - 2014-11-04
  7. 2014/10/31 00:05:47 - 2014-10-31
  8. 2014/10/24 03:05:36 - 2014-10-24
  9. 2014/10/24 03:05:21 - 2014-10-24
  10. 2014/10/23 05:03:19 - 2014-10-23
  11. 2014/10/23 04:51:10 - 2014-10-23