Userpage RSS link

ユーザー投稿動画ページでRSS linkをつけるだけ

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name           Userpage RSS link
// @namespace      http://efcl.info/
// @description    ユーザー投稿動画ページでRSS linkをつけるだけ
// @include        http://www.nicovideo.jp/user/*/video
// @version 0.0.1.20140518104259
// ==/UserScript==

(function() {
    var links = document.getElementsByTagName("link");
    if (isExistRss(links)) {
        alert("もうRSSあるからこのスクリプトいらないっす!");
        return;
    }
    var link = links[0];
    var alternateLink = document.createElement("link");
    setAttributes(alternateLink, {
        rel : "alternate",
        charset : "utf-8",
        type : "application/rss+xml",
        href : location.href + "?rss=2.0"
    });
    link.parentNode.insertBefore(alternateLink, link);
    function setAttributes(ele, attrs) {
        for (var attr in attrs) {
            ele.setAttribute(attr, attrs[attr]);
        }
    }

    function isExistRss(ele) {
        for (i = 0; i < ele.length; i++) {
            if (ele[i].getAttribute("rel") == "alternate" && /(xml|rss)/.test(ele[i].getAttribute("type"))) {
                return true;
            }
        }

    }
})();