Link IPFS hashes to the IPFS gateway
当前为
// ==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.