Kizuna / Nyaa Magnet Links

// ==UserScript==
// @name           Nyaa Magnet Links
// @author         Kizuna
// @version        1.0.4
// @include        http://*.nyaa.se/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @description    Adds magnet links to Nyaa.se for convenience
// @run-at         document-end
// @namespace      https://greasyfork.org/users/4706-kizuna
// ==/UserScript==


url = document.URL;

if(url.search("page=search")) {
    $(function () {
        $('[title="Download"]').attr('href', function (i, h) {
            return h + (h.indexOf('?') != -1 ? "&magnet=1" : "?magnet=1");
        });
    });
}

if(url.search("page=view")) {
    button = $('.viewdownloadbutton').find('a');
    link = button.attr('href');
    button.before('<a href="' + link + '&magnet=1" rel="nofollow"><img src="http://i.imgur.com/I1lPYRt.png" alt="Magnet" width="25px" style="margin-right:10px;"/></a>');
}