Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created September 20, 2010 09:28
Show Gist options
  • Save hitode909/587659 to your computer and use it in GitHub Desktop.
Save hitode909/587659 to your computer and use it in GitHub Desktop.
近代デジタルライブラリーましにする
// ==UserScript==
// @name kindai-util
// @namespace http://www.hatena.ne.jp/hitode909
// @include http://kindai.da.ndl.go.jp/*
// @include http://kindai.ndl.go.jp/*
// ==UserScript==
// 上のナビゲーションいらないので消す
(function() {
if (location.href.indexOf('info:ndljp/pid/') == -1) return;
var frame = document.querySelector('frameset');
if (!frame) return;
frame.rows = '50, *';
})();
// 旧式ブラウザ対応viewにする
(function() {
if (location.href.indexOf('BIImgControl') == -1) return;
var menu = document.querySelector('#menu2');
if (!menu || menu.value == 1) {
return;
}
menu.querySelector('option[value="1"]').selected = true;
unsafeWindow.imgDisp(0, 1);
// 印刷用URL
var downloadLink = document.querySelector('a[href="JavaScript:execDownload()"]');
if (downloadLink) {
downloadLink.href = serializeForm({action: '/BIImgSelDisp.php'} , {}, document);
downloadLink.target = '_blank';
}
})();
// 前回のサイズ覚えておく
(function() {
if (location.href.indexOf('ndlimageviewer-rgc.aspx') == -1) return;
['dlImageSize', 'dlZoom'].forEach(function(key) {
// 変更時に記録
document.querySelector('select#' + key).addEventListener('change', function(ev) {
GM_setValue(key, this[this.selectedIndex].textContent);
}, false);
// selectされてるのが,前回とちがったら,戻す
try {
var last = GM_getValue(key, '');
var current = document.querySelector('select#' + key + ' option[selected]').textContent;
if (last != current) {
Array.forEach(document.querySelectorAll('select#' + key + ' option'), function(elem) {
if (elem.textContent == last) {
setTimeout(function() {
location.replace(elem.value);
}, 0);
}
});
}
} catch(e) {
console.log(e);
}
});
})();
// 本文を見るリンク,新しいウィンドウ開かない
(function() {
if (location.href.indexOf('BIBibDetail.php') == -1) return;
var a = document.querySelector('img[src="./images/btn_honbun.gif"]').parentNode;
a.href = '/' + a.href.match(/'([^']+?)'\)/)[1];
})();
// 検索結果のリンクを普通のリンクにする
(function() {
if (location.href.indexOf('BIBibList.php') == -1) return;
Array.forEach(document.querySelectorAll('a[href^="JavaScript:submitDetail"]'), function(a) {
var id = a.href.match(/\('([^']+?)'/)[1];
a.href = serializeForm({action: "./BIBibDetail.php"}, {tpl_select_row_no: id}, document);
});
})();
// 検索getにする
(function() {
var searchForm = document.querySelector('#searchArea form');
if (!searchForm) return;
searchForm.method = 'get';
})();
// PDFダウンロードリンク
(function() {
if (location.href.indexOf('BIImgSelDisp.php') == -1) return;
var downloadLink = function(from, to) {
var a = document.createElement('a');
a.textContent = from + '...' + to;
a.href = serializeForm({ action: './BIImgSelDispExec.php' }, { tpl_start_koma: from, tpl_end_koma: to }, document);
a.target = '_blank';
return a;
};
var title = document.createElement('h3');
title.textContent = 'ページを指定してPDFを開く';
document.body.appendChild(title);
var notice = document.createElement('p');
var table = document.createElement('table');
for(var i = 1; i < 500; i+=10) {
var tr = document.createElement('tr');
for(var j = 9; j >= 0; j--) {
var td = document.createElement('td');
var a = downloadLink(i, i + j);
td.appendChild(a);
tr.appendChild(td);
}
table.appendChild(tr);
}
document.body.appendChild(table);
})();
// urlを返す
function serializeForm(form, merge, root) {
var params = { };
if (!root) root = document;
Array.map(root.querySelectorAll('input'), function(input) {
params[input.name] = input.value;
});
for(var key in merge) if (merge.hasOwnProperty(key)) {
params[key] = merge[key];
}
var query = '';
var pairs = [];
for(var key in params) if (params.hasOwnProperty(key)) {
pairs.push([key, params[key]]);
}
return form.action + '?' + pairs.map(function(_) { return encodeURIComponent(_[0]) + '=' + encodeURIComponent(_[1]) }).join('&');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment