Hatena /archive
by
noromanba
2012-07-21 [2012/07/21 01:44:16]
Go to archive on H::D, H::G and Hatena Blog
@@ -7,38 +7,34 @@
* @include http://*.hatenablog.tld/*
* @include http://*.hatenadiary.tld/*
* @include http://*.hateblo.jp/*
+ * @include http://*
* @license MIT License http://nrm.mit-license.org/2012
- * @require
+ * @require
*/
(function (Hatena) {
- var id = (function () {
- if (typeof Hatena !== 'object') return '';
-
- if (Hatena.Author && Hatena.Author.name) {
- return Hatena.Author.name;
- }
- if (Hatena.Diary && Hatena.Diary.Author) {
- return Hatena.Diary.Author;
- }
-
- return '';
- })();
-
- var topPage,
- origin = location.origin || location.protocol + '//' + location.hostname;
-
+ var isHatenaBlog = function () {
+ return (Hatena.Author && Hatena.Author.name) ||
+ (Hatena.Diary && Hatena.Diary.Author);
+ };
+
// strict HatenaID: /[a-zA-Z][\w-]{1,30}[a-zA-Z\d]/
// loosed HatenaID: /[\w-]+/
- if (/^(?:d|[\w-]+\.g)\.hatena\.ne\.jp$/.test(location.hostname)) {
- topPage = origin + '/' + (id || location.pathname.split[1]);
- } else if (/^(?:[\w-]+\.(?:hatena(?:blog\.(?:com|jp)|diary\.(?:com|jp))|hateblo\.jp)$)/.test(location.hostname)) {
- topPage = origin;
- } else if (id || (Hatena && Hatena.Diary)) {
- // prob. Hatena Blog original domain
- topPage = origin;
- } else {
+ // Hatena DiaryID: /[\w-+]+/
+ var origin = location.origin || location.protocol + '//' + location.hostname,
+ diaryId;
+ if ((diaryId = (/^https?:\/\/(?:d|[\w-]+\.g)\.hatena\.ne\.jp\/([\w-+]+)/.exec(location.href) || [])[1])) {
+ location.href = origin + '/' + diaryId + '/archive';
+ return; // for Firefox
+ }
+
+ if (/^https?:\/\/(?:[\w+]+\.(?:hatena(?:blog\.(?:com|jp)|diary\.(?:com|jp))|hateblo\.jp))/.test(location.hostname)) {
+ location.href = origin + '/archive';
+ return;
+ }
+
+ // Hatena Blog original domain
+ if (isHatenaBlog) {
+ location.href = origin;
return;
}
-
- location.href = topPage + '/archive';
})(window.Hatena || {});
/*
* @title Hatena /archive
* @description Go to archive on H::D, H::G and Hatena Blog
* @include http://d.hatena.ne.jp/*
* @include http://*.g.hatena.ne.jp/*
* @include https://*.g.hatena.ne.jp/*
* @include http://*.hatenablog.tld/*
* @include http://*.hatenadiary.tld/*
* @include http://*.hateblo.jp/*
* @include http://*
* @license MIT License http://nrm.mit-license.org/2012
* @require
*/
(function (Hatena) {
var isHatenaBlog = function () {
return (Hatena.Author && Hatena.Author.name) ||
(Hatena.Diary && Hatena.Diary.Author);
};
// strict HatenaID: /[a-zA-Z][\w-]{1,30}[a-zA-Z\d]/
// loosed HatenaID: /[\w-]+/
// Hatena DiaryID: /[\w-+]+/
var origin = location.origin || location.protocol + '//' + location.hostname,
diaryId;
if ((diaryId = (/^https?:\/\/(?:d|[\w-]+\.g)\.hatena\.ne\.jp\/([\w-+]+)/.exec(location.href) || [])[1])) {
location.href = origin + '/' + diaryId + '/archive';
return; // for Firefox
}
if (/^https?:\/\/(?:[\w+]+\.(?:hatena(?:blog\.(?:com|jp)|diary\.(?:com|jp))|hateblo\.jp))/.test(location.hostname)) {
location.href = origin + '/archive';
return;
}
// Hatena Blog original domain
if (isHatenaBlog) {
location.href = origin;
return;
}
})(window.Hatena || {});
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。