+Youtube
by
noromanba
2012-12-14 [2012/12/14 09:22:27]
Subscribe Youtube feed (Atom, RSS)
@@ -16,46 +16,48 @@
* 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
+ * http://gdata.youtube.com/feeds/base/users/youtube/uploads?orderby=updated&alt=rss&client=ytapi-youtube-rss-redirect&v=2
+ * @private
*/
var d = document;
-var userChannel = '';
-var userName = '';
+function $(id) { return d.getElementById(id) };
- // from Video View
- userChannel = d.getElementById('watch-uploader-info');
- if (userChannel) {
- extractUserName();
- }
- // from Channel View
- userChannel = d.getElementById('playnav-curvideo-channel-name');
- if (userChannel) {
- extractUserName();
- }
- // Normal User Channel View
- userChannel = d.getElementsByClassName("upper-section ytg-box");
- if (userChannel) {
- userChannel = userChannel[0];
- extractUserName();
+goSubscribe(extractUserName(getChannelElement()));
+
+function getChannelElement() {
+ var chElement = '';
+
+ var idVideo = 'watch-uploader-info';
+ var idChannel = 'playnav-curvideo-channel-name';
+ var clsChannel = "upper-section ytg-box";
+ if ($(idVideo)) {
+ chElement = $(idVideo);
+ } else if ($(idChannel)) {
+ chElement = $(idChannel);
+ } else if (d.getElementsByClassName(clsChannel)) {
+ chElement = d.getElementsByClassName(clsChannel).firstChild;
+ } else {
+ alert('Oops.. Can't find ChannelElement!');
}
+ return chElement;
+}
-function extractUserName() {
- if (userChannel) {
- var nodes = userChannel.childNodes;
+function extractUserName(var chElement) {
+ if (chElement) {
+ var nodes = chElement.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].tagName == 'A') {
- userChannel = nodes[i].href;
+ chElement = nodes[i].href;
break;
}
}
} else {
- userChannel = prompt('Try Manual Input','UserName');
+ chElement = prompt('Try Manual Input','UserName');
}
- userName = userChannel.replace(/http:\/\/www\.youtube\.com\/user\/(.*)/, '$1');
- goSubscribe();
+ return chElement.replace(/http:\/\/www\.youtube\.com\/user\/(.*)/, '$1');
}
-function goSubscribe() {
+function goSubscribe(var 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';
/*
* @title +YR
* @description Subscribe Youtube Uploads RSS.
* @include http://http://www.youtube.com/*
* @license MIT License
* @require
* @see http://let.hatelabo.jp/noromanba/let/gYC-yJnWtr6DNw
*
* [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
* @private
*/
var d = document;
function $(id) { return d.getElementById(id) };
goSubscribe(extractUserName(getChannelElement()));
function getChannelElement() {
var chElement = '';
var idVideo = 'watch-uploader-info';
var idChannel = 'playnav-curvideo-channel-name';
var clsChannel = "upper-section ytg-box";
if ($(idVideo)) {
chElement = $(idVideo);
} else if ($(idChannel)) {
chElement = $(idChannel);
} else if (d.getElementsByClassName(clsChannel)) {
chElement = d.getElementsByClassName(clsChannel).firstChild;
} else {
alert('Oops.. Can't find ChannelElement!');
}
return chElement;
}
function extractUserName(var chElement) {
if (chElement) {
var nodes = chElement.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].tagName == 'A') {
chElement = nodes[i].href;
break;
}
}
} else {
chElement = prompt('Try Manual Input','UserName');
}
return chElement.replace(/http:\/\/www\.youtube\.com\/user\/(.*)/, '$1');
}
function goSubscribe(var 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 です。