+Youtube
by
noromanba
2012-12-14 [2012/12/14 09:22:27]
Subscribe Youtube feed (Atom, RSS)
@@ -1,10 +1,11 @@
/*
- * @title +YR
+ * @title +Youtube Subscribe
* @description Subscribe Youtube Uploads RSS.
* @include http://http://www.youtube.com/*
* @license MIT License
* @require
* @see http://let.hatelabo.jp/noromanba/let/gYC-yJnWtr6DNw
+ * @TODO refactor.
*
* [NOTES]
* Large Thumbnail ver.
@@ -17,7 +18,6 @@
* http://www.youtube.com/rss/user/youtube/videos.rss
* Exepand Alt-GW. Order by Updated?
* http://gdata.youtube.com/feeds/base/users/youtube/uploads?orderby=updated&alt=rss&client=ytapi-youtube-rss-redirect&v=2
- * @private
*/
var d = document;
function $(id) { return d.getElementById(id) };
@@ -32,9 +32,11 @@
goSubscribe(uName);
}
-function getUserNameByLocation() {
- if (location.href.match(/http:\/\/www\.youtube\.com\/user\/(\w+)/) {
+function getUserNameByLocation(locate) {
+ if (location.href.match(/http:\/\/www\.youtube\.com\/user\/(\w+)/)) {
return RegExp.$1;
+ } else if (locate) {
+ return locate.replace(/http:\/\/www\.youtube\.com\/user\/(\w+)/, '$1');
}
return '';
}
@@ -56,13 +58,13 @@
alert('Oops.. Can not find ChannelElement!');
return '';
}
- return extractUserName(chElement);
+ return getUserNameByLocation(extractUserName(chElement));
}
function extractUserName(chElement) {
var nodes = chElement.childNodes;
for (var i = 0; i < nodes.length; i++) {
- if (nodes[i].tagName.toUpperCase() == 'A') {
+ if (nodes[i].tagName == 'A') {
return nodes[i].href;
}
}
/*
* @title +Youtube Subscribe
* @description Subscribe Youtube Uploads RSS.
* @include http://http://www.youtube.com/*
* @license MIT License
* @require
* @see http://let.hatelabo.jp/noromanba/let/gYC-yJnWtr6DNw
* @TODO refactor.
*
* [NOTES]
* Large Thumbnail ver.
* http://gdata.youtube.com/feeds/base/users/youtube/uploads
* Default Register from Browser
* http://gdata.youtube.com/feeds/base/users/youtube/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile
* Tiny Query ver.
* http://gdata.youtube.com/feeds/base/users/youtube/uploads?alt=rss&v=2&orderby=published
* Alternate Gateway
* http://www.youtube.com/rss/user/youtube/videos.rss
* Exepand Alt-GW. Order by Updated?
* http://gdata.youtube.com/feeds/base/users/youtube/uploads?orderby=updated&alt=rss&client=ytapi-youtube-rss-redirect&v=2
*/
var d = document;
function $(id) { return d.getElementById(id) };
entry();
function entry() {
var uName = getUserNameByLocation();
if (!uName) {
uName = getUserNameByElement();
}
goSubscribe(uName);
}
function getUserNameByLocation(locate) {
if (location.href.match(/http:\/\/www\.youtube\.com\/user\/(\w+)/)) {
return RegExp.$1;
} else if (locate) {
return locate.replace(/http:\/\/www\.youtube\.com\/user\/(\w+)/, '$1');
}
return '';
}
function getUserNameByElement() {
var chElement = '';
var videoView = 'watch-uploader-info';
var chView = 'playnav-curvideo-channel-name';
var feedView = "upper-section ytg-box";
if ($(videoView)) {
chElement = $(videoView);
} else if ($(chView)) {
chElement = $(chView);
} else if (d.getElementsByClassName(feedView)) {
chElement = d.getElementsByClassName(feedView)[0];
} else {
alert('Oops.. Can not find ChannelElement!');
return '';
}
return getUserNameByLocation(extractUserName(chElement));
}
function extractUserName(chElement) {
var nodes = chElement.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].tagName == 'A') {
return nodes[i].href;
}
}
return '';
}
function goSubscribe(userName) {
if (userName) {
var baseFeed = 'http://gdata.youtube.com/feeds/base/users/' + encodeURIComponent(userName) + '/uploads';
var uiQuery = '?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile';
if (confirm('Sucscribe This?\n' + baseFeed)) {
var readerPreview = 'http://google.com/reader/view/feed/';
location.href = readerPreview + baseFeed + uiQuery;
}
}
}
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。