IPFS Hash Linker

Link IPFS hashes to the IPFS gateway

当前为 2015-12-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           IPFS Hash Linker
// @namespace      IPFS Hash Linker
// @description    Link IPFS hashes to the IPFS gateway
// @version        1.0
// @include        *
// ==/UserScript==

text = document.body.innerHTML;
if (text.match(/([^A-Za-z0-9/"]|ipfs\/)Qm[A-HJ-NP-Za-km-z1-9]{44,45}[^A-Za-z0-9"]/)) {
    document.body.innerHTML = text.replace(/(<[^<]*[^A-Za-z0-9/"])(\/?ipfs\/)?(Qm[A-HJ-NP-Za-km-z1-9]{44,45})([^A-Za-z0-9?%"]...)/g,function(matchedString,preHash,path,hash,postHash){
        if(typeof path == "undefined") {
            // Sometimes there's no leading /ipfs/
            path = "/ipfs/";
        }
        if(matchedString.match(/^<(textarea|input|pre|code)/i) || postHash=="</a>") {
            // Make no change inside links or in other weird environments.
            return preHash+path+hash+postHash;
        } else {
            // Otherwise put it in a link.
            return preHash+"<a href=\"https://gateway.ipfs.io/ipfs/"+hash+"\">"+path+hash+"</a>"+postHash;
        }
    });
}

// Tips: 1NT9pxhDcPfsFhnrVoehxiUZ7HCC3gnsn3
// Based on the "Bitcoin Tool" userscript:
// http://userscripts.org/scripts/show/104381

// This is public domain code, free for commercial and non-commercial use.
// If you use some of it, give a link to this script.