+Youtube
by
noromanba
2012-12-14 [2012/12/14 09:22:27]
Subscribe Youtube feed (Atom, RSS)
@@ -24,26 +24,25 @@
* If you use 'Developer Tools' and it's stuck or death, try '--disable-extensions' option.
*/
var d = document;
-// @TODO use querySelector() both
-function $(id) { return d.getElementById(id) };
-function $C(name) { return d.getElementsByClassName(name) };
+//function $(id) { return d.getElementById(id) };
+//function $C(name) { return d.getElementsByClassName(name) };
+function $(qs) { return d.querySelector(qs); }
entry();
+void 0;
function entry() {
if (getUserNameByLocation()) {
return goSubscribe(getUserNameByLocation());
}
- return goSubscribe(getUserNameByElement());
+// return goSubscribe(getUserNameByElement());
+ return goSubscribe(getUserNameBySelector());
}
-function getUserNameByLocation(place) {
- var here = location.href;
- if (parseUserName(here)) {
- return parseUserName(here);
- }
- if (parseUserName(place)) {
- return parseUserName(place);
+function getUserNameByLocation() {
+ var loc = location.href;
+ if (parseUserName(loc)) {
+ return parseUserName(loc);
}
return '';
}
@@ -55,23 +54,40 @@
return '';
}
-function getUserNameByElement() {
- var aVideo = 'watch-uploader-info';
+function getUserNameBySelector() {
+ var aVideo = '#watch-uploader-info';
if ($(aVideo)) {
return extractUserName($(aVideo));
}
- var chView = 'playnav-curvideo-channel-name';
+ 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]);
+ var newChView = "upper-section, ytg-box";
+ if ($(newChView)) {
+ return extractUserName($(newChView)[0]);
}
alert('Oops.. Can not find ChannelElement!');
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()) {
for (var i = 0; i < chElement.childNodes.length, node = chElement.childNodes[i]; i++) {
@@ -92,7 +108,7 @@
var streamAnchor = '#stream/feed/' + defaultFeed;
if (confirm('Sucscribe [ ' + userName + ' ] ?\n')) {
var readerPreview = 'http://google.com/reader/view/feed/';
- window.open(readerPreview + encodeURIComponent(defaultFeed + streamAnchor));
+ location.href = readerPreview + encodeURIComponent(defaultFeed + streamAnchor);
}
}
}
/*
* @title +Subscribe Youtube
* @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
*
* [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]
* Possibilities conflict Browser Extensions.
* If you use 'Developer Tools' and it's stuck or death, try '--disable-extensions' option.
*/
var d = document;
//function $(id) { return d.getElementById(id) };
//function $C(name) { return d.getElementsByClassName(name) };
function $(qs) { return d.querySelector(qs); }
entry();
void 0;
function entry() {
if (getUserNameByLocation()) {
return goSubscribe(getUserNameByLocation());
}
// return goSubscribe(getUserNameByElement());
return goSubscribe(getUserNameBySelector());
}
function getUserNameByLocation() {
var loc = location.href;
if (parseUserName(loc)) {
return parseUserName(loc);
}
return '';
}
function parseUserName(place) {
if (place && place.match(/http:\/\/www\.youtube\.com\/user\/(\w+).*/)) {
return RegExp.$1;
}
return '';
}
function getUserNameBySelector() {
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 ($(newChView)) {
return extractUserName($(newChView)[0]);
}
alert('Oops.. Can not find ChannelElement!');
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()) {
for (var i = 0; i < chElement.childNodes.length, node = chElement.childNodes[i]; i++) {
if (node.tagName && node.tagName.toUpperCase() == 'A') {
return parseUserName(node.href);
}
}
}
return '';
}
function goSubscribe(userName) {
if (userName) {
var baseFeed = 'http://gdata.youtube.com/feeds/base/users/' + encodeURIComponent(userName) + '/uploads';
var apiQuery = '?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile';
var defaultFeed = baseFeed + apiQuery;
var streamAnchor = '#stream/feed/' + defaultFeed;
if (confirm('Sucscribe [ ' + userName + ' ] ?\n')) {
var readerPreview = 'http://google.com/reader/view/feed/';
location.href = readerPreview + encodeURIComponent(defaultFeed + streamAnchor);
}
}
}
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。