livedoorの写真ギャラリーを一括DLするためのgreasemonkey
これはなに?
livedoorの写真ギャラリーの画像一覧のページで実行すると、オリジナル画像へのリンクに書き換えるgreasemonkeyスクリプトです。
例えば、菅山かおるの一覧ページで、サムネイルをクリックしたときには、通常こちらのページに飛ぶのですが、これをオリジナル画像へのリンクに書き換えます。
どう使うの?
firefoxのアドオンであるgreasemonkeyをインストール後、下記のLD_gallery_link_orig.user.jsをクリックしてインストールしたら、例で示したようなサイトにいくと実行されます。
ソースコード
// ==UserScript== // @name livedoor_pic_link_orig // @namespace http://d.hatena.ne.jp/Cherenkov/ // @include http://sports.livedoor.com/photo/* // ==/UserScript== (function(){ var thumb = document.evaluate("//img[../../../../../@class='photo-search-cell']", document, null, 7, null); for(var i=0;i<thumb.snapshotLength;i++){ thumb.snapshotItem(i).parentNode.href = thumb.snapshotItem(i).src.replace('-s','-o'); } //以下広告不可視化 function addGlobalStyle(list){ for(var i in list.id){list.id[i] = '#'+list.id[i];} for(var i in list.class){list.class[i] = '.'+list.class[i];} for(var i in list.name){list.name[i] = '[name="'+list.name[i]+'"]';} list.removeList = list.id.concat(list.class,list.name); GM_addStyle(list.removeList+'{display:none!important;}'); } var list = {}; list.id = ['MegaText','headerBanner','ma-outer-box']; list.class = ['large-showcase','ad-border','center','ads-by-google-2']; list.name = ['google_ads_frame']; addGlobalStyle(list); })();
///////////////////////////////////////////////
と、したのですが
写真ギャラリートップページの下の、写真で追う!のところのサムネイル(一覧へのリンク)も直リン化されてしまったので、
差し替えます。通常のサムネイルリンクの横に別途オリジナル画像へのリンクを付加します。
if(foto.snapshotItem(0).parentNode.parentNode.width != '1%')とか条件つければよかったかもしれないけど、そんな条件は弱いと思ったからやめた。
差し替えたものなら、見た目がグリモンぽくなっていいし、LD的にもいいはず。
差し替えソースコード(別途リンク付加版)
var thumb = document.evaluate("//img[../../../../../@class='photo-search-cell']", document, null, 7, null); if(/image\.sports\.livedoor\.com/.test(thumb.snapshotItem(0).src)){ var link = document.createElement("a"); link.appendChild(document.createTextNode("ORIG")); link.style.backgroundColor = 'red'; link.style.position = 'absolute'; for(var i=0;i<thumb.snapshotLength;i++){ var foto = link.cloneNode(true); foto.href = thumb.snapshotItem(i).src.replace('-s','-o'); thumb.snapshotItem(i).parentNode.parentNode.appendChild(foto); } }
と、したのですが2(単純にリンク書き換え版)
もう好きなの使ってください。
var thumb = document.evaluate("//img[../../../../../@class='photo-search-cell']", document, null, 7, null); if(/image\.sports\.livedoor\.com/.test(thumb.snapshotItem(0).src)){ for(var i=0;i<thumb.snapshotLength;i++){ thumb.snapshotItem(i).parentNode.href = thumb.snapshotItem(i).src.replace('-s','-o'); } }
インストール
(広告不可視化関数のおまけ付)
- LD_gallery_link_orig.user.js 別途リンク付加版 やっぱりこっち使う。
- LD_gallery_link_orig2.user.js 単純にリンク書き換え版
感想
- 正確には一括DLじゃないよね。ページをつなげるやつと連動させればいいのかね。
- ばかの一つ覚えでxpathの部分を../../../../なんてやってるけど他にかっこいいやり方あるかな。
- greasemonkeyスクリプトの文字数制限はアリかナシか。.user.js部分を抜いて、24文字。充分ですか?