Created
March 7, 2015 14:31
-
-
Save adamharley/5ba036ffadef2bd0a0ae to your computer and use it in GitHub Desktop.
4chan magnet links extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "4chan magnet links", | |
"description": "", | |
"version": "0.1", | |
"content_scripts": [ | |
{ | |
"matches": [ | |
"http://boards.4chan.org/*" | |
], | |
"js": ["parse.js"], | |
"run_at": "document_end" | |
} | |
]/*, | |
"icons": { "16": "icon16.png", | |
"48": "icon48.png", | |
"128": "icon128.png" } | |
*/ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var postMessages = document.querySelectorAll(".postMessage"); | |
[].forEach.call(postMessages, function(postMessage) { | |
var lines = postMessage.innerHTML.split("<br>"); | |
lines.forEach(function(line, i){ | |
if (line.substr(0,7) == 'magnet:') { | |
var dnIndex = line.indexOf("&dn="); | |
var title = dnIndex ? ' for ' + decodeURIComponent(line.substr(dnIndex + 8)) : ''; | |
lines[i] = '<a href="' + line + '">Magnet' + title + '</a>'; | |
} | |
}); | |
postMessage.innerHTML = lines.join('<br>'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment