はてなーに奉げるユーザースクリプト

うそ。自分用につくったやつを自分用にまとめただけ。

ソースコード

// ==UserScript==
// @name           hatener_script
// @namespace      http://d.hatena.ne.jp/Cherenkov/
// @description    userscript for hatener.
// @include        http://*.hatena.ne.jp/*
// ==/UserScript==

var url;
if (/^http\:\/\/d\.hatena\.ne\.jp/.test(location.href))         {url = 'd.hatena.ne.jp'}
else if (/^http\:\/\/s\.hatena\.ne\.jp/.test(location.href))    {url = 's.hatena.ne.jp'}
else if (/^http\:\/\/b\.hatena\.ne\.jp/.test(location.href))    {url = 'b.hatena.ne.jp'}

// http://*.hatena.ne.jp/*なページで実行したいものはswitchの外に。
// @name           hatena_star_link_diary
// @include        http://*.hatena.ne.jp/*
// @description    スターのリンクをユーザーのダイアリーに換える。
location.href = "javascript:if(window.Hatena&&Hatena.Star){Hatena.Star.User.prototype.userPage=function(){return 'http://d.hatena.ne.jp/'+this.name+'/'}};void(0)";

switch (url){

  case 'd.hatena.ne.jp':
// @name           hatena_diary_confirm
// @include        http://d.hatena.ne.jp/*/edit
// @include        http://d.hatena.ne.jp/*/draft?epoch=*
// @description    ダイアリー編集ページからリンクに飛ぶときに確認する。
if(/.+?\/edit/.test(location.href) || /.+?\/draft\?epoch\=/.test(location.href)){
    var link = document.evaluate("//a[not(@target='_blank')]", document, null, 7, null);
    for(var i=0;i<link.snapshotLength;i++){
        link.snapshotItem(i).setAttribute("onclick","return confirm('ページ遷移しますがよろしいですか');");
    }
}
  break;

  case 's.hatena.ne.jp':
// @include        http://s.hatena.ne.jp/*
// @description    はてなスターのインデックスページのユーザアイコンのリンクをダイアリーに換える。
    var profileImage = document.evaluate('//img[@class="profile-image"]', document, null, 7, null);
    for(var i=0;i<profileImage.snapshotLength;i++){
        profileImage.snapshotItem(i).parentNode.href = profileImage.snapshotItem(i).parentNode.href.replace('s', 'd');
    }
  break;

  case 'b.hatena.ne.jp':
//if(/b\.hatena\.ne\.jp\/entry/.test(location.href)){
// @name           hateb_link_user_diary2
// @include        http://b.hatena.ne.jp/entry/*
// @description    はてブのエントリーページにあるユーザー名のリンクをダイアリーに換える。
    var icons = document.evaluate('//a[@class="username"][../../@id="bookmarked_user"]', document, null, 7, null);
    for(var i=0;i<icons.snapshotLength;i++){
        icons.snapshotItem(i).href = icons.snapshotItem(i).previousSibling.previousSibling.href.replace('b','d');
    }
  break;

}

インストール

hatener_script.user.js

感想

  • 広告不可視化関数は割愛。
  • 不具合でたら報告。