+Youtube
by
noromanba
2012-12-14 [2012/12/14 09:22:27]
Subscribe Youtube feed (Atom, RSS)
@@ -35,6 +35,7 @@
if (!uName) {
uName = getUserNameByElement();
}
+
if (uName) {
goSubscribe(uName);
}
@@ -42,15 +43,15 @@
function getUserNameByLocation(place) {
var l = location.href;
- if (tryGetUserName(l)) {
- return tryGetUserName(l);
- } else if (tryGetUserName(place)) {
- return tryGetUserName(place);
+ if (parseUserName(l)) {
+ return parseUserName(l);
+ } else if (parseUserName(place)) {
+ return parseUserName(place);
}
return '';
}
-function tryGetUserName(place) {
+function parseUserName(place) {
if (place && place.match(/http:\/\/www\.youtube\.com\/user\/(\w+).*/)) {
return RegExp.$1;
}
@@ -58,32 +59,33 @@
}
function getUserNameByElement() {
- var chElement = '';
- var videoView = 'watch-uploader-info';
+ var aVideo = 'watch-uploader-info';
+ if ($(aVideo)) {
+ return extractUserName($(aVideo));
+ }
+
var chView = 'playnav-curvideo-channel-name';
- var feedView = "upper-section ytg-box";
+ if ($(chView)) {
+ return extractUserName($(chView));
+ }
- if ($(videoView)) {
- chElement = $(videoView);
- } else if ($(chView)) {
- chElement = $(chView);
- } else if ($C(feedView)) {
- chElement = $C(feedView)[0];
- } else {
- alert('Oops.. Can not find ChannelElement!');
- return '';
+ var newChView = "upper-section ytg-box";
+ if ($C(newChView)) {
+ return extractUserName($C(newChView)[0]);
}
- return extractUserName(chElement);
+
+ alert('Oops.. Can not find ChannelElement!');
+ return '';
}
function extractUserName(chElement) {
if (chElement && chElement.hasChildNodes()) {
var nodes = chElement.childNodes;
for (var i = 0; i < nodes.length; i++) {
- if (nodes[i].tagName == 'A') {
+ if (nodes[i].tagName && nodes[i].tagName.toUpperCase() == 'A') {
var place = nodes[i].href;
- return tryGetUserName(place);
+ return parseUserName(place);
}
}
}
/*
* @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-yZeZ6_P0WQ
* @TODO refactor.
*
* [RSS]
* 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
*
* [NOTE]
* Incompatible Browser Extensions. When you use 'Debuglet + Developer Tools', DevTools is stop and death.
* Try '--disable-extensions'.
*/
var d = document;
function $(id) { return d.getElementById(id) };
function $C(name) { return d.getElementsByClassName(name) };
entry();
function entry() {
var uName = getUserNameByLocation();
if (!uName) {
uName = getUserNameByElement();
}
if (uName) {
goSubscribe(uName);
}
}
function getUserNameByLocation(place) {
var l = location.href;
if (parseUserName(l)) {
return parseUserName(l);
} else if (parseUserName(place)) {
return parseUserName(place);
}
return '';
}
function parseUserName(place) {
if (place && place.match(/http:\/\/www\.youtube\.com\/user\/(\w+).*/)) {
return RegExp.$1;
}
return '';
}
function getUserNameByElement() {
var aVideo = 'watch-uploader-info';
if ($(aVideo)) {
return extractUserName($(aVideo));
}
var chView = 'playnav-curvideo-channel-name';
if ($(chView)) {
return extractUserName($(chView));
}
var newChView = "upper-section ytg-box";
if ($C(newChView)) {
return extractUserName($C(newChView)[0]);
}
alert('Oops.. Can not find ChannelElement!');
return '';
}
function extractUserName(chElement) {
if (chElement && chElement.hasChildNodes()) {
var nodes = chElement.childNodes;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].tagName && nodes[i].tagName.toUpperCase() == 'A') {
var place = nodes[i].href;
return parseUserName(place);
}
}
}
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 です。