Pixiv閲覧用のブックマークレットつくった

2012.08.13 R-18Gのイラストに対して、ページタイトルに[R-18]が入らない問題を修正

2012.08.09 Operaで背景画像の抽出が機能しない不具合を修正しました。

Pixivのページから広告をはじめ色々な装飾をできるだけ取り除くブックマークレットです。できることはだいたい以下の通り

  • 広告を除去する
  • プロフ画像とイラスト以外の画像をほとんど全て除去する(百科事典へのリンク画像等も含む)
  • イラストはオリジナル画像を貼り直す
  • 漫画の場合は全ページを展開して貼り直し、ページ遷移なしで見られるようにする
    • イラスト・漫画ともに画像が大きい場合はクリックすればオリジナルサイズで表示する
  • 背景画像がある場合、ページの一番下に貼る(マウスオーバーでオリジナルサイズ)


確認済みの動作環境


スクリプトはこちら。
はてなダイアリーではJavascriptのリンクが作れないっぽいので直貼りしています。面倒ですがブックマークの編集で以下のコードを貼付けてください。

javascript:(function(){$(document).ready(function(){function getImgUrl(url){var src=$.ajax({url:url,async:false}).responseText;return $("img",$(src)).attr("src");}if(window.location.href.match("tag=")){window.location.href=window.location.href.split("&tag=")[0];return;}eval($("#wrapper>script:first").text().split("pixiv.context.").join("var "));if($("div.works_display>a").size()){$("head").append("<style />");$("head>style:last").append("img.illust {max-width: 740px; margin: 6px 0; }");$("head>style:last").append("img#page_bg {max-width: 100px; max-height: 100px; }");$("head>style:last").append("img#page_bg:hover {max-height: none; max-width: none; }");var img=$("div.works_display>a>img");if($("div.works_display>a").attr("href").match(/manga/)){var pg=parseInt($("section.work-info>ul.meta>li:eq(1)").text().replace("漫画 ","").replace("P",""));for(i=0;i<pg;i++){$("<div/>").attr("class","image-container").append($("<img>").attr({class:"illust",src:getImgUrl(window.location.href.replace("medium","manga_big")+"&page="+i),alt:img.attr("alt")+"_p"+i,title:img.attr("alt")+"_p"+i})).appendTo("div.works_display");}}else{$("<div/>").attr("class","image-container").append($("<img>").attr({class:"illust",src:getImgUrl(window.location.href.replace("medium","big")),alt:img.attr("alt"),title:img.attr("alt")})).appendTo("div.works_display");}$("div.works_display>a").remove();if($("#one_comment_area:hidden").size())one_comment_view();}$("section.score>*:not(dl)").remove();if($("section.questionnaire").size()){if($("section.questionnaire>span.status.toggle-list").size()){if($("section.questionnaire>div.list:hidden").size()){$("section.questionnaire>span.status.toggle-list").click();return;}else{$("section.questionnaire>div.stats:hidden").show();$("section.questionnaire>*:not(div.stats)").remove();}}else{$("section.questionnaire>div.stats:hidden").show();var t=$("section.questionnaire>span.status.toggle-stats").text().split("この作品のアンケートに「")[1].split("」と答えました")[0];t=$("section.questionnaire>div.stats:visible>table>tbody>tr").filter(function(){return $("th",this).text()==t});t.css("color","#258fb8");$("section.questionnaire>*:not(div.stats)").remove();}}var r18="";if($("section.work-info>ul.meta").text().match("R-18")){r18="[R-18]";}$("title").text("(pixiv)["+userId+"-"+illustId+"]"+r18+"【"+userName+"】"+illustTitle);$("head").contents().filter(function(){return this.nodeType==8}).remove();$("body").contents().filter(function(){return this.nodeType==8}).remove();$("body").contents().not("#wrapper").remove();$("body>*:not(#wrapper)").remove();$("#wrapper>*:not(#contents,script:eq(0))").remove();$("div.ui-layout-west>*:not(div.profile_area)").remove();$("div.profile_area>*:not(a,h2)").remove();$("div.profile_area>a").attr("href",window.location.href.split(illustId)[0]+illustId);$("div.contents-east>*:not(div.two_column_body)").remove();$("div.two_column_body>*:not(section.work-info,#tag_area,div.works_display,div.works_info)").remove();$("section.work-info>p.caption").contents().filter(function(){return this.nodeType==3}).each(function(){$(this).replaceWith($($("<p>"+$(this).text()+"</p>")).contents());});$("#tag_area>p").replaceWith($("#tags"));$("#tags>a").filter(":has(img)").remove();$("div.works_info>div.worksOption>:not('#one_comment_area,div.worksImageresponse')").remove();$("div.worksOptionRight").remove();$("div.worksImageresponse:not(:contains('イメージレスポンス'))").remove();var bg=$("body").css("background-image");if(bg!="none"){$("<img/>").attr({id:"page_bg",src:bg.replace("url(","").replace(")","").replace(/\"/g,"").replace(/\'/g,""),alt:"背景画像",title:"背景画像"}).appendTo($("div.two_column_body"));}$("head>meta[name]").remove();$("#wrapper").contents().filter(function(){return this.nodeType==8}).remove();$("input").remove();$("noscript").remove();$("script:not(:contains('pixiv.context.illustId'),[src*='jquery'])").remove();var script=document.createElement("script");script.type="text/javascript";script.text='$(document).ready(function(){$("img.illust").toggle(function(){$(this).css("max-width","none");},function(){$(this).removeAttr("style");});});';document.getElementsByTagName("head")[0].appendChild(script);});})();

使い方
Pixivのイラストページまたは漫画ページでブックマークレットを起動するとページが整形されます。※ページが読み込み中の場合は読み込み完了するまでタイムラグが発生します。

  1. アンケートがある場合はアンケートが開かれます。
  2. もう一度ブックマークレットを起動すると、アンケートに回答した場合は自分の回答が水色にハイライトされた状態で整形され、回答していない場合は黒字のままで整形されます。

なお、タグ検索から飛んだ場合には、ブックマークレットを呼び出した際に一度ページがリロードされます。これはURLの末尾に"&tag=***"という文字列がついてしまっているのを削除する目的で行われる動作です。

蛇足

  • Operaの場合、SpeedDialのURLを編集してブックマークレットにすると、Ctrl+数字キーのショートカットで呼び出せるので便利です。