V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
autoxbc

煎蛋网(jandan.net)补全原始题图

  •  1
     
  •   autoxbc · Oct 5, 2018 · 2141 views
    This topic created in 2764 days ago, the information mentioned may be changed or developed.

    摸鱼网站煎蛋因为之前的图片版权风波,无法在文章中引用译介文章的原始题图,虽然通过合作图库配上了意思接近的图,离准确传达原文信息还是有些距离

    稍微研究了一下,发现来源网站的 Open Graph 信息都很完整,也就是源码中 meta[property="og:image"] 就包含题图,提取出来可以补全到文章中

    原图示例

    注意需要允许油猴跨域 Tampermonkey => 设置 => 安全 => @connect 模式 => 已禁用

    如果发现原图无法加载,有可能需要梯子或者伪造 Referrer

    // ==UserScript==
    // @name      煎蛋网(jandan.net)补全原始题图
    // @author      autoxbc
    // @version      1.0
    // @match      *://jandan.net/*
    // @grant      GM.xmlHttpRequest
    // ==/UserScript==
    
    const links = document.querySelectorAll('#content .post.f em a');
    [].slice.call(links).forEach( e => {
      const node = e.previousSibling ;
      if( !node || !node.data || node.data.trim() !== '本文译自' )
        return;
    
      GM.xmlHttpRequest( {
        method: 'GET',
        url: e.href ,
        onload: ( { response } ) => {
          const div = document.createElement('div');
          div.innerHTML = response ;
          const meta = div.querySelector('meta[property="og:image"]');
          if(!meta)
            return;
    
          let target ;
          const imgs = document.querySelectorAll('#content .post.f img');
          if( imgs.length === 1 )
          {
            target = imgs[0];
            const br = target.nextElementSibling ;
            if( br && br.matches('br') )
            {
              const em = br.nextElementSibling ;
              if( em && em.matches('em') )
                em.remove();
              br.remove();
            }
          }
          else {
            const h1 = document.querySelector('#content .post.f h1');
            target = h1.insertAdjacentElement('afterend', new Image() );
          }
    
          target.src = meta.content ;
          target.outerHTML += '<p style="text-align:center !important;">原图</p>';
        } ,
      } );
    } );
    
    5 replies    2018-10-08 17:12:09 +08:00
    delectate
        1
    delectate  
       Oct 6, 2018
    需要配合 refcontrol 使用。
    silencefent
        2
    silencefent  
       Oct 6, 2018
    原先习惯了还没觉得...
    Thx4
        3
    Thx4  
       Oct 6, 2018
    左图笑死了哈哈哈哈哈
    xiaoxinshiwo
        4
    xiaoxinshiwo  
       Oct 8, 2018
    你是 cot 吗?
    autoxbc
        5
    autoxbc  
    OP
       Oct 8, 2018
    @xiaoxinshiwo #4 不是啦,我不穿女装的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2456 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 05:15 · PVG 13:15 · LAX 22:15 · JFK 01:15
    ♥ Do have faith in what you're doing.