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

2018-10-05 22:56:00 +08:00
 autoxbc

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

稍微研究了一下,发现来源网站的 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>';
    } ,
  } );
} );
1772 次点击
所在节点    分享发现
5 条回复
delectate
2018-10-06 07:02:07 +08:00
需要配合 refcontrol 使用。
silencefent
2018-10-06 10:38:53 +08:00
原先习惯了还没觉得...
Thx4
2018-10-06 18:47:14 +08:00
左图笑死了哈哈哈哈哈
xiaoxinshiwo
2018-10-08 16:10:00 +08:00
你是 cot 吗?
autoxbc
2018-10-08 17:12:09 +08:00
@xiaoxinshiwo #4 不是啦,我不穿女装的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/495101

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX